public BuilderExplorer(
            BuilderViewport viewport,
            BuilderSelection selection,
            BuilderClassDragger classDragger,
            BuilderHierarchyDragger hierarchyDragger,
            BuilderElementContextMenu contextMenuManipulator,
            VisualElement documentElementRoot,
            HighlightOverlayPainter highlightOverlayPainter,
            string toolbarUxmlPath)
        {
            m_Viewport            = viewport;
            m_DocumentElementRoot = documentElementRoot;
            m_DocumentElement     = viewport.documentElement;
            AddToClassList(s_UssClassName);

            m_ClassDragger           = classDragger;
            m_HierarchyDragger       = hierarchyDragger;
            m_ContextMenuManipulator = contextMenuManipulator;

            m_SelectionMadeExternally = false;

            m_Selection = selection;

            // TODO: Transfer to own USS.
            var sheet = EditorGUIUtility.Load(k_DefaultStyleSheetPath) as StyleSheet;

            styleSheets.Add(sheet);
            StyleSheet colorSheet;

            if (EditorGUIUtility.isProSkin)
            {
                colorSheet = EditorGUIUtility.Load(k_DefaultDarkStyleSheetPath) as StyleSheet;
            }
            else
            {
                colorSheet = EditorGUIUtility.Load(k_DefaultLightStyleSheetPath) as StyleSheet;
            }
            styleSheets.Add(colorSheet);

            // Query the UI
            if (!string.IsNullOrEmpty(toolbarUxmlPath))
            {
                var template = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(toolbarUxmlPath);
                template.CloneTree(this);
            }

            // Create the Hierarchy View.
            m_ElementHierarchyView = new ElementHierarchyView(
                m_DocumentElement,
                selection, classDragger, hierarchyDragger,
                contextMenuManipulator, ElementSelected, highlightOverlayPainter);
            m_ElementHierarchyView.style.flexGrow = 1;
            Add(m_ElementHierarchyView);

            // Make sure the Hierarchy View gets focus when the pane gets focused.
            primaryFocusable = m_ElementHierarchyView.Q <ListView>();

            UpdateHierarchyAndSelection(false);
            m_ShouldRebuildHierarchyOnStyleChange = true;
        }
Beispiel #2
0
        public BuilderExplorer(
            BuilderPaneWindow paneWindow,
            BuilderViewport viewport,
            BuilderSelection selection,
            BuilderClassDragger classDragger,
            BuilderExplorerDragger explorerDragger,
            BuilderElementContextMenu contextMenuManipulator,
            VisualElement documentElementRoot,
            bool includeDocumentElementRoot,
            HighlightOverlayPainter highlightOverlayPainter,
            string toolbarUxmlPath)
        {
            m_PaneWindow                 = paneWindow;
            m_Viewport                   = viewport;
            m_DocumentElementRoot        = documentElementRoot;
            m_IncludeDocumentElementRoot = includeDocumentElementRoot;
            m_DocumentElement            = viewport.documentElement;
            AddToClassList(s_UssClassName);

            m_ClassDragger           = classDragger;
            m_ExplorerDragger        = explorerDragger;
            m_ContextMenuManipulator = contextMenuManipulator;

            m_SelectionMadeExternally = false;

            m_Selection = selection;


            // Query the UI
            if (!string.IsNullOrEmpty(toolbarUxmlPath))
            {
                var template = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(toolbarUxmlPath);
                template.CloneTree(this);
            }

            // Create the Hierarchy View.
            m_ElementHierarchyView = new ElementHierarchyView(
                m_PaneWindow,
                m_DocumentElement,
                selection, classDragger, explorerDragger,
                contextMenuManipulator, ElementSelectionChanged, highlightOverlayPainter);
            m_ElementHierarchyView.style.flexGrow = 1;
            Add(m_ElementHierarchyView);

            // Enable horizontal scrolling.
#if UNITY_2020_2_OR_NEWER
            m_ElementHierarchyView.Q <TreeView>().horizontalScrollingEnabled = true;
#endif

            // Make sure the Hierarchy View gets focus when the pane gets focused.
            primaryFocusable = m_ElementHierarchyView.Q <ListView>();

            UpdateHierarchyAndSelection(false);
            m_ShouldRebuildHierarchyOnStyleChange = true;
        }
        public ElementHierarchySearchBar(ElementHierarchyView parent)
        {
            m_ParentTreeView = parent;
            m_FoundItems     = new List <SearchResultItem>();

            this.AddToClassList("unity-treeview-searchbar");

            m_FieldHelpLabel             = new Label("Search by type, name, or class");
            m_FieldHelpLabel.pickingMode = PickingMode.Ignore;
            m_FieldHelpLabel.AddToClassList("unity-treeview-searchbar-label");
            m_FieldHelpLabel.AddToClassList("unity-treeview-searchbar-label-help");
            Add(m_FieldHelpLabel);

            var field = new TextField();

            field.AddToClassList("unity-treeview-searchbar-field");
            field.RegisterValueChangedCallback(PerformSearch);
            field.RegisterCallback <KeyDownEvent>((e) =>
            {
                var targetField = field;
                if (e.keyCode == KeyCode.F3 || e.keyCode == KeyCode.Return || e.keyCode == KeyCode.KeypadEnter)
                {
                    if (e.modifiers == EventModifiers.Shift)
                    {
                        SelectPrev();
                    }
                    else
                    {
                        SelectNext();
                    }
                }
                else if (e.keyCode == KeyCode.Escape)
                {
                    targetField.value = string.Empty;
                    targetField.visualInput.Blur();
                    m_ParentTreeView.ClearSearchResults();
                    m_ParentTreeView.Focus();
                }
            }, TrickleDown.TrickleDown);
            Add(field);

            m_CountLabel = new Label();
            m_CountLabel.AddToClassList("unity-treeview-searchbar-label");
            m_CountLabel.AddToClassList("unity-treeview-searchbar-hidden");
            Add(m_CountLabel);

            var prevButton = new Button(SelectPrev)
            {
                text = "<"
            };

            prevButton.AddToClassList("unity-treeview-searchbar-button");
            prevButton.AddToClassList("unity-treeview-searchbar-button-prev");
            Add(prevButton);

            var nextButton = new Button(SelectNext)
            {
                text = ">"
            };

            nextButton.AddToClassList("unity-treeview-searchbar-button");
            nextButton.AddToClassList("unity-treeview-searchbar-button-next");
            Add(nextButton);
        }