コード例 #1
0
        public void Activate(BuilderSelection selection, VisualTreeAsset visualTreeAsset, VisualElement target)
        {
            m_Selection       = selection;
            m_VisualTreeAsset = visualTreeAsset;
            m_Target          = target;

            // On the first RefreshUI, if an element is already selected, we need to make sure it
            // has a valid style. If not, we need to delay our UI building until it is properly initialized.
            if (m_Target != null && float.IsNaN(m_Target.layout.width))
            {
                m_Target.RegisterCallback <GeometryChangedEvent>(RefreshAfterFirstInit);
                return;
            }

            ActivateInner();
        }
コード例 #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.documentRootElement;
            AddToClassList(s_UssClassName);

            m_ClassDragger    = classDragger;
            m_ExplorerDragger = explorerDragger;

            m_SelectionMadeExternally = false;

            m_Selection = selection;

            // Query the UI
            if (!string.IsNullOrEmpty(toolbarUxmlPath))
            {
                var template = BuilderPackageUtilities.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);
            // Make sure the Hierarchy View gets focus when the pane gets focused.
            primaryFocusable = m_ElementHierarchyView;

            UpdateHierarchyAndSelection(false);
            m_ShouldRebuildHierarchyOnStyleChange = true;
        }
コード例 #3
0
        public BuilderLibrary(
            BuilderPaneWindow paneWindow, BuilderViewport viewport,
            BuilderSelection selection, BuilderLibraryDragger dragger,
            BuilderTooltipPreview tooltipPreview)
        {
            m_PaneWindow      = paneWindow;
            m_DocumentElement = viewport.documentElement;
            m_Selection       = selection;
            m_Dragger         = dragger;
            m_TooltipPreview  = tooltipPreview;

            AddToClassList(s_UssClassName);

            BuilderAssetModificationProcessor.Register(this);

            RefreshTreeView();
        }
コード例 #4
0
        public BuilderElementContextMenu(BuilderPaneWindow paneWindow, BuilderSelection selection)
        {
            m_PaneWindow = paneWindow;
            m_Selection  = selection;

            m_WeStartedTheDrag = false;

            activators = new List <ManipulatorActivationFilter>();
            activators.Add(new ManipulatorActivationFilter {
                button = MouseButton.RightMouse
            });
            if (Application.platform == RuntimePlatform.OSXEditor || Application.platform == RuntimePlatform.OSXPlayer)
            {
                activators.Add(new ManipulatorActivationFilter {
                    button = MouseButton.LeftMouse, modifiers = EventModifiers.Control
                });
            }
        }
コード例 #5
0
        public override void CreateUI()
        {
            var root = rootVisualElement;

            // Load assets.
            var saveDialogTemplate = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(BuilderConstants.UIBuilderPackagePath + "/BuilderSaveDialog.uxml");

            // Load template.
            saveDialogTemplate.CloneTree(root);

            // Fetch the save dialog.
            var dialog = root.Q <ModalPopup>("save-dialog");

            // Create selection.
            m_Selection = new BuilderSelection(root, this);

            // Create viewport first.
            m_Viewport = new BuilderViewport(this, selection, null);
            selection.documentElement = m_Viewport.documentElement;

            // Create the rest of the panes.
            m_Toolbar = new BuilderToolbar(this, selection, dialog, m_Viewport, null, null, null, null);
            root.Add(m_Viewport);
            m_Viewport.toolbar.Add(m_Toolbar);

            // Init selection.
            selection.AssignNotifiers(new IBuilderSelectionNotifier[]
            {
                document,
                m_Viewport,
                m_Viewport.parentTracker,
                m_Viewport.resizer,
                m_Viewport.mover,
                m_Viewport.anchorer
            });

            // Command Handler
            commandHandler.RegisterPane(m_Viewport);
            commandHandler.RegisterToolbar(m_Toolbar);

            dialog.BringToFront();

            OnEnableAfterAllSerialization();
        }
コード例 #6
0
 public BuilderHierarchy(
     BuilderViewport viewport,
     BuilderSelection selection,
     BuilderClassDragger classDragger,
     BuilderHierarchyDragger hierarchyDragger,
     BuilderElementContextMenu contextMenuManipulator,
     HighlightOverlayPainter highlightOverlayPainter)
     : base(
         viewport,
         selection,
         classDragger,
         hierarchyDragger,
         contextMenuManipulator,
         viewport.documentElement,
         highlightOverlayPainter,
         null)
 {
     viewDataKey = "builder-hierarchy";
 }
コード例 #7
0
        public BuilderLibrary(
            BuilderPaneWindow paneWindow, BuilderViewport viewport,
            BuilderSelection selection, BuilderLibraryDragger dragger,
            BuilderTooltipPreview tooltipPreview)
        {
            m_PaneWindow      = paneWindow;
            m_DocumentElement = viewport.documentElement;
            m_Selection       = selection;
            m_Dragger         = dragger;
            m_TooltipPreview  = tooltipPreview;

            viewDataKey = "unity-ui-builder-library";

            // Load styles.
            AddToClassList(k_UssClassName);
            styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(BuilderConstants.LibraryUssPathNoExt + ".uss"));
            styleSheets.Add(EditorGUIUtility.isProSkin
                ? AssetDatabase.LoadAssetAtPath <StyleSheet>(BuilderConstants.LibraryUssPathNoExt + "Dark.uss")
                : AssetDatabase.LoadAssetAtPath <StyleSheet>(BuilderConstants.LibraryUssPathNoExt + "Light.uss"));

            var template = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(BuilderConstants.LibraryUssPathNoExt + ".uxml");

            template.CloneTree(this);

            m_EditorExtensionMode     = paneWindow.document.UXMLFileSettings.EditorExtensionMode;
            m_LibraryContentContainer = this.Q <VisualElement>(k_ContentContainerName);

            m_HeaderButtonStrip         = this.Q <ToggleButtonStrip>();
            m_HeaderButtonStrip.choices = Enum.GetNames(typeof(BuilderLibraryTab));
            m_HeaderButtonStrip.labels  = new List <string> {
                BuilderConstants.LibraryStandardControlsTabName, BuilderConstants.LibraryProjectTabName
            };
            m_HeaderButtonStrip.RegisterValueChangedCallback(e =>
            {
                m_ActiveTab = (BuilderLibraryTab)Enum.Parse(typeof(BuilderLibraryTab), e.newValue);
                SaveViewData();
                RefreshView();
            });

            AddFocusable(m_HeaderButtonStrip);
            BuilderLibraryContent.OnLibraryContentUpdated += RebuildView;
        }
