本文整理汇总了C#中UnityEngine.GameObject.GetComponentInParent方法的典型用法代码示例。如果您正苦于以下问题:C# GameObject.GetComponentInParent方法的具体用法?C# GameObject.GetComponentInParent怎么用?C# GameObject.GetComponentInParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.GameObject
的用法示例。
在下文中一共展示了GameObject.GetComponentInParent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnExit
public virtual void OnExit(GameObject exited)
{
Entity e = exited.GetComponentInParent<Entity>();
if (e)
{
entitiesInContact.Remove(e);
}
}
示例2: Awake
void Awake()
{
On("OnMainCameraChange");
_healthContainer = GetComponentInChildren<Image>().gameObject;
_healthContainer.GetComponentInParent<Canvas>().worldCamera = Camera.main;
_rectTransform = _healthContainer.GetComponent<RectTransform>();
_healthBar = _healthContainer.transform.FindChild("HealthBar").GetComponent<RectTransform>();
_image = _healthBar.GetComponent<Image>();
_krHealth = transform.GetComponentInParent<KRHealth>();
}
示例3: OnParticleCollision
void OnParticleCollision(GameObject shooter) {
//print ( "OnParticleCollision " + other.transform.root.name + " ME : " + transform.root.name);
shooterCombat = shooter.transform.root.GetComponent<Combat>();
if (shooterCombat != myCombat && shooterCombat.isLocalPlayer) {
shooterCombat.GiveDamage ( shooter.GetComponentInParent<Weapon>().damage , transform.root.name , DamageType.Smell , Vector3.zero , Vector2.zero );
//myCombat.TakeDamage ( shooter.GetComponentInParent<Weapon>().damage , transform.root.name , DamageType.Smell , Vector3.zero , Vector2.zero );
}
}
示例4: OnTouch
public virtual void OnTouch(GameObject touched)
{
Entity e = touched.GetComponentInParent<Entity>();
if (e)
{
if (!entitiesInContact.Contains(e))
{
attack.Execute(DamageInfo.DamageType.physical, damageModifierOnTouch, e);
entitiesInContact.Add(e);
StartCoroutine(_OnContinuousTouch(e));
}
}
}
示例5: TryToPickup
public bool TryToPickup(GameObject obj) {
var new_item = obj.GetComponent<Rigidbody> ();
if (new_item == null)
new_item = obj.GetComponentInParent<Rigidbody> ();
if (new_item != null && !new_item.isKinematic) {
Pickup (new_item);
return true;
} else {
Debug.Log ("Can't pick up " + obj.name);
return false;
}
}
示例6: GetActor
protected IInteractionActor GetActor(GameObject other) {
if (!_cachedActorMap.ContainsKey(other)) {
// cache miss - grab from other object using GetComponent
IInteractionActor actor = other.GetComponentInParent<IInteractionActor>();
if (actor == null) {
Debug.LogError("InteractionZone entered by GameObject without InteractionZoneActor script");
return null;
}
_cachedActorMap[other] = actor;
}
return _cachedActorMap[other];
}
示例7: SetupObject
private static void SetupObject(string objectName)
{
selectedObject = Selection.activeGameObject;
theThing.name = objectName;
if (selectedObject)
{
if (GameObject.Find(selectedObject.name))
{
if (selectedObject.GetComponentInParent<Canvas>())
notCanvas = false;
else
notCanvas = true;
}
else
notCanvas = true;
}
else
notCanvas = true;
if (notCanvas)
{
if (!GameObject.FindObjectOfType<UnityEngine.EventSystems.EventSystem>())
{
GameObject.Instantiate(AssetDatabase.LoadAssetAtPath("Assets/MaterialUI/ComponentPrefabs/EventSystem.prefab",
typeof (GameObject))).name = "EventSystem";
}
if (GameObject.FindObjectOfType<Canvas>())
{
selectedObject = GameObject.FindObjectOfType<Canvas>().gameObject as GameObject;
}
else
{
selectedObject =
GameObject.Instantiate(AssetDatabase.LoadAssetAtPath("Assets/MaterialUI/ComponentPrefabs/Canvas.prefab",
typeof (GameObject))) as GameObject;
selectedObject.name = "Canvas";
}
}
theThing.transform.SetParent(selectedObject.transform);
theThing.transform.localPosition = Vector3.zero;
theThing.transform.localScale = new Vector3(1, 1, 1);
Selection.activeGameObject = theThing;
}
示例8: GetItemInfo
private ItemInfo GetItemInfo(GameObject selected)
{
if (selected == null) return null;
foreach (var info in _items)
{
if (info.Control == selected)
return info;
}
//we only use the first parent, in the case of nested listboxes
var parentItem = selected.GetComponentInParent<ListBoxItem>();
var parent = parentItem == null ? null : parentItem.gameObject;
foreach(var info in _items)
{
if (info.Control == parent)
return info;
}
return null;
}
示例9: Start
void Start () {
cameraAudio = GetComponent<AudioSource> ();
parent = GameObject.Find("PlayerCam");
cameraHeldUp = new Vector3( 0.009f, 0.030f,-0.100f);
cameraHeldDown = new Vector3( 0.293f,-0.499f, 0.300f);
photoReview = false;
// Set portrait lens
/*curLens = GameObject.Find (currentLens);
curLens.GetComponent<MeshRenderer> ().enabled = true;
parent.GetComponentInParent<DepthOfField> ().focalSize = curLens.GetComponent<Lens> ().focalSize;
parent.GetComponentInParent<DepthOfField> ().focalLength = curLens.GetComponent<Lens> ().focalDistance;
parent.GetComponentInParent<Camera> ().fieldOfView = curLens.GetComponent<Lens> ().fieldOfView;
*/
FilterPrefab.SetActive (false);
lensIter = 0;
filterIter = 0;
memCardReader = GameObject.Find("/MemoryCardManager").GetComponent<MemoryCardReader>();
PlayerProfile.profile.load ();
currentLens = PlayerProfile.profile.lensesInBag[0];
curLens = GameObject.Find (currentLens);
curLens.GetComponent<MeshRenderer> ().enabled = true;
parent.GetComponentInParent<DepthOfField> ().focalSize = curLens.GetComponent<Lens> ().focalSize;
parent.GetComponentInParent<DepthOfField> ().focalLength = curLens.GetComponent<Lens> ().focalDistance;
parent.GetComponentInParent<Camera> ().fieldOfView = curLens.GetComponent<Lens> ().fieldOfView;
/*foreach (string s in PlayerProfile.profile.lensesInBag) {
Debug.Log ("Lens " + s);
}
foreach (string s in PlayerProfile.profile.filtersInBag) {
Debug.Log ("Filters " + s);
}*/
}
示例10: DoCollide
private void DoCollide(GameObject collidedObject)
{
Collider other = collidedObject.GetComponent<Collider>();
if (ignoreColliders != null && ignoreColliders.Contains(other))
return;
IInteractable interactable = collidedObject.GetComponentInParent<IInteractable>();
if (interactable != null)
{
if (interactable is Entity)
{
CharController controller = collidedObject.GetComponent<CharController>();
if (controller) controller.Hit();
}
float strBonus = str ? str.Value * 0.5f : 0;
AttackAction attack = owner.GetComponent<AttackAction>();
if (attack)
attack.Execute(strBonus, interactable);
}
SimulateImpact(collidedObject, impactMultiplier, true);
}
示例11: setupTextButtonBoard
/// <summary>
/// Create the content of a board, which content is a set of TextButton.
/// </summary>
/// <param name="texts">The text array should be displayed on a set of TextButtons</param>
/// <param name="buttonPrefab">prefab of the TextButton, which could be customized by developers</param>
/// <param name="contentGameObject">parent GameObject that the created a set of TextButtons should be child of</param>
/// <param name="toBottom">whether the content of board should scroll to bottom when shown</param>
/// <param name="onclick">function to be called when responding TextButton is clicked</param>
/// <param name="parameters">parameter array should be attached to the TextButton and would be passed to the on click function</param>
public void setupTextButtonBoard(List<string> texts, GameObject buttonPrefab, GameObject contentGameObject, bool toBottom, UnityAction<bool, System.Object> onclick, List<System.Object> parameters)
{
//Destroy all previous text buttons
for (int i = 0; i < contentGameObject.transform.childCount; i++) {
GameObject.Destroy(contentGameObject.transform.GetChild(i).gameObject);
}
//Create a list of log text button
List<GameObject> textButtons = new List<GameObject>();
for (int i = 0; i < texts.Count; i++) {
GameObject newTextButton = this.createTextButton(texts[i], buttonPrefab, contentGameObject, onclick, parameters[i]);
if (textButtons.Count > 0) {
newTextButton.transform.localPosition = textButtons[textButtons.Count - 1].transform.localPosition;
newTextButton.transform.localPosition = new Vector3(newTextButton.transform.localPosition.x,
newTextButton.transform.localPosition.y - newTextButton.GetComponent<RectTransform>().rect.height*1f,
newTextButton.transform.localPosition.z);
}
textButtons.Add(newTextButton);
}
//Resize the backLogText
float height = (textButtons.Count + 1) * textButtons[0].GetComponent<RectTransform>().rect.height;
float width = contentGameObject.GetComponent<RectTransform>().rect.width;
contentGameObject.GetComponent<RectTransform>().sizeDelta = new Vector2(width, height);
//Scroll to the bottom
if (toBottom) {
contentGameObject.GetComponentInParent<ScrollRect>().normalizedPosition = new Vector2(0, 0);
}
}
示例12: ExtractRootParentFrom
GameObject ExtractRootParentFrom(GameObject theObject)
{
// try to get the player GameObject from this Flowchart's GameObject
Persona personaScript = theObject.GetComponent<Persona>();
// if it wasn't there
if (personaScript == null)
{
// try to get the Persona from this flowchart's parents
personaScript = theObject.GetComponentInParent<Persona>();
}
// if we found the Persona component
if (personaScript != null)
{ // return it's GameObject
return personaScript.gameObject;
}
// couldn't find it (this is an error
Debug.LogError("Couldn't find root parent object");
return null;
}
示例13: MouseClick
public virtual void MouseClick(GameObject hitGameObject, Vector3 hitPoint, Player player)
{
if (isSelected == false)
{
return;
}
if (hitGameObject == null)
{
return;
}
bool isGround = hitGameObject.CompareTag(Tags.GROUND);
if (isGround == true)
{
return;
}
Destructible hitEntity = hitGameObject.GetComponentInParent<Destructible>();
if (hitEntity == null)
{
return;
}
if (hitEntity == this)
{
return;
}
bool readyToAttack = IsAbleToAttack();
if (readyToAttack == false)
{
ChangeSelection(hitEntity, player);
return;
}
if (hitEntity.MaxHitPoints == 0)
{
ChangeSelection(hitEntity, player);
return;
}
Player hitEntityOwner = hitEntity.Owner;
if (hitEntityOwner != null)
{
bool samePlayer = Owner.PlayerId == hitEntityOwner.PlayerId;
if (samePlayer == true)
{
ChangeSelection(hitEntity, player);
return;
}
}
SetAttackTarget(hitEntity);
}
示例14: Loot
public Loot(GameObject agent, GameObject cell)
: base(agent, TaskType.Loot)
{
this.cell = cell;
hive = cell.GetComponentInParent<HiveWarehouse>();
}
示例15: GetPartByGameObject
/// <summary>
/// Finds the part by the GameObject belongs to.
/// </summary>
/// <param name="gameObject">GameObject of a part</param>
/// <returns>the part</returns>
/// <remarks>Thanks goes to xEvilReeperx! :-)</remarks>
/// <see cref="http://forum.kerbalspaceprogram.com/threads/7544-The-official-unoffical-help-a-fellow-plugin-developer-thread?p=2124761&viewfull=1#post2124761"/>
public Part GetPartByGameObject(GameObject gameObject)
{
return gameObject.GetComponentInParent<Part>();
}