Ejemplo n.º 1
0
        public void RebuildTree(IPanelDebug panelDebug)
        {
            if (!hierarchyHasChanged && m_CurrentPanelDebug == panelDebug)
            {
                return;
            }

            m_CurrentPanelDebug = panelDebug;
            m_Container.Clear();

            int nextId = 1;

            m_TreeRootItems.Clear();

            var visualTree = panelDebug?.visualTree;

            if (visualTree != null)
            {
                var rootItem = new TreeViewItemData <VisualElement>(nextId++, visualTree);
                m_TreeRootItems.Add(rootItem);

                var childItems = new List <TreeViewItemData <VisualElement> >();
                AddTreeItemsForElement(childItems, visualTree, ref nextId);

                rootItem.AddChildren(childItems);
            }

            Func <VisualElement> makeItem = () =>
            {
                var element = new VisualElement();
                element.name = "unity-treeview-item-content";
                element.RegisterCallback <MouseEnterEvent>((e) =>
                {
                    HighlightItemInTargetWindow(e.target as VisualElement);
                });
                element.RegisterCallback <MouseLeaveEvent>((e) =>
                {
                    UnhighlightItemInTargetWindow(e.target as VisualElement);
                });
                return(element);
            };

            // Clear selection which would otherwise persist via view data persistence.
            m_TreeView?.ClearSelection();

            m_TreeView = new TreeView(makeItem, FillItem);
            m_TreeView.SetRootItems(treeRootItems);
            m_TreeView.fixedItemHeight            = 20;
            m_TreeView.style.flexGrow             = 1;
            m_TreeView.horizontalScrollingEnabled = true;
            m_TreeView.onSelectedIndicesChange   += items =>
            {
                if (m_SelectElementCallback == null)
                {
                    return;
                }

                if (!items.Any())
                {
                    m_SelectElementCallback(null);
                    return;
                }

                var index   = items.First();
                var element = m_TreeViewController.GetDataForIndex(index);
                m_SelectElementCallback(element);
            };

            m_TreeViewController = m_TreeView.viewController as DefaultTreeViewController <VisualElement>;
            m_Container.Add(m_TreeView);

            hierarchyHasChanged = false;
            m_SearchBar.ClearSearch();
        }
Ejemplo n.º 2
0
        public void RebuildTree(IPanelDebug panelDebug)
        {
            if (!hierarchyHasChanged && m_CurrentPanelDebug == panelDebug)
            {
                return;
            }

            m_CurrentPanelDebug = panelDebug;
            m_Container.Clear();

            int nextId = 1;

            m_TreeRootItems.Clear();

            var visualTree = panelDebug?.visualTree;

            if (visualTree != null)
            {
                var rootItem = new TreeViewItem <VisualElement>(nextId++, visualTree);
                m_TreeRootItems.Add(rootItem);

                var childItems = new List <ITreeViewItem>();
                AddTreeItemsForElement(childItems, visualTree, ref nextId);

                rootItem.AddChildren(childItems);
            }

            Func <VisualElement> makeItem = () =>
            {
                var element = new VisualElement();
                element.name = "unity-treeview-item-content";
                element.RegisterCallback <MouseEnterEvent>((e) =>
                {
                    HighlightItemInTargetWindow(e.target as VisualElement);
                });
                element.RegisterCallback <MouseLeaveEvent>((e) =>
                {
                    UnhighlightItemInTargetWindow(e.target as VisualElement);
                });
                return(element);
            };

            // Clear selection which would otherwise persist via view data persistence.
            m_TreeView?.ClearSelection();

            m_TreeView = new TreeView(m_TreeRootItems, 20, makeItem, FillItem);
            m_TreeView.style.flexGrow     = 1;
            m_TreeView.onSelectionChange += items =>
            {
                if (m_SelectElementCallback == null)
                {
                    return;
                }

                if (!items.Any())
                {
                    m_SelectElementCallback(null);
                    return;
                }

                var item    = items.First() as TreeViewItem <VisualElement>;
                var element = item != null ? item.data : null;
                m_SelectElementCallback(element);
            };

            m_Container.Add(m_TreeView);

            hierarchyHasChanged = false;
            m_SearchBar.ClearSearch();
        }