コード例 #8
0
        public BuilderViewport(BuilderPaneWindow paneWindow, BuilderSelection selection)
        {
            m_PaneWindow = paneWindow;
            m_Selection  = selection;

            AddToClassList("unity-builder-viewport");

            var template = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(BuilderConstants.UIBuilderPackagePath + "/BuilderViewport.uxml");

            template.CloneTree(this);

            m_Toolbar         = this.Q("toolbar");
            m_ViewportWrapper = this.Q("viewport-wrapper");
            m_Viewport        = this.Q("viewport");
            m_Canvas          = this.Q <BuilderCanvas>("canvas");
            m_Canvas.document = paneWindow.document;
            m_SharedStylesAndDocumentElement = this.Q("shared-styles-and-document");
            m_StyleSelectorElementContainer  = this.Q(BuilderConstants.StyleSelectorElementContainerName);
            m_DocumentElement      = this.Q("document");
            m_PickOverlay          = this.Q("pick-overlay");
            m_HighlightOverlay     = this.Q("highlight-overlay");
            m_BuilderParentTracker = this.Q <BuilderParentTracker>("parent-tracker");
            m_BuilderResizer       = this.Q <BuilderResizer>("resizer");
            m_BuilderMover         = this.Q <BuilderMover>("mover");
            m_BuilderAnchorer      = this.Q <BuilderAnchorer>("anchorer");
            m_FitCanvasButton      = this.Q <Button>("fit-canvas-button");

            m_FitCanvasButton.clickable.clicked += FitCanvas;
            m_Canvas.RegisterCallback <GeometryChangedEvent>(VerifyCanvasStillFitsViewport);
            m_Viewport.RegisterCallback <GeometryChangedEvent>(VerifyCanvasStillFitsViewport);

            m_BuilderMover.parentTracker = m_BuilderParentTracker;

            m_PickOverlay.RegisterCallback <MouseDownEvent>(OnPick);
            m_PickOverlay.RegisterCallback <MouseMoveEvent>(OnHover);
            m_PickOverlay.RegisterCallback <MouseLeaveEvent>(OnMouseLeave);
            m_Viewport.RegisterCallback <MouseDownEvent>(OnMissPick);

            // Make sure this gets focus when the pane gets focused.
            primaryFocusable = this;
            this.focusable   = true;
        }
コード例 #9
0
        public BuilderHierarchy(
            BuilderViewport viewport,
            BuilderSelection selection,
            BuilderClassDragger classDragger,
            BuilderHierarchyDragger hierarchyDragger,
            BuilderElementContextMenu contextMenuManipulator,
            HighlightOverlayPainter highlightOverlayPainter)
            : base(
                viewport,
                selection,
                classDragger,
                hierarchyDragger,
                contextMenuManipulator,
                viewport.documentElement,
                highlightOverlayPainter,
                kToolbarPath)
        {
            viewDataKey = "builder-hierarchy";

            m_HierarchyTypeClassVisibilityMenu = this.Q <ToolbarMenu>("hierarchy-visibility-toolbar-menu");
            SetUpHierarchyVisibilityMenu();
        }
コード例 #10
0
        public BuilderInspectorHeader(BuilderInspector inspector)
        {
            m_Inspector       = inspector;
            m_Selection       = inspector.selection;
            m_Header          = m_Inspector.Q <VisualElement>("header-container");
            m_StatusIndicator = m_Header.Q <FieldStatusIndicator>("header-field-status-indicator");
            m_StatusIndicator.populateMenuItems = (menu) =>
            {
                BuildNameFieldContextualMenu(menu, m_TextField);
            };

            m_InnerHeader = m_Inspector.Q <VisualElement>("header-container-minor");
            m_Icon        = m_Inspector.Q <VisualElement>("header-icon");

            m_Pill = m_Inspector.Q <Label>("header-selected-pill");
            m_Pill.AddToClassList("unity-builder-tag-pill");

            m_TextField             = m_Inspector.Q <TextField>("header-selected-text-field");
            m_TextField.isDelayed   = true;
            m_TextField.tooltip     = "name";
            m_TextField.bindingPath = "name";

            m_EditorWarningHelpBox      = m_Inspector.Q <UnityEngine.UIElements.HelpBox>("header-editor-warning-help-box");
            m_EditorWarningHelpBox.text = BuilderConstants.HeaderSectionHelpBoxMessage;
            m_ErrorIcon = m_Inspector.Q <VisualElement>("header-error-icon");

            // Warning must be hidden at first
            m_ErrorIcon.style.backgroundImage = EditorGUIUtility.LoadIcon("console.erroricon");
            AdjustBottomPadding(false);

            // Store callbacks to reduce delegate allocations
            m_ElementNameChangeCallback    = new EventCallback <ChangeEvent <string> >(OnNameAttributeChange);
            m_SelectorNameChangeCallback   = new EventCallback <ChangeEvent <string> >(OnStyleSelectorNameChange);
            m_SelectorEnterKeyDownCallback = new EventCallback <KeyDownEvent>(OnEnterStyleSelectorNameChange);

            m_TextField.RegisterValueChangedCallback(m_ElementNameChangeCallback);
            m_RightClickManipulator = new ContextualMenuManipulator(BuildNameFieldContextualMenu);
        }
コード例 #11
0
        public BuilderDragger(
            BuilderPaneWindow paneWindow,
            VisualElement root, BuilderSelection selection,
            BuilderViewport viewport, BuilderParentTracker parentTracker)
        {
            m_PaneWindow    = paneWindow;
            m_Root          = root;
            m_Canvas        = viewport.documentElement;
            m_Selection     = selection;
            m_ParentTracker = parentTracker;

            activators = new List <ManipulatorActivationFilter>();
            activators.Add(new ManipulatorActivationFilter {
                button = MouseButton.LeftMouse
            });

            m_Active           = false;
            m_WeStartedTheDrag = false;

            m_DraggedElement = CreateDraggedElement();
            m_DraggedElement.AddToClassList(s_DraggerPreviewClassName);
            m_Root.Add(m_DraggedElement);
        }
コード例 #12
0
        public BuilderInspectorInheritedStyles(BuilderInspector inspector, BuilderInspectorMatchingSelectors matchingSelectors)
        {
            m_Inspector         = inspector;
            m_Selection         = inspector.selection;
            m_PaneWindow        = inspector.paneWindow;
            m_MatchingSelectors = matchingSelectors;

            m_InheritedStylesSection   = m_Inspector.Q <PersistedFoldout>("inspector-inherited-styles-foldout");
            m_ClassListContainer       = m_Inspector.Q("class-list-container");
            m_MatchingSelectorsFoldout = m_Inspector.Q <PersistedFoldout>("matching-selectors-container");

            m_AddClassField           = m_Inspector.Q <TextField>("add-class-field");
            m_AddClassField.isDelayed = true;
            m_AddClassField.RegisterCallback <KeyUpEvent>(OnAddClassFieldChange);

            m_AddClassButton    = m_Inspector.Q <Button>("add-class-button");
            m_CreateClassButton = m_Inspector.Q <Button>("create-class-button");

            m_ClassPillTemplate = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(
                BuilderConstants.UIBuilderPackagePath + "/BuilderClassPill.uxml");

            m_AddClassButton.clickable.clicked    += AddStyleClass;
            m_CreateClassButton.clickable.clicked += ExtractLocalStylesToNewClass;
        }
