Assets/WatsonCore/Utilities/Utility.cs
/// <summary>
/// Finds the object in child of parent object by name of child
/// </summary>
/// <returns>The object.</returns>
/// <param name="parent">Parent Object.</param>
/// <param name="nameChild">Name child.</param>
Finds the object in child of parent object by name of child
Finds the object in child of parent object by name of child
public static GameObject FindObject(GameObject parent, string nameChild)
        {
            GameObject childObject = null;
            string[] childPath = nameChild.Split('/');
            for (int i = 0; i < childPath.Length; i++)
            {
                string childTransformName = childPath[i];
                Transform[] childerenTransform = parent.GetComponentsInChildren<Transform>(includeInactive: true);
                if (childerenTransform != null)
                {
                    foreach (Transform item in childerenTransform)
                    {
                        if (string.Equals(item.name, childTransformName))
                        {
                            if (i == childPath.Length - 1)
                            {
                                childObject = item.gameObject;
                            }
                            else
                            {
                                parent = item.gameObject;
                            }
                            break;
                        }
                    }
                }
            }
            return childObject;
        }
public static GameObject FindObject ( GameObject parent , string nameChild ) { GameObject childObject = null ; string [ ] childPath = nameChild . Split ( ' ' ) ; for ( int i = 0 ; i < childPath . Length ; i ++ ) { string childTransformName = childPath [ i ] ; Transform [ ] childerenTransform = parent . GetComponentsInChildren < Transform > ( includeInactive : true ) ; if ( childerenTransform != null ) { foreach ( Transform item in childerenTransform ) { if ( string . Equals ( item . name , childTransformName ) ) { if ( i == childPath . Length - 1 ) { childObject = item . gameObject ; } else { parent = item . gameObject ; } break ; } } } } return childObject ; }
Finds the object in child of parent object by name of child
Finds the object in child of parent object by name of child
None
parent
GameObject
None
nameChild
string
None