Esempio n. 1
0
        public HierarchyDataTransform FindTransform(Transform target, Transform nextInPath = null)
        {
            if (m_depth < 0)              // This object is hidden from Hierarchy
            {
                return(null);
            }

            bool isInitSearch = nextInPath == null;

            if (isInitSearch)
            {
                nextInPath = (this is HierarchyDataRootSearch) ? target : target.root;

                // In the current implementation, FindTransform is only called from RuntimeHierarchy.Select which
                // automatically calls RefreshContent prior to FindTransform
                //( (HierarchyDataRoot) this ).RefreshContent();
            }

            int childIndex = IndexOf(nextInPath);

            if (childIndex < 0)
            {
                if (isInitSearch && this is HierarchyDataRootPseudoScene)
                {
                    nextInPath = target;
                    childIndex = IndexOf(nextInPath);
                    while (childIndex < 0 && nextInPath != null)
                    {
                        nextInPath = nextInPath.parent;
                        childIndex = IndexOf(nextInPath);
                    }

                    if (childIndex < 0)
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }

            if (!CanExpand)
            {
                return(null);
            }

            bool wasExpanded = IsExpanded;

            if (!wasExpanded)
            {
                IsExpanded = true;
            }

            HierarchyDataTransform childItem = children[childIndex];

            if (childItem.BoundTransform == target)
            {
                return(childItem);
            }

            HierarchyDataTransform result = null;

            if (childItem.BoundTransform == nextInPath)
            {
                Transform next   = target;
                Transform parent = next.parent;
                while (parent != null && parent != nextInPath)
                {
                    next   = parent;
                    parent = next.parent;
                }

                if (parent != null)
                {
                    result = childItem.FindTransform(target, next);
                }
            }

            if (result != null && result.m_depth < 0)
            {
                result = null;
            }

            if (result == null && !wasExpanded)
            {
                IsExpanded = false;
            }

            return(result);
        }
Esempio n. 2
0
        public HierarchyDataTransform FindTransform(Transform target, Transform nextInPath = null)
        {
            bool isInitSearch = nextInPath == null;

            if (isInitSearch)
            {
                nextInPath = target.root;
                ((HierarchyDataRoot)this).RefreshContent();
            }

            int childIndex = IndexOf(nextInPath);

            if (childIndex < 0)
            {
                if (isInitSearch && this is HierarchyDataRootPseudoScene)
                {
                    nextInPath = target;
                    childIndex = IndexOf(nextInPath);
                    while (childIndex < 0 && nextInPath != null)
                    {
                        nextInPath = nextInPath.parent;
                        childIndex = IndexOf(nextInPath);
                    }

                    if (childIndex < 0)
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }

            if (!CanExpand)
            {
                return(null);
            }

            bool wasExpanded = IsExpanded;

            if (!wasExpanded)
            {
                IsExpanded = true;
            }

            HierarchyDataTransform childItem = children[childIndex];

            if (childItem.BoundTransform == target)
            {
                return(childItem);
            }

            HierarchyDataTransform result = null;

            if (childItem.BoundTransform == nextInPath)
            {
                Transform next   = target;
                Transform parent = next.parent;
                while (parent != null && parent != nextInPath)
                {
                    next   = parent;
                    parent = next.parent;
                }

                if (parent != null)
                {
                    result = childItem.FindTransform(target, next);
                }
            }

            if (result != null && result.m_depth < 0)
            {
                result = null;
            }

            if (result == null && !wasExpanded)
            {
                IsExpanded = false;
            }

            return(result);
        }