コード例 #13
0
        public BuilderInspector(BuilderPaneWindow paneWindow, BuilderSelection selection)
        {
            // Yes, we give ourselves a view data key. Don't do this at home!
            viewDataKey = "unity-ui-builder-inspector";

            // Init External References
            m_Selection  = selection;
            m_PaneWindow = paneWindow;

            // Load Template
            var template = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(
                BuilderConstants.UIBuilderPackagePath + "/Inspector/BuilderInspector.uxml");

            template.CloneTree(this);

            // Get the scroll view.
            // HACK: ScrollView is not capable of remembering a scroll position for content that changes often.
            // The main issue is that we expande/collapse/display/hide different parts of the Inspector
            // all the time so initially the ScrollView is empty and it restores the scroll position to zero.
            m_ScrollView = this.Q <ScrollView>("inspector-scroll-view");
            m_ScrollView.contentContainer.RegisterCallback <GeometryChangedEvent>(OnScrollViewContentGeometryChange);
            m_ScrollView.verticalScroller.valueChanged += (newValue) =>
            {
                CacheScrollPosition(newValue, m_ScrollView.verticalScroller.highValue);
                SaveViewData();
            };

            // Load styles.
            AddToClassList(s_UssClassName);
            styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(BuilderConstants.InspectorUssPathNoExt + ".uss"));
            if (EditorGUIUtility.isProSkin)
            {
                styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(BuilderConstants.InspectorUssPathNoExt + "Dark.uss"));
            }
            else
            {
                styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(BuilderConstants.InspectorUssPathNoExt + "Light.uss"));
            }

            // Matching Selectors
            m_MatchingSelectors = new BuilderInspectorMatchingSelectors(this);

            // Style Fields
            m_StyleFields = new BuilderInspectorStyleFields(this);

            // Sections
            m_Sections = new List <VisualElement>();

            // Nothing Selected Section
            m_NothingSelectedSection = this.Q <Label>("nothing-selected-label");
            m_Sections.Add(m_NothingSelectedSection);

            // Canvas Section
            m_CanvasSection = new BuilderInspectorCanvas(this);
            m_Sections.Add(m_CanvasSection.root);

            // StyleSheet Section
            m_StyleSheetSection = new BuilderInspectorStyleSheet(this);
            m_Sections.Add(m_StyleSheetSection.root);

            // Style Selector Section
            m_SelectorSection = new BuilderInspectorSelector(this);
            m_Sections.Add(m_SelectorSection.root);

            // Attributes Section
            m_AttributesSection = new BuilderInspectorAttributes(this);
            m_Sections.Add(m_AttributesSection.root);

            // Inherited Styles Section
            m_InheritedStyleSection = new BuilderInspectorInheritedStyles(this, m_MatchingSelectors);
            m_Sections.Add(m_InheritedStyleSection.root);

            // Local Styles Section
            m_LocalStylesSection = new BuilderInspectorLocalStyles(this, m_StyleFields);
            m_Sections.Add(m_LocalStylesSection.root);

            // This will take into account the current selection and then call RefreshUI().
            SelectionChanged();

            // Forward focus to the panel header.
            this.Query().Where(e => e.focusable).ForEach((e) => AddFocusable(e));
        }
コード例 #14
0
 public BuilderUssPreview(BuilderPaneWindow paneWindow, BuilderSelection selection) : base(paneWindow)
 {
     m_Selection = selection;
 }
コード例 #15
0
 public BuilderHierarchyContextMenu(BuilderPaneWindow paneWindow, BuilderSelection selection)
     : base(paneWindow, selection)
 {
 }
コード例 #16
0
        public BuilderStyleSheets(
            BuilderViewport viewport,
            BuilderSelection selection,
            BuilderClassDragger classDragger,
            BuilderHierarchyDragger hierarchyDragger,
            BuilderExplorerContextMenu contextMenuManipulator,
            HighlightOverlayPainter highlightOverlayPainter,
            BuilderTooltipPreview tooltipPreview)
            : base(
                viewport,
                selection,
                classDragger,
                hierarchyDragger,
                contextMenuManipulator,
                viewport.styleSelectorElementContainer,
                highlightOverlayPainter,
                kToolbarPath)
        {
            m_TooltipPreview = tooltipPreview;
            if (m_TooltipPreview != null)
            {
                var helpTooltipTemplate  = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(kHelpTooltipPath);
                var helpTooltipContainer = helpTooltipTemplate.CloneTree();
                m_TooltipPreview.Add(helpTooltipContainer); // We are the only ones using it so just add the contents and be done.
            }

            viewDataKey = "builder-style-sheets";
            AddToClassList(BuilderConstants.ExplorerStyleSheetsPaneClassName);

            var parent = this.Q("new-selector-item");

            // Init text field.
            m_NewSelectorTextField = parent.Q <TextField>("new-selector-field");
            m_NewSelectorTextField.SetValueWithoutNotify(BuilderConstants.ExplorerInExplorerNewClassSelectorInfoMessage);
            m_NewSelectorTextInputField = m_NewSelectorTextField.Q("unity-text-input");
            m_NewSelectorTextInputField.RegisterCallback <KeyDownEvent>(OnEnter, TrickleDown.TrickleDown);

            m_NewSelectorTextInputField.RegisterCallback <FocusEvent>((evt) =>
            {
                var input = evt.target as VisualElement;
                var field = input.parent as TextField;
                m_FieldFocusedFromStandby = true;
                if (field.text == BuilderConstants.ExplorerInExplorerNewClassSelectorInfoMessage || m_NewSelectorJustCreated)
                {
                    m_NewSelectorJustCreated = false;
                    field.value = BuilderConstants.UssSelectorClassNameSymbol;
                }

                ShowTooltip();
            });

            m_NewSelectorTextField.RegisterCallback <ChangeEvent <string> >((evt) =>
            {
                var field = evt.target as TextField;

                if (!string.IsNullOrEmpty(evt.newValue) && evt.newValue != BuilderConstants.UssSelectorClassNameSymbol)
                {
                    m_NewSelectorAddButton.SetEnabled(true);
                    m_PseudoStatesMenu.SetEnabled(true);
                }
                else
                {
                    m_NewSelectorAddButton.SetEnabled(false);
                    m_PseudoStatesMenu.SetEnabled(false);
                }

                if (!m_FieldFocusedFromStandby)
                {
                    return;
                }

                m_FieldFocusedFromStandby = false;

                // We don't want the '.' we just inserted in the FocusEvent to be highlighted,
                // which is the default behavior.
                field.SelectRange(1, 1);
            });

            m_NewSelectorTextInputField.RegisterCallback <BlurEvent>((evt) =>
            {
                var input = evt.target as VisualElement;
                var field = input.parent as TextField;
                if (m_NewSelectorJustCreated)
                {
                    field.schedule.Execute(PostEnterRefocus);
                    evt.PreventDefault();
                    evt.StopImmediatePropagation();
                    return;
                }

                if (string.IsNullOrEmpty(field.text) || field.text == BuilderConstants.UssSelectorClassNameSymbol)
                {
                    field.SetValueWithoutNotify(BuilderConstants.ExplorerInExplorerNewClassSelectorInfoMessage);
                    m_NewSelectorAddButton.SetEnabled(false);
                    m_PseudoStatesMenu.SetEnabled(false);
                }

                HideTooltip();
            });

            // Setup new selector button.
            m_NewSelectorAddButton = parent.Q <ToolbarButton>("add-new-selector-button");
            m_NewSelectorAddButton.clickable.clicked += OnAddPress;
            m_NewSelectorAddButton.SetEnabled(false);

            // Setup pseudo states menu.
            m_PseudoStatesMenu = parent.Q <ToolbarMenu>("add-pseudo-state-menu");
            m_PseudoStatesMenu.SetEnabled(false);
            SetUpPseudoStatesMenu();
        }
