Ejemplo n.º 1
0
        //public HierarchyItem SelectTransform( Transform target, Transform nextInPath = null )
        //{
        //	bool wasExpanded = IsExpanded;
        //	if( !wasExpanded )
        //		IsExpanded = true;
        //	else
        //		Refresh();

        //	if( nextInPath == null )
        //		nextInPath = target.root;

        //	HierarchyItem result = null;
        //	for( int i = 0; i < children.Count; i++ )
        //	{
        //		if( children[i].BoundTransform == target )
        //		{
        //			Hierarchy.OnClicked( children[i] );
        //			result = children[i];

        //			break;
        //		}
        //		else if( children[i].BoundTransform == nextInPath )
        //		{
        //			Transform next = target;
        //			Transform parent = next.parent;
        //			while( parent != null && parent != nextInPath )
        //			{
        //				next = parent;
        //				parent = next.parent;
        //			}

        //			if( parent != null )
        //				result = children[i].SelectTransform( target, next );

        //			break;
        //		}
        //	}

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

        //	return result;
        //}

        public HierarchyItem SelectTransform(Transform target, Transform nextInPath = null)
        {
            bool isInitSearch = nextInPath == null;

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

            RefreshContent();

            int childIndex = IndexOf(nextInPath);

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

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

            bool wasExpanded = IsExpanded;

            if (!wasExpanded)
            {
                IsExpanded = true;
            }

            HierarchyItemTransform childItem = children[childIndex];

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

            HierarchyItem 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.SelectTransform(target, next);

                    if (result.IsNull())
                    {
                        result = null;
                    }
                }
            }

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

            return(result);
        }
Ejemplo n.º 2
0
        public virtual void Refresh()
        {
            if (!IsValid)
            {
                Unbind();
                return;
            }

            RefreshContent();

            if (m_isExpanded)
            {
                for (int i = children.Count - 1; i >= 0; i--)
                {
                    if (children[i].BoundTransform.IsNull())
                    {
                        children[i].Unbind();
                        children.RemoveAt(i);
                    }
                }

                int index;
                int childCount = ChildCount;
                for (index = 0; index < childCount; index++)
                {
                    Transform child = GetChild(index);
                    if (children.Count <= index)
                    {
                        GenerateChildItem(child, index);
                    }
                    else if (children[index].BoundTransform != child)
                    {
                        int childIndex;
                        for (childIndex = 0; childIndex < children.Count; childIndex++)
                        {
                            if (children[childIndex].BoundTransform == child)
                            {
                                break;
                            }
                        }

                        if (childIndex == children.Count)
                        {
                            GenerateChildItem(child, index);
                        }
                        else
                        {
                            HierarchyItemTransform childItem = children[childIndex];

                            children.RemoveAt(childIndex);
                            children.Insert(index, childItem);

                            childItem.transform.SetSiblingIndex(index);
                        }
                    }

                    ((HierarchyItem)children[index]).IsActive = children[index].BoundTransform.gameObject.activeInHierarchy;
                    children[index].Refresh();
                }

                for (int i = children.Count - 1; i >= index; i--)
                {
                    children[i].Unbind();
                    children.RemoveAt(i);
                }
            }

            if (ChildCount == 0)
            {
                if (expandToggle.gameObject.activeSelf)
                {
                    expandToggle.gameObject.SetActive(false);
                    IsExpanded = false;
                }
            }
            else if (!expandToggle.gameObject.activeSelf)
            {
                expandToggle.gameObject.SetActive(true);
            }
        }