Пример #1
0
        public void OnClicked(HierarchyItem drawer)
        {
            if (currentlySelectedDrawer == drawer)
            {
                if (OnItemDoubleClicked != null)
                {
                    if (!drawer.IsNull() && Time.realtimeSinceStartup - lastClickTime <= doubleClickThreshold)
                    {
                        lastClickTime = 0f;
                        if (drawer is HierarchyItemTransform)
                        {
                            Transform target = ((HierarchyItemTransform)drawer).BoundTransform;
                            if (!target.IsNull())
                            {
                                OnItemDoubleClicked(target);
                            }
                        }
                    }
                    else
                    {
                        lastClickTime = Time.realtimeSinceStartup;
                    }
                }

                return;
            }

            lastClickTime = Time.realtimeSinceStartup;

            if (!currentlySelectedDrawer.IsNull())
            {
                currentlySelectedDrawer.IsSelected = false;
            }

            currentlySelectedDrawer = drawer;

            if (!drawer.IsNull())
            {
                drawer.IsSelected = true;

                if (drawer is HierarchyItemTransform)
                {
                    CurrentSelection = ((HierarchyItemTransform)drawer).BoundTransform;
                }
                else
                {
                    CurrentSelection = null;
                }
            }
            else
            {
                CurrentSelection = null;
            }
        }
Пример #2
0
        private HierarchyItem InstantiateDrawer(List <HierarchyItem> drawerPool, HierarchyItem drawerPrefab, Transform drawerParent)
        {
            for (int i = drawerPool.Count - 1; i >= 0; i--)
            {
                HierarchyItem instance = drawerPool[i];
                drawerPool.RemoveAt(i);

                if (!instance.IsNull())
                {
                    instance.transform.SetParent(drawerParent, false);
                    instance.gameObject.SetActive(true);
                    instance.Hierarchy = this;
                    instance.Skin      = Skin;

                    return(instance);
                }
            }

            HierarchyItem result = (HierarchyItem)Instantiate(drawerPrefab, drawerParent, false);

            result.Hierarchy = this;
            result.Skin      = Skin;

            return(result);
        }
Пример #3
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() && !wasExpanded)
            {
                IsExpanded = false;
            }

            return(null);
        }
Пример #4
0
        public void OnClicked(HierarchyItem drawer)
        {
            if (currentlySelectedDrawer == drawer)
            {
                if (OnItemDoubleClicked != null)
                {
                    if (!drawer.IsNull() && Time.realtimeSinceStartup - lastClickTime <= m_doubleClickThreshold)
                    {
                        lastClickTime = 0f;
                        if (drawer is HierarchyItemTransform)
                        {
                            Transform target = ((HierarchyItemTransform)drawer).BoundTransform;
                            if (!target.IsNull())
                            {
                                OnItemDoubleClicked(target);
                            }
                        }
                    }
                    else
                    {
                        lastClickTime = Time.realtimeSinceStartup;
                    }
                }

                return;
            }

            lastClickTime = Time.realtimeSinceStartup;

            if (!currentlySelectedDrawer.IsNull())
            {
                currentlySelectedDrawer.IsSelected = false;
            }

            currentlySelectedDrawer = drawer;

            if (!drawer.IsNull())
            {
                drawer.IsSelected = true;

                if (drawer is HierarchyItemTransform)
                {
                    Transform clickedTransform = ((HierarchyItemTransform)drawer).BoundTransform;
                    CurrentSelection = clickedTransform;

                    if (drawer is HierarchyItemSearchEntry && !clickedTransform.IsNull())
                    {
                        // Fetch the object's path and show it in Hierarchy
                        System.Text.StringBuilder sb = new System.Text.StringBuilder(200).AppendLine("Path:");

                        while (!clickedTransform.IsNull())
                        {
                            sb.Append("  ").AppendLine(clickedTransform.name);
                            clickedTransform = clickedTransform.parent;
                        }

                        selectedPathText.text = sb.Append("  ").Append(drawer.GetComponentInParent <HierarchyItemRoot>().Content.Name).ToString();
                        selectedPathBackground.gameObject.SetActive(true);
                    }
                }
                else
                {
                    CurrentSelection = null;
                }
            }
            else
            {
                CurrentSelection = null;
            }
        }