コード例 #17
0
        public BuilderViewport(BuilderPaneWindow paneWindow, BuilderSelection selection, BuilderElementContextMenu contextMenuManipulator)
        {
            m_PaneWindow             = paneWindow;
            m_Selection              = selection;
            m_ContextMenuManipulator = contextMenuManipulator;

            AddToClassList("unity-builder-viewport");

            var template = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(BuilderConstants.UIBuilderPackagePath + "/BuilderViewport.uxml");

            template.CloneTree(this);

            m_Toolbar             = this.Q("toolbar");
            m_ViewportWrapper     = this.Q("viewport-wrapper");
            m_Viewport            = this.Q("viewport");
            m_Surface             = this.Q("viewport-surface");
            m_Surface.pickingMode = PickingMode.Ignore;
            m_Canvas          = this.Q <BuilderCanvas>("canvas");
            m_Canvas.document = paneWindow.document;
            m_SharedStylesAndDocumentElement = this.Q("shared-styles-and-document");
            m_SharedStylesAndDocumentElement.pseudoStates |= PseudoStates.Root; // To apply variables of the active theme that are defined in the :root selector
            m_StyleSelectorElementContainer = this.Q(BuilderConstants.StyleSelectorElementContainerName);
            m_DocumentElement        = this.Q("document");
            m_Canvas.documentElement = m_DocumentElement;
            m_EditorLayer            = this.Q("__unity-editor-layer");
            m_EditorLayer.AddToClassList(BuilderConstants.HiddenStyleClassName);
            m_TextEditor                = this.Q <TextField>("__unity-text-editor");
            m_Canvas.editorLayer        = m_EditorLayer;
            m_PickOverlay               = this.Q("pick-overlay");
            m_HighlightOverlay          = this.Q("highlight-overlay");
            m_BuilderParentTracker      = this.Q <BuilderParentTracker>("parent-tracker");
            m_BuilderSelectionIndicator = this.Q <BuilderSelectionIndicator>("selection-indicator");
            m_BuilderResizer            = this.Q <BuilderResizer>("resizer");
            m_BuilderMover              = this.Q <BuilderMover>("mover");
            m_BuilderAnchorer           = this.Q <BuilderAnchorer>("anchorer");
            m_BuilderZoomer             = new BuilderZoomer(this);
            m_BuilderPanner             = new BuilderPanner(this);

            m_BuilderMover.parentTracker = m_BuilderParentTracker;

            m_PickOverlay.RegisterCallback <MouseDownEvent>(OnPick);
            m_PickOverlay.RegisterCallback <MouseMoveEvent>(OnHover);
            m_PickOverlay.RegisterCallback <MouseLeaveEvent>(OnMouseLeave);
            m_Viewport.RegisterCallback <MouseDownEvent>(OnMissPick);
            m_Viewport.RegisterCallback <GeometryChangedEvent>(OnGeometryChanged);

            m_Canvas.header.AddManipulator(new Clickable(OnCanvasHeaderClick));
            m_ContextMenuManipulator?.RegisterCallbacksOnTarget(m_Viewport);

            // Make sure this gets focus when the pane gets focused.
            primaryFocusable = this;
            focusable        = true;

            // Restore the zoom scale
            zoomScale     = paneWindow.document.viewportZoomScale;
            contentOffset = paneWindow.document.viewportContentOffset;

            // Repaint bug workaround.
            m_CheckerboardBackground = this.Q <CheckerboardBackground>();
            RegisterCallback <BlurEvent>(e => { m_CheckerboardBackground.MarkDirtyRepaint(); });
            RegisterCallback <FocusEvent>(e => { m_CheckerboardBackground.MarkDirtyRepaint(); });
        }
コード例 #18
0
        public override void CreateUI()
        {
            var root = rootVisualElement;

            titleContent       = GetLocalizedTitleContent();
            saveChangesMessage = BuilderConstants.SaveDialogSaveChangesPromptMessage;

            // Load assets.
            var builderTemplate = BuilderPackageUtilities.LoadAssetAtPath <VisualTreeAsset>(BuilderConstants.UIBuilderPackagePath + "/Builder.uxml");

            // Load templates.
            builderTemplate.CloneTree(root);

            // Create overlay painter.
            m_HighlightOverlayPainter = new HighlightOverlayPainter();

            // Fetch the tooltip previews.
            var styleSheetsPaneTooltipPreview = root.Q <BuilderTooltipPreview>("stylesheets-pane-tooltip-preview");
            var libraryTooltipPreview         = root.Q <BuilderTooltipPreview>("library-tooltip-preview");

            // Create selection.
            m_Selection = new BuilderSelection(root, this);

            // Create Element Context Menu Manipulator
            var contextMenuManipulator = new BuilderElementContextMenu(this, selection);

            // Create viewport first.
            m_Viewport = new BuilderViewport(this, selection, contextMenuManipulator);
            selection.documentRootElement = m_Viewport.documentRootElement;
            var overlayHelper = viewport.Q <OverlayPainterHelperElement>();

            overlayHelper.painter = m_HighlightOverlayPainter;

            // Create the rest of the panes.
            var classDragger       = new BuilderClassDragger(this, root, selection, m_Viewport, m_Viewport.parentTracker);
            var styleSheetsDragger = new BuilderStyleSheetsDragger(this, root, selection);
            var styleSheetsPane    = new BuilderStyleSheets(this, m_Viewport, selection, classDragger, styleSheetsDragger, m_HighlightOverlayPainter, styleSheetsPaneTooltipPreview);
            var hierarchyDragger   = new BuilderHierarchyDragger(this, root, selection, m_Viewport, m_Viewport.parentTracker)
            {
                builderStylesheetRoot = styleSheetsPane.container
            };

            m_Hierarchy = new BuilderHierarchy(this, m_Viewport, selection, classDragger, hierarchyDragger, contextMenuManipulator, m_HighlightOverlayPainter);

            var libraryDragger = new BuilderLibraryDragger(this, root, selection, m_Viewport, m_Viewport.parentTracker, hierarchy.container, libraryTooltipPreview)
            {
                builderStylesheetRoot = styleSheetsPane.container
            };

            m_Viewport.viewportDragger.builderHierarchyRoot = hierarchy.container;
            m_Library     = new BuilderLibrary(this, m_Viewport, selection, libraryDragger, libraryTooltipPreview);
            m_Inspector   = new BuilderInspector(this, selection, m_HighlightOverlayPainter);
            m_Toolbar     = new BuilderToolbar(this, selection, m_Viewport, hierarchy, m_Library, m_Inspector, libraryTooltipPreview);
            m_UxmlPreview = new BuilderUxmlPreview(this);
            m_UssPreview  = new BuilderUssPreview(this, selection);
            root.Q("viewport").Add(m_Viewport);
            m_Viewport.toolbar.Add(m_Toolbar);
            root.Q("library").Add(m_Library);
            root.Q("style-sheets").Add(styleSheetsPane);
            root.Q("hierarchy").Add(hierarchy);
            root.Q("uxml-preview").Add(m_UxmlPreview);
            root.Q("uss-preview").Add(m_UssPreview);
            root.Q("inspector").Add(m_Inspector);

            // Init selection.
            selection.AssignNotifiers(new IBuilderSelectionNotifier[]
            {
                document,
                m_Viewport,
                styleSheetsPane,
                hierarchy,
                m_Inspector,
                m_Library,
                m_UxmlPreview,
                m_UssPreview,
                m_Toolbar,
                m_Viewport.parentTracker,
                m_Viewport.resizer,
                m_Viewport.mover,
                m_Viewport.anchorer,
                m_Viewport.selectionIndicator
            });

            // Command Handler
            commandHandler.RegisterPane(styleSheetsPane);
            commandHandler.RegisterPane(hierarchy);
            commandHandler.RegisterPane(m_Viewport);
            commandHandler.RegisterToolbar(m_Toolbar);

            m_MiddleSplitView = rootVisualElement.Q <TwoPaneSplitView>("middle-column");
            m_MiddleSplitView.RegisterCallback <GeometryChangedEvent>(OnFirstDisplay);

            OnEnableAfterAllSerialization();
        }
