DoGetChildByName() static private méthode

static private DoGetChildByName ( GameObject root, string name, string tag ) : GameObject
root UnityEngine.GameObject
name string
tag string
Résultat UnityEngine.GameObject
Exemple #1
0
        private static GameObject DoGetChildByName(GameObject root, string name, string tag)
        {
            if (root == null)
            {
                return(null);
            }
            IEnumerator enumerator = root.transform.GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    object    obj       = enumerator.Current;
                    Transform transform = (Transform)obj;
                    if (!string.IsNullOrEmpty(name))
                    {
                        if (transform.name == name)
                        {
                            if (string.IsNullOrEmpty(tag))
                            {
                                return(transform.gameObject);
                            }
                            if (transform.tag.Equals(tag))
                            {
                                return(transform.gameObject);
                            }
                        }
                    }
                    else if (!string.IsNullOrEmpty(tag) && transform.CompareTag(tag))
                    {
                        return(transform.gameObject);
                    }
                    GameObject gameObject = GetChild.DoGetChildByName(transform.gameObject, name, tag);
                    if (gameObject != null)
                    {
                        return(gameObject);
                    }
                }
            }
            finally
            {
                IDisposable disposable;
                if ((disposable = (enumerator as IDisposable)) != null)
                {
                    disposable.Dispose();
                }
            }
            return(null);
        }
Exemple #2
0
 private static GameObject DoGetChildByName(GameObject root, string name, string tag)
 {
     if (root == null)
     {
         return(null);
     }
     foreach (Transform transform in root.transform)
     {
         if (!string.IsNullOrEmpty(name))
         {
             if (transform.name == name)
             {
                 if (string.IsNullOrEmpty(tag))
                 {
                     GameObject result = transform.gameObject;
                     return(result);
                 }
                 if (transform.tag.Equals(tag))
                 {
                     GameObject result = transform.gameObject;
                     return(result);
                 }
             }
         }
         else if (!string.IsNullOrEmpty(tag) && transform.CompareTag(tag))
         {
             GameObject result = transform.gameObject;
             return(result);
         }
         GameObject gameObject = GetChild.DoGetChildByName(transform.gameObject, name, tag);
         if (gameObject != null)
         {
             GameObject result = gameObject;
             return(result);
         }
     }
     return(null);
 }
Exemple #3
0
 public override void OnEnter()
 {
     this.storeResult.Value = GetChild.DoGetChildByName(base.Fsm.GetOwnerDefaultTarget(this.gameObject), this.childName.Value, this.withTag.Value);
     base.Finish();
 }