Пример #1
0
        public void PoolDrawer(HierarchyItem drawer)
        {
            if (drawer == currentlySelectedDrawer)
            {
                currentlySelectedDrawer = null;
                m_currentSelection      = null;
            }

            if (drawer is HierarchyItemTransform)
            {
                List <HierarchyItem> pool = drawer is HierarchyItemSearchEntry ? searchEntryDrawerPool : transformDrawerPool;
                if (pool.Count < poolCapacity)
                {
                    drawer.gameObject.SetActive(false);
                    drawer.transform.SetParent(poolParent, false);
                    pool.Add(drawer);
                }
                else
                {
                    Destroy(drawer.gameObject);
                }
            }
            else
            {
                drawer.gameObject.SetActive(false);
                drawer.transform.SetParent(poolParent, false);
                sceneDrawerPool.Add(drawer);
            }
        }
Пример #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);
        }
 private void Awake()
 {
     hierarchyItem = GetComponent <HierarchyItem>();
     if (hierarchyItem == null)
     {
         m_hierarchy = GetComponent <RuntimeHierarchy>();
     }
 }
Пример #4
0
        public bool Select(Transform selection)
        {
            if (selection.IsNull())
            {
                Deselect();
                return(true);
            }
            else
            {
                if (selection == CurrentSelection)
                {
                    return(true);
                }

                Scene selectionScene = selection.gameObject.scene;
                for (int i = 0; i < sceneDrawers.Count; i++)
                {
                    IHierarchyRootContent content = sceneDrawers[i].Content;
                    if ((content is HierarchyRootPseudoScene) || ((HierarchyRootScene)content).Scene == selectionScene)
                    {
                        HierarchyItem selectionItem = sceneDrawers[i].SelectTransform(selection);
                        if (selectionItem != null)
                        {
                            if (drawAreaHierarchy.sizeDelta.y > 0f)
                            {
                                // Focus on selected HierarchyItem
                                LayoutRebuilder.ForceRebuildLayoutImmediate(drawAreaHierarchy);
                                Vector3 localPos = drawAreaHierarchy.InverseTransformPoint(selectionItem.transform.position);
                                scrollView.verticalNormalizedPosition = Mathf.Clamp01(1f + localPos.y / drawAreaHierarchy.sizeDelta.y);
                            }

                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Пример #5
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);
        }
Пример #6
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;
            }
        }