コード例 #19
0
        public BuilderStyleSheets(
            BuilderPaneWindow paneWindow,
            BuilderViewport viewport,
            BuilderSelection selection,
            BuilderClassDragger classDragger,
            BuilderStyleSheetsDragger styleSheetsDragger,
            HighlightOverlayPainter highlightOverlayPainter,
            BuilderTooltipPreview tooltipPreview)
            : base(
                paneWindow,
                viewport,
                selection,
                classDragger,
                styleSheetsDragger,
                new BuilderStyleSheetsContextMenu(paneWindow, selection),
                viewport.styleSelectorElementContainer,
                false,
                highlightOverlayPainter,
                kToolbarPath)
        {
            m_TooltipPreview = tooltipPreview;
            if (m_TooltipPreview != null)
            {
                var helpTooltipTemplate  = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(kHelpTooltipPath);
                var helpTooltipContainer = helpTooltipTemplate.CloneTree();
                m_TooltipPreview.Add(helpTooltipContainer); // We are the only ones using it so just add the contents and be done.
            }

            viewDataKey = "builder-style-sheets";
            AddToClassList(BuilderConstants.ExplorerStyleSheetsPaneClassName);

            var parent = this.Q("new-selector-item");

            // Init text field.
            m_NewSelectorField     = parent.Q <BuilderNewSelectorField>("new-selector-field");
            m_NewSelectorTextField = m_NewSelectorField.textField;
            m_NewSelectorTextField.SetValueWithoutNotify(BuilderConstants.ExplorerInExplorerNewClassSelectorInfoMessage);
            m_NewSelectorTextInputField = m_NewSelectorTextField.Q("unity-text-input");
            m_NewSelectorTextInputField.RegisterCallback <KeyDownEvent>(OnEnter, TrickleDown.TrickleDown);
            UpdateNewSelectorFieldEnabledStateFromDocument();

            m_NewSelectorTextInputField.RegisterCallback <FocusEvent>((evt) =>
            {
                var input = evt.target as VisualElement;
                var field = input.parent as TextField;
                m_FieldFocusedFromStandby = true;
                if (field.text == BuilderConstants.ExplorerInExplorerNewClassSelectorInfoMessage || m_ShouldRefocusSelectorFieldOnBlur)
                {
                    m_ShouldRefocusSelectorFieldOnBlur = false;
                    field.value = BuilderConstants.UssSelectorClassNameSymbol;
                }

                ShowTooltip();
            });

            m_NewSelectorTextField.RegisterCallback <ChangeEvent <string> >((evt) =>
            {
                var field = evt.target as TextField;

                if (!m_FieldFocusedFromStandby)
                {
                    return;
                }

                m_FieldFocusedFromStandby = false;

                // We don't want the '.' we just inserted in the FocusEvent to be highlighted,
                // which is the default behavior.
                field.SelectRange(1, 1);
            });

            m_NewSelectorTextInputField.RegisterCallback <BlurEvent>((evt) =>
            {
                var input = evt.target as VisualElement;
                var field = input.parent as TextField;
                if (m_ShouldRefocusSelectorFieldOnBlur)
                {
                    field.schedule.Execute(PostEnterRefocus);
                    evt.PreventDefault();
                    evt.StopImmediatePropagation();
                    return;
                }

                if (string.IsNullOrEmpty(field.text) || field.text == BuilderConstants.UssSelectorClassNameSymbol)
                {
                    field.SetValueWithoutNotify(BuilderConstants.ExplorerInExplorerNewClassSelectorInfoMessage);
                    m_PseudoStatesMenu.SetEnabled(false);
                }

                HideTooltip();
            });

            // Setup New USS Menu.
            m_AddUSSMenu = parent.Q <ToolbarMenu>("add-uss-menu");
            SetUpAddUSSMenu();

            // Setup pseudo states menu.
            m_PseudoStatesMenu = m_NewSelectorField.pseudoStatesMenu;

            // Update sub title.
            UpdateSubtitleFromActiveUSS();
        }
コード例 #20
0
        public override void CreateUI()
        {
            var root = rootVisualElement;

            // Load assets.
            var builderTemplate    = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(BuilderConstants.UIBuilderPackagePath + "/Builder.uxml");
            var saveDialogTemplate = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(BuilderConstants.UIBuilderPackagePath + "/BuilderSaveDialog.uxml");

            // Load templates.
            builderTemplate.CloneTree(root);
            saveDialogTemplate.CloneTree(root);

            // Create overlay painter.
            m_HighlightOverlayPainter = new HighlightOverlayPainter();

            // Fetch the save dialog.
            var dialog = root.Q <ModalPopup>("save-dialog");

            // Fetch the tooltip previews.
            var styleSheetsPaneTooltipPreview = root.Q <BuilderTooltipPreview>("stylesheets-pane-tooltip-preview");
            var libraryTooltipPreview         = root.Q <BuilderTooltipPreview>("library-tooltip-preview");

            // Create selection.
            m_Selection = new BuilderSelection(root, this);

            // Create Element Context Menu Manipulator
            var contextMenuManipulator = new BuilderElementContextMenu(this, selection);

            // Create viewport first.
            m_Viewport = new BuilderViewport(this, selection, contextMenuManipulator);
            selection.documentElement = m_Viewport.documentElement;
            var overlayHelper = viewport.Q <OverlayPainterHelperElement>();

            overlayHelper.painter = m_HighlightOverlayPainter;

            // Create the rest of the panes.
            var classDragger     = new BuilderClassDragger(this, root, selection, m_Viewport, m_Viewport.parentTracker);
            var hierarchyDragger = new BuilderHierarchyDragger(this, root, selection, m_Viewport, m_Viewport.parentTracker);
            var styleSheetsPane  = new BuilderStyleSheets(m_Viewport, selection, classDragger, hierarchyDragger, contextMenuManipulator, m_HighlightOverlayPainter, styleSheetsPaneTooltipPreview);
            var hierarchy        = new BuilderHierarchy(m_Viewport, selection, classDragger, hierarchyDragger, contextMenuManipulator, m_HighlightOverlayPainter);
            var libraryDragger   = new BuilderLibraryDragger(this, root, selection, m_Viewport, m_Viewport.parentTracker, hierarchy.container, libraryTooltipPreview);

            m_Library     = new BuilderLibrary(this, m_Viewport, selection, libraryDragger, libraryTooltipPreview);
            m_Inspector   = new BuilderInspector(this, selection);
            m_Toolbar     = new BuilderToolbar(this, selection, dialog, m_Viewport, hierarchy, m_Library, m_Inspector, libraryTooltipPreview);
            m_UxmlPreview = new BuilderUxmlPreview(this);
            m_UssPreview  = new BuilderUssPreview(this);
            root.Q("viewport").Add(m_Viewport);
            m_Viewport.toolbar.Add(m_Toolbar);
            root.Q("library").Add(m_Library);
            root.Q("style-sheets").Add(styleSheetsPane);
            root.Q("hierarchy").Add(hierarchy);
            root.Q("uxml-preview").Add(m_UxmlPreview);
            root.Q("uss-preview").Add(m_UssPreview);
            root.Q("inspector").Add(m_Inspector);

            // Init selection.
            selection.AssignNotifiers(new IBuilderSelectionNotifier[]
            {
                document,
                m_Viewport,
                styleSheetsPane,
                hierarchy,
                m_Inspector,
                m_UxmlPreview,
                m_UssPreview,
                m_Viewport.parentTracker,
                m_Viewport.resizer,
                m_Viewport.mover,
                m_Viewport.anchorer
            });

            // Command Handler
            commandHandler.RegisterPane(styleSheetsPane);
            commandHandler.RegisterPane(hierarchy);
            commandHandler.RegisterPane(m_Viewport);
            commandHandler.RegisterToolbar(m_Toolbar);

            OnEnableAfterAllSerialization();
        }
