Esempio n. 1
0
        // TODO: Find should identify unique instance
        // TODO: Check if path is unique for object (with optional root)
        // TODO: Implement forcing of unique name for GameObject
        // - Rename GameObject
        // - Rename all identically named siblings

        // TODO: This should return GameObjects

        /// <returns>the GameObjects specified by this path relative to parent</returns>
        /// <remarks>
        /// If the path matches no GameObjects the returned array will be empty.
        /// An empty path matches parent.
        /// A null parent matches active scene.
        /// </remarks>
        public Transform[] Find(Transform parent = null)
        {
            if (path.Count == 0)
            {
                return new Transform[] { parent }
            }
            ;

            List <Transform> findList = new List <Transform>();

            Transform[] childList = TransformExtensions.Children(parent);
            foreach (var childItem in childList)
            {
                // Evaluate match
                var lhsRecurse = Clone() as PathName;

                var rhsRecurse = new PathName(childItem.name, PathStep.Step.Name);
                if (!MatchStep(lhsRecurse, rhsRecurse))
                {
                    continue;
                }
                findList.AddRange(lhsRecurse.Find(childItem));
            }
            return(findList.ToArray());
        }
Esempio n. 2
0
        /// <returns>an array of all GameObject matching name that are children of parent</returns>
        /// <remarks>
        /// Unlike Transform.Find() path separators are assumed to be a part of the name.
        /// When parent = null the search begins with the scene root.
        /// </remarks>
        public static GameObject[] NameFind(PathName name, Transform parent = null, bool recurse = false)
        {
            List <GameObject> findList = new List <GameObject>();

            Transform[] childList = TransformExtensions.Children(parent);
            foreach (var child in childList)
            {
                if (name == child.name)
                {
                    findList.Add(child.gameObject);
                }
                if (recurse)
                {
                    findList.AddRange(NameFind(name, child, recurse));
                }
            }
            return(findList.ToArray());
        }