コード例 #21
0
 public static void SetActiveUSS(BuilderSelection selection, BuilderPaneWindow paneWindow, StyleSheet styleSheet)
 {
     paneWindow.document.UpdateActiveStyleSheet(selection, styleSheet, null);
 }
コード例 #22
0
        public TextField CreateRenamingTextField(VisualElement documentElement, Label nameLabel, BuilderSelection selection)
        {
            var renameTextfield = new TextField()
            {
                name      = BuilderConstants.ExplorerItemRenameTextfieldName,
                isDelayed = true
            };

            renameTextfield.AddToClassList(BuilderConstants.ExplorerItemRenameTextfieldClassName);

            renameTextfield.SetValueWithoutNotify(
                string.IsNullOrEmpty(documentElement.name)
                    ? documentElement.typeName
                    : documentElement.name);
            renameTextfield.AddToClassList(BuilderConstants.HiddenStyleClassName);

            renameTextfield.RegisterCallback <KeyUpEvent>((e) =>
            {
                e.StopImmediatePropagation();
            });

            renameTextfield.RegisterCallback <FocusOutEvent>(e =>
            {
                OnEditTextFinished(documentElement, renameTextfield, nameLabel, selection);
            });

            return(renameTextfield);
        }
コード例 #23
0
        public BuilderToolbar(
            BuilderPaneWindow paneWindow,
            BuilderSelection selection,
            ModalPopup saveDialog,
            BuilderViewport viewport,
            BuilderExplorer explorer,
            BuilderLibrary library,
            BuilderInspector inspector,
            BuilderTooltipPreview tooltipPreview)
        {
            m_PaneWindow     = paneWindow;
            m_Selection      = selection;
            m_SaveDialog     = saveDialog;
            m_Viewport       = viewport;
            m_Explorer       = explorer;
            m_Library        = library;
            m_Inspector      = inspector;
            m_TooltipPreview = tooltipPreview;

            // Query the UI
            m_SaveDialogUxmlPathField      = m_SaveDialog.Q <TextField>("save-dialog-uxml-path");
            m_SaveDialogUxmlLocationButton = m_SaveDialog.Q <Button>("save-dialog-uxml-location-button");
            m_SaveDialogUssPathField       = m_SaveDialog.Q <TextField>("save-dialog-uss-path");
            m_SaveDialogUssLocationButton  = m_SaveDialog.Q <Button>("save-dialog-uss-location-button");
            m_SaveDialogSaveButton         = m_SaveDialog.Q <Button>("save-dialog-save-button");
            m_SaveDialogCancelButton       = m_SaveDialog.Q <Button>("save-dialog-cancel-button");
            m_SaveDialogTitleLabel         = m_SaveDialog.Q <Label>("title");

            m_SaveDialogUxmlPathField.RegisterValueChangedCallback(OnUxmlPathFieldChange);
            m_SaveDialogUssPathField.RegisterValueChangedCallback(OnUssPathFieldChange);

            m_SaveDialogSaveButton.clickable.clicked         += SaveDocument;
            m_SaveDialogCancelButton.clickable.clicked       += m_SaveDialog.Hide;
            m_SaveDialogUxmlLocationButton.clickable.clicked += OnUxmlLocationButtonClick;
            m_SaveDialogUssLocationButton.clickable.clicked  += OnUssLocationButtonClick;

            var saveDialogValidationBoxContainer = m_SaveDialog.Q("save-dialog-validation-box");

            m_SaveDialogValidationBox = new IMGUIContainer(DrawSaveDialogValidationMessage);
            m_SaveDialogValidationBox.style.overflow = Overflow.Hidden;
            saveDialogValidationBoxContainer.Add(m_SaveDialogValidationBox);

            var template = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(
                BuilderConstants.UIBuilderPackagePath + "/BuilderToolbar.uxml");

            template.CloneTree(this);

            // File Menu
            m_FileMenu = this.Q <ToolbarMenu>("file-menu");
            SetUpFileMenu();

            // Preview Button
            var previewButton = this.Q <ToolbarToggle>("preview-button");

            previewButton.RegisterValueChangedCallback(TogglePreviewMode);

            m_CanvasThemeMenu = this.Q <ToolbarMenu>("canvas-theme-menu");
            SetUpCanvasThemeMenu();
            ChangeCanvasTheme(document.currentCanvasTheme);
            UpdateCanvasThemeMenuStatus();

            // Track unsaved changes state change.
            document.unsavedChangesStateChanged = SetViewportSubTitle;
            SetViewportSubTitle();

            // Get Builder package version.
            var packageInfo = PackageInfo.FindForAssetPath("Packages/" + BuilderConstants.BuilderPackageName);

            if (packageInfo == null)
            {
                m_BuilderPackageVersion = null;
            }
            else
            {
                m_BuilderPackageVersion = packageInfo.version;
            }

            RegisterCallback <AttachToPanelEvent>(RegisterCallbacks);
        }
コード例 #24
0
        public BuilderStyleSheets(
            BuilderPaneWindow paneWindow,
            BuilderViewport viewport,
            BuilderSelection selection,
            BuilderClassDragger classDragger,
            BuilderStyleSheetsDragger styleSheetsDragger,
            HighlightOverlayPainter highlightOverlayPainter,
            BuilderTooltipPreview tooltipPreview)
            : base(
                paneWindow,
                viewport,
                selection,
                classDragger,
                styleSheetsDragger,
                new BuilderStyleSheetsContextMenu(paneWindow, selection),
                viewport.styleSelectorElementContainer,
                false,
                highlightOverlayPainter,
                kToolbarPath)
        {
            m_TooltipPreview = tooltipPreview;
            if (m_TooltipPreview != null)
            {
                var helpTooltipTemplate  = BuilderPackageUtilities.LoadAssetAtPath <VisualTreeAsset>(kHelpTooltipPath);
                var helpTooltipContainer = helpTooltipTemplate.CloneTree();
                m_TooltipPreview.Add(helpTooltipContainer); // We are the only ones using it so just add the contents and be done.
            }

            viewDataKey = "builder-style-sheets";
            AddToClassList(BuilderConstants.ExplorerStyleSheetsPaneClassName);

            var parent = this.Q("new-selector-item");

            // Init text field.
            m_NewSelectorField     = parent.Q <BuilderNewSelectorField>("new-selector-field");
            m_NewSelectorTextField = m_NewSelectorField.textField;
            m_NewSelectorTextField.SetValueWithoutNotify(BuilderConstants.ExplorerInExplorerNewClassSelectorInfoMessage);
            m_NewSelectorTextInputField = m_NewSelectorTextField.Q("unity-text-input");
            m_NewSelectorTextInputField.RegisterCallback <KeyDownEvent>(OnEnter, TrickleDown.TrickleDown);
            UpdateNewSelectorFieldEnabledStateFromDocument();

            m_NewSelectorTextInputField.RegisterCallback <FocusEvent>((evt) =>
            {
                var input        = evt.target as VisualElement;
                var field        = GetTextFieldParent(input);
                m_FieldFocusStep = FieldFocusStep.FocusedFromStandby;
                if (field.text == BuilderConstants.ExplorerInExplorerNewClassSelectorInfoMessage || m_ShouldRefocusSelectorFieldOnBlur)
                {
                    m_ShouldRefocusSelectorFieldOnBlur = false;
                    field.value = BuilderConstants.UssSelectorClassNameSymbol;
                }

                ShowTooltip();
            }, TrickleDown.TrickleDown);

            m_NewSelectorTextField.RegisterCallback <ChangeEvent <string> >((evt) =>
            {
                if (m_FieldFocusStep != FieldFocusStep.FocusedFromStandby)
                {
                    return;
                }

                m_FieldFocusStep = m_NewSelectorTextField.value == BuilderConstants.UssSelectorClassNameSymbol ? FieldFocusStep.NeedsSelectionOverride : FieldFocusStep.Idle;

                // We don't want the '.' we just inserted in the FocusEvent to be highlighted,
                // which is the default behavior. Same goes for when we add pseudo states with options menu.
                m_NewSelectorTextField.SelectRange(m_NewSelectorTextField.value.Length, m_NewSelectorTextField.value.Length);
            });

            // Since MouseDown captures the mouse, we need to RegisterCallback directly on the target in order to intercept the event.
            // This could be replaced by setting selectAllOnMouseUp to false.
            m_NewSelectorTextInputField.Q <TextElement>().RegisterCallback <MouseUpEvent>((evt) =>
            {
                // We want to prevent the default action on mouse up in KeyboardTextEditor, but only when
                // the field selection behaviour was changed by us.
                if (m_FieldFocusStep != FieldFocusStep.NeedsSelectionOverride)
                {
                    return;
                }

                m_FieldFocusStep = FieldFocusStep.Idle;

                // Reselect on the next execution, after the KeyboardTextEditor selects all.
                m_NewSelectorTextInputField.schedule.Execute(() =>
                {
                    m_NewSelectorTextField.SelectRange(m_NewSelectorTextField.value.Length, m_NewSelectorTextField.value.Length);
                });
            }, TrickleDown.TrickleDown);

            m_NewSelectorTextInputField.RegisterCallback <BlurEvent>((evt) =>
            {
                var input = evt.target as VisualElement;
                var field = GetTextFieldParent(input);
                if (m_ShouldRefocusSelectorFieldOnBlur)
                {
                    field.schedule.Execute(PostEnterRefocus);
                    evt.PreventDefault();
                    evt.StopImmediatePropagation();
                    return;
                }

                if (string.IsNullOrEmpty(field.text) || field.text == BuilderConstants.UssSelectorClassNameSymbol)
                {
                    field.SetValueWithoutNotify(BuilderConstants.ExplorerInExplorerNewClassSelectorInfoMessage);
                    m_PseudoStatesMenu.SetEnabled(false);
                }

                HideTooltip();
            }, TrickleDown.TrickleDown);

            // Setup New USS Menu.
            m_AddUSSMenu = parent.Q <ToolbarMenu>("add-uss-menu");
            SetUpAddUSSMenu();

            // Setup pseudo states menu.
            m_PseudoStatesMenu = m_NewSelectorField.pseudoStatesMenu;

            // Update sub title.
            UpdateSubtitleFromActiveUSS();

            // Init drag stylesheet root
            classDragger.builderStylesheetRoot       = container;
            styleSheetsDragger.builderStylesheetRoot = container;

            RegisterCallback <GeometryChangedEvent>(e => AdjustPosition());
        }
コード例 #25
0
        public ElementHierarchyView(
            BuilderPaneWindow paneWindow,
            VisualElement documentRootElement,
            BuilderSelection selection,
            BuilderClassDragger classDragger,
            BuilderExplorerDragger explorerDragger,
            BuilderElementContextMenu contextMenuManipulator,
            Action <List <VisualElement> > selectElementCallback,
            HighlightOverlayPainter highlightOverlayPainter)
        {
            m_PaneWindow             = paneWindow;
            m_DocumentRootElement    = documentRootElement;
            m_Selection              = selection;
            m_ClassDragger           = classDragger;
            m_ExplorerDragger        = explorerDragger;
            m_ContextMenuManipulator = contextMenuManipulator;

            this.focusable = true;

            m_SelectElementCallback = selectElementCallback;
            hierarchyHasChanged     = true;
            hasUnsavedChanges       = false;

            m_SearchResultsHightlights = new List <VisualElement>();

            this.RegisterCallback <FocusEvent>(e => m_TreeView?.Focus());

            // HACK: ListView/TreeView need to clear their selections when clicking on nothing.
            this.RegisterCallback <MouseDownEvent>(e =>
            {
                var leafTarget = e.leafTarget as VisualElement;
                if (leafTarget.parent is ScrollView)
                {
                    ClearSelection();
                }
            });

            m_TreeViewHoverOverlay = highlightOverlayPainter;

            m_Container                            = new VisualElement();
            m_Container.name                       = "explorer-container";
            m_Container.style.flexGrow             = 1;
            m_ClassDragger.builderHierarchyRoot    = m_Container;
            m_ExplorerDragger.builderHierarchyRoot = m_Container;
            Add(m_Container);

            m_ClassPillTemplate = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(
                BuilderConstants.UIBuilderPackagePath + "/BuilderClassPill.uxml");

            // Create TreeView.
            m_TreeRootItems = new List <ITreeViewItem>();
            m_TreeView      = new TreeView(m_TreeRootItems, 20, MakeItem, FillItem);
#if UNITY_2020_1_OR_NEWER
            m_TreeView.selectionType = SelectionType.Multiple;
#else
            m_TreeView.selectionType = SelectionType.Single; // ListView/TreeView do not support selecting mutliple items via code.
#endif
            m_TreeView.viewDataKey    = "unity-builder-explorer-tree";
            m_TreeView.style.flexGrow = 1;
#if UNITY_2020_1_OR_NEWER
            m_TreeView.onSelectionChange += OnSelectionChange;
#else
            m_TreeView.onSelectionChanged += OnSelectionChange;
#endif

#if UNITY_2019_3_OR_NEWER
            m_TreeView.RegisterCallback <MouseDownEvent>(OnLeakedMouseClick);
#endif

            m_Container.Add(m_TreeView);

            m_ContextMenuManipulator.RegisterCallbacksOnTarget(m_Container);
        }
コード例 #26
0
        public ElementHierarchyView(
            VisualElement documentRootElement,
            BuilderSelection selection,
            BuilderClassDragger classDragger,
            BuilderHierarchyDragger hierarchyDragger,
            BuilderElementContextMenu contextMenuManipulator,
            Action <VisualElement> selectElementCallback,
            HighlightOverlayPainter highlightOverlayPainter)
        {
            m_DocumentRootElement    = documentRootElement;
            m_Selection              = selection;
            m_ClassDragger           = classDragger;
            m_HierarchyDragger       = hierarchyDragger;
            m_ContextMenuManipulator = contextMenuManipulator;

            this.focusable = true;

            m_SelectElementCallback = selectElementCallback;
            hierarchyHasChanged     = true;

            m_SearchResultsHightlights = new List <VisualElement>();

            this.RegisterCallback <FocusEvent>(e => m_TreeView?.Focus());

            // HACK: ListView/TreeView need to clear their selections when clicking on nothing.
            this.RegisterCallback <MouseDownEvent>(e =>
            {
                var leafTarget = e.leafTarget as VisualElement;
                if (leafTarget.parent is ScrollView)
                {
                    ClearSelection();
                }
            });

            m_TreeViewHoverOverlay = highlightOverlayPainter;

            m_Container                             = new VisualElement();
            m_Container.name                        = "explorer-container";
            m_Container.style.flexGrow              = 1;
            m_ClassDragger.builderHierarchyRoot     = m_Container;
            m_HierarchyDragger.builderHierarchyRoot = m_Container;
            Add(m_Container);

            m_SearchBar = new ElementHierarchySearchBar(this);
            Add(m_SearchBar);

            // TODO: Hiding for now since search does not work, especially with style class pills.
            m_SearchBar.style.display = DisplayStyle.None;

            m_ClassPillTemplate = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(
                BuilderConstants.UIBuilderPackagePath + "/BuilderClassPill.uxml");

            // Create TreeView.
            m_TreeRootItems           = new List <ITreeViewItem>();
            m_TreeView                = new TreeView(m_TreeRootItems, 20, MakeItem, FillItem);
            m_TreeView.viewDataKey    = "unity-builder-explorer-tree";
            m_TreeView.style.flexGrow = 1;
#if UNITY_2020_1_OR_NEWER
            m_TreeView.onSelectionChange += OnSelectionChange;
#else
            m_TreeView.onSelectionChanged += OnSelectionChange;
#endif

#if UNITY_2019_3_OR_NEWER
            m_TreeView.RegisterCallback <MouseDownEvent>(OnLeakedMouseClick);
#endif

            m_Container.Add(m_TreeView);

            m_ContextMenuManipulator.RegisterCallbacksOnTarget(m_Container);
        }
コード例 #27
0
 public void SetSelection(BuilderSelection selection)
 {
     m_Selection = selection;
 }
コード例 #28
0
        public BuilderToolbar(
            BuilderPaneWindow paneWindow,
            BuilderSelection selection,
            BuilderViewport viewport,
            BuilderExplorer explorer,
            BuilderLibrary library,
            BuilderInspector inspector,
            BuilderTooltipPreview tooltipPreview)
        {
            m_PaneWindow     = paneWindow;
            m_Selection      = selection;
            m_Viewport       = viewport;
            m_Explorer       = explorer;
            m_Library        = library;
            m_Inspector      = inspector;
            m_TooltipPreview = tooltipPreview;

            var template = BuilderPackageUtilities.LoadAssetAtPath <VisualTreeAsset>(
                BuilderConstants.UIBuilderPackagePath + "/BuilderToolbar.uxml");

            template.CloneTree(this);

#if !UNITY_2019_4 && !UNITY_2020_1
            m_ThemeManager                    = new ThemeStyleSheetManager(this);
            m_ThemeManager.selection          = m_Selection;
            m_ThemeManager.themeFilesChanged += UpdateCanvasThemeMenuStatus;
#else
            m_ThemeManager = null;
#endif

            // File Menu
            m_FileMenu = this.Q <ToolbarMenu>("file-menu");
            SetUpFileMenu();

            // Zoom Menu
            m_ZoomMenu = this.Q <ToolbarMenu>("zoom-menu");
            SetUpZoomMenu();

            // Fit canvas
            m_FitCanvasButton = this.Q <ToolbarButton>(FitCanvasButtonName);
            m_FitCanvasButton.clickable.clicked += () => m_Viewport.FitCanvas();

            // Preview Button
            var previewButton = this.Q <ToolbarToggle>(PreviewToggleName);
            previewButton.RegisterValueChangedCallback(TogglePreviewMode);

            m_CanvasThemeMenu = this.Q <ToolbarMenu>("canvas-theme-menu");
            SetUpCanvasThemeMenu();
            ChangeCanvasTheme(document.currentCanvasTheme, document.currentCanvasThemeStyleSheet);
            UpdateCanvasThemeMenuStatus();
            SetViewportSubTitle();

            // Track unsaved changes state change.
            SetCanvasTitle();

            m_SettingsMenu = this.Q <ToolbarMenu>("settings-menu");
            SetupSettingsMenu();

            // Breadcrumbs & BreadCrumbs Toolbar
            m_BreadcrumbsToolbar = this.Q <Toolbar>(BreadcrumbsToolbarName);
            m_Breadcrumbs        = this.Q <ToolbarBreadcrumbs>(BreadcrumbsName);
            SetToolbarBreadCrumbs();

            // Get Builder package version.
            var packageInfo = PackageInfo.FindForAssetPath("Packages/" + BuilderConstants.BuilderPackageName);
            if (packageInfo == null)
            {
                m_BuilderPackageVersion = null;
            }
            else
            {
                m_BuilderPackageVersion = packageInfo.version;
            }

            RegisterCallback <AttachToPanelEvent>(RegisterCallbacks);
        }
コード例 #29
0
 public void Deactivate()
 {
     m_Selection       = null;
     m_VisualTreeAsset = null;
     m_Target          = null;
 }
コード例 #30
0
 public BuilderStyleSheetsContextMenu(BuilderPaneWindow paneWindow, BuilderSelection selection)
     : base(paneWindow, selection)
 {
 }