public static void RemoveUSSFromAsset(BuilderPaneWindow paneWindow, BuilderSelection selection, VisualElement clickedElement)
        {
            // We need to save all files before we remove the USS references.
            // If we don't do this, changes in the removed USS will be lost.
            var shouldContinue = s_CheckForUnsavedChanges(paneWindow);

            if (!shouldContinue)
            {
                return;
            }

            var selectedElements = selection.selection;

            if (!selectedElements.Contains(clickedElement))
            {
                // Removed just clicked element
                var clickedStyleSheetIndex = (int)clickedElement.GetProperty(BuilderConstants.ElementLinkedStyleSheetIndexVEPropertyName);
                BuilderAssetUtilities.RemoveStyleSheetFromAsset(paneWindow.document, clickedStyleSheetIndex);
            }
            else
            {
                // Removed selected elements
                var styleSheetIndexes = selectedElements.Where(x => BuilderSharedStyles.IsStyleSheetElement(x) &&
                                                               string.IsNullOrEmpty(x.GetProperty(BuilderConstants.ExplorerItemLinkedUXMLFileName) as string))
                                        .Select(x => (int)x.GetProperty(BuilderConstants.ElementLinkedStyleSheetIndexVEPropertyName))
                                        .OrderByDescending(x => x)
                                        .ToArray();

                BuilderAssetUtilities.RemoveStyleSheetsFromAsset(paneWindow.document, styleSheetIndexes);
            }

            paneWindow.OnEnableAfterAllSerialization();
        }
        public BuilderDragger(
            BuilderPaneWindow paneWindow,
            VisualElement root, BuilderSelection selection,
            BuilderViewport viewport = null, BuilderParentTracker parentTracker = null)
        {
            m_PaneWindow         = paneWindow;
            m_Root               = root;
            this.viewport        = viewport;
            m_Canvas             = viewport?.documentRootElement;
            m_Selection          = selection;
            m_ParentTracker      = parentTracker;
            m_PlacementIndicator = viewport?.placementIndicator;
            if (m_PlacementIndicator != null)
            {
                m_PlacementIndicator.documentRootElement = m_Canvas;
            }

            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);
        }
Esempio n. 3
0
 public BuilderViewportDragger(
     BuilderPaneWindow paneWindow,
     VisualElement root, BuilderSelection selection,
     BuilderViewport viewport = null, BuilderParentTracker parentTracker = null)
     : base(paneWindow, root, selection, viewport, parentTracker)
 {
 }
Esempio n. 4
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_AddClassValidationMessageContainer = m_Inspector.Q("add-class-validation-message-container");
            m_AddClassValidationMessageContainer.Add(new IMGUIContainer(DrawAddClassValidationMessage));
            m_AddClassValidationMessageContainer.style.display = DisplayStyle.None;

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

            m_AddClassButton.clickable.clicked    += AddStyleClass;
            m_CreateClassButton.clickable.clicked += ExtractLocalStylesToNewClass;

            m_AddClassValidationRegex = new Regex(@"^[a-zA-Z0-9\-_]+$");
        }
 public override void SetupView(BuilderLibraryDragger dragger, BuilderTooltipPreview tooltipPreview,
                                BuilderPaneContent builderPaneContent, BuilderPaneWindow builderPaneWindow,
                                VisualElement documentElement, BuilderSelection selection)
 {
     base.SetupView(dragger, tooltipPreview, builderPaneContent, builderPaneWindow, documentElement, selection);
     FillView(m_Items);
 }
Esempio n. 6
0
 public BuilderCommandHandler(
     BuilderPaneWindow paneWindow,
     BuilderSelection selection)
 {
     m_PaneWindow = paneWindow;
     m_Toolbar    = null;
     m_Selection  = selection;
 }
        public static bool CreateNewUSSAsset(BuilderPaneWindow paneWindow, string ussPath)
        {
            // Create the file. Can be empty.
            File.WriteAllText(ussPath, string.Empty);
            AssetDatabase.Refresh();

            return(AddUSSToAsset(paneWindow, ussPath));
        }
Esempio n. 8
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 BuilderCodePreview(BuilderPaneWindow paneWindow)
        {
            m_PaneWindow = paneWindow;

            m_ScrollView = new ScrollView(ScrollViewMode.VerticalAndHorizontal);
            m_ScrollView.AddToClassList(s_CodeScrollViewClassName);
            m_ScrollView.RegisterCallback <GeometryChangedEvent>(OnGeometryChanged);
            Add(m_ScrollView);

            AddToClassList(s_UssClassName);

            m_Container = new VisualElement();
            m_Container.AddToClassList(s_CodeContainerClassName);

            m_LineNumbers = new Label();
            m_LineNumbers.RemoveFromClassList(TextField.ussClassName);
            m_LineNumbers.AddToClassList(s_CodeClassName);
            m_LineNumbers.AddToClassList(s_CodeLineNumbersClassName);
            m_LineNumbers.AddToClassList(s_CodeInputClassName);

            m_Code = new TextField(TextField.kMaxLengthNone, true, false, char.MinValue);
            m_Code.textSelection.isSelectable = true;
            m_Code.isReadOnly = true;
            m_Code.name       = s_CodeName;
            m_Code.RemoveFromClassList(TextField.ussClassName);
            m_Code.AddToClassList(s_CodeClassName);
            m_Code.AddToClassList(s_CodeTextClassName);
            m_Code.AddToClassList(disabledUssClassName);
            var codeInput = m_Code.Q(className: TextField.inputUssClassName);

            codeInput.AddToClassList(s_CodeInputClassName);

            m_CodeOuterContainer = new VisualElement();
            m_CodeOuterContainer.AddToClassList(s_CodeCodeOuterContainerClassName);
            m_Container.Add(m_CodeOuterContainer);

            m_CodeContainer = new VisualElement();
            m_CodeContainer.AddToClassList(s_CodeCodeContainerClassName);
            m_CodeOuterContainer.Add(m_CodeContainer);

            m_CodeContainer.Add(m_LineNumbers);
            m_CodeContainer.Add(m_Code);

            m_ScrollView.Add(m_Container);

            // Make sure the Hierarchy View gets focus when the pane gets focused.
            primaryFocusable = m_Code;

            // Make sure no key events get through to the code field.
            m_Code.RegisterCallback <KeyDownEvent>(BlockEvent, TrickleDown.TrickleDown);
            m_Code.RegisterCallback <KeyUpEvent>(BlockEvent, TrickleDown.TrickleDown);

            SetText(string.Empty);
        }
        public static VisualElement CreateAbsoluteIsland(BuilderPaneWindow paneWindow, VisualElement documentRootElement, Vector2 localMousePosition)
        {
            var vta       = paneWindow.document.visualTreeAsset;
            var selection = paneWindow.primarySelection;

            // Create absolute island container.
            var absoluteIslandContainer = new VisualElement();

            absoluteIslandContainer.name = "unity-absolute-island";
            documentRootElement.Add(absoluteIslandContainer);
            BuilderAssetUtilities.AddElementToAsset(paneWindow.document, absoluteIslandContainer);

            bool isTop    = localMousePosition.y < documentRootElement.resolvedStyle.height / 2;
            bool isBottom = !isTop;
            bool isLeft   = localMousePosition.x < documentRootElement.resolvedStyle.width / 2;
            bool isRight  = !isLeft;

            // Set Absolute position.
            BuilderStyleUtilities.SetInlineStyleValue(vta, absoluteIslandContainer, "position", Position.Absolute);

            if (isTop && isLeft)
            {
                var left = localMousePosition.x;
                var top  = localMousePosition.y;
                BuilderStyleUtilities.SetInlineStyleValue(vta, absoluteIslandContainer, "left", left);
                BuilderStyleUtilities.SetInlineStyleValue(vta, absoluteIslandContainer, "top", top);
            }
            else if (isTop && isRight)
            {
                var right = documentRootElement.resolvedStyle.width - localMousePosition.x;
                var top   = localMousePosition.y;
                BuilderStyleUtilities.SetInlineStyleValue(vta, absoluteIslandContainer, "right", right);
                BuilderStyleUtilities.SetInlineStyleValue(vta, absoluteIslandContainer, "top", top);
            }
            else if (isBottom && isLeft)
            {
                var left   = localMousePosition.x;
                var bottom = documentRootElement.resolvedStyle.height - localMousePosition.y;
                BuilderStyleUtilities.SetInlineStyleValue(vta, absoluteIslandContainer, "left", left);
                BuilderStyleUtilities.SetInlineStyleValue(vta, absoluteIslandContainer, "bottom", bottom);
            }
            else if (isBottom && isRight)
            {
                var right  = documentRootElement.resolvedStyle.width - localMousePosition.x;
                var bottom = documentRootElement.resolvedStyle.height - localMousePosition.y;
                BuilderStyleUtilities.SetInlineStyleValue(vta, absoluteIslandContainer, "right", right);
                BuilderStyleUtilities.SetInlineStyleValue(vta, absoluteIslandContainer, "bottom", bottom);
            }

            // Need to explicitly update inline styles from asset.
            selection.NotifyOfHierarchyChange(null, absoluteIslandContainer, BuilderHierarchyChangeType.InlineStyle | BuilderHierarchyChangeType.FullRefresh);

            return(absoluteIslandContainer);
        }
        public static bool AddUSSToAsset(BuilderPaneWindow paneWindow, string ussPath)
        {
            bool added = BuilderAssetUtilities.AddStyleSheetToAsset(paneWindow.document, ussPath);

            if (added)
            {
                paneWindow.OnEnableAfterAllSerialization();
            }

            return(added);
        }
        public static bool AddExistingUSSToAsset(BuilderPaneWindow paneWindow)
        {
            string ussPath = s_OpenFileDialogCallback();

            if (string.IsNullOrEmpty(ussPath))
            {
                return(false);
            }

            return(AddUSSToAsset(paneWindow, ussPath));
        }
        public static bool CreateNewUSSAsset(BuilderPaneWindow paneWindow)
        {
            string ussPath = s_SaveFileDialogCallback();

            if (string.IsNullOrEmpty(ussPath))
            {
                return(false);
            }

            return(CreateNewUSSAsset(paneWindow, ussPath));
        }
 public virtual void SetupView(BuilderLibraryDragger dragger, BuilderTooltipPreview tooltipPreview,
                               BuilderPaneContent builderPaneContent, BuilderPaneWindow builderPaneWindow,
                               VisualElement documentElement, BuilderSelection selection)
 {
     m_Dragger             = dragger;
     m_TooltipPreview      = tooltipPreview;
     m_BuilderPaneContent  = builderPaneContent;
     m_PaneWindow          = builderPaneWindow;
     m_DocumentRootElement = documentElement;
     m_Selection           = selection;
 }
 public BuilderLibraryDragger(
     BuilderPaneWindow paneWindow,
     VisualElement root, BuilderSelection selection,
     BuilderViewport viewport, BuilderParentTracker parentTracker,
     VisualElement explorerContainer,
     BuilderTooltipPreview tooltipPreview)
     : base(paneWindow, root, selection, viewport, parentTracker)
 {
     builderHierarchyRoot = explorerContainer;
     m_TooltipPreview     = tooltipPreview;
 }
        public static bool OpenAsSubDocument(BuilderPaneWindow paneWindow, VisualTreeAsset vta)
        {
            bool didSaveChanges = paneWindow.document.CheckForUnsavedChanges();

            if (!didSaveChanges)
            {
                return(false);
            }
            paneWindow.document.AddSubDocument();
            paneWindow.LoadDocument(vta, false);

            return(true);
        }
Esempio n. 17
0
        public virtual void Activate(BuilderPaneWindow paneWindow, BuilderSelection selection, VisualTreeAsset visualTreeAsset, VisualElement target)
        {
            base.Activate(target);

            if (target == null)
            {
                return;
            }

            m_PaneWindow      = paneWindow;
            m_Selection       = selection;
            m_VisualTreeAsset = visualTreeAsset;
        }
        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_StyleSelectorElementContainer  = this.Q(BuilderConstants.StyleSelectorElementContainerName);
            m_DocumentElement        = this.Q("document");
            m_Canvas.documentElement = m_DocumentElement;
            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_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_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;
        }
Esempio n. 19
0
        public static void RemoveUSSFromAsset(BuilderPaneWindow paneWindow, int selectedStyleSheetIndex)
        {
            // We need to save all files before we remove the USS.
            // If we don't do this, changes in the removed USS will be lost.
            var shouldContinue = s_CheckForUnsavedChanges(paneWindow);

            if (!shouldContinue)
            {
                return;
            }

            BuilderAssetUtilities.RemoveStyleSheetFromAsset(paneWindow.document, selectedStyleSheetIndex);
            paneWindow.OnEnableAfterAllSerialization();
        }
Esempio n. 20
0
        public void RegisterWindow(BuilderPaneWindow window)
        {
            if (window == null || m_RegisteredWindows.Contains(window))
            {
                return;
            }

            m_RegisteredWindows.Add(window);

            if (window is IBuilderViewportWindow)
            {
                primaryViewportWindow = window as IBuilderViewportWindow;
                BroadcastChange();
            }
        }
        public BuilderSelection(VisualElement root, BuilderPaneWindow paneWindow)
        {
            m_Notifiers = new List <IBuilderSelectionNotifier>();
            m_Selection = new List <VisualElement>();

            m_Root       = root;
            m_PaneWindow = paneWindow;

            m_DummyElementForStyleChangeNotifications                = new VisualElement();
            m_DummyElementForStyleChangeNotifications.name           = "unity-dummy-element-for-style-change-notifications";
            m_DummyElementForStyleChangeNotifications.style.position = Position.Absolute;
            m_DummyElementForStyleChangeNotifications.style.top      = -1000;
            m_DummyElementForStyleChangeNotifications.style.left     = -1000;
            m_DummyElementForStyleChangeNotifications.style.width    = 1;
            m_DummyElementForStyleChangeNotifications.RegisterCallback <GeometryChangedEvent>(AfterPanelUpdaterChange);
            m_Root.Add(m_DummyElementForStyleChangeNotifications);
        }
Esempio n. 22
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();
        }
        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
                });
            }
        }
Esempio n. 24
0
        public BuilderSelection(VisualElement root, BuilderPaneWindow paneWindow)
        {
            m_Notifiers = new List <IBuilderSelectionNotifier>();
            m_Selection = new List <VisualElement>();

            m_Root       = root;
            m_PaneWindow = paneWindow;

            m_DummyElementForStyleChangeNotifications                = new VisualElement();
            m_DummyElementForStyleChangeNotifications.name           = "unity-dummy-element-for-style-change-notifications";
            m_DummyElementForStyleChangeNotifications.style.position = Position.Absolute;
            m_DummyElementForStyleChangeNotifications.style.top      = -1000;
            m_DummyElementForStyleChangeNotifications.style.left     = -1000;
            m_DummyElementForStyleChangeNotifications.style.width    = 1;
            m_DummyElementForStyleChangeNotifications.RegisterCallback <GeometryChangedEvent>(AfterPanelUpdaterChange);
            m_Root.Add(m_DummyElementForStyleChangeNotifications);

            m_LiveReloadTriggerMethod = ReflectionExtensions.GetStaticMethodByReflection(typeof(UIElementsUtility), "InMemoryAssetsHaveBeenChanged");
        }
Esempio n. 25
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;
        }
Esempio n. 26
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;
        }
Esempio n. 27
0
        public void UnregisterWindow(BuilderPaneWindow window)
        {
            if (window == null)
            {
                return;
            }

            var removed = m_RegisteredWindows.Remove(window);

            if (!removed)
            {
                return;
            }

            if (window is IBuilderViewportWindow && primaryViewportWindow == window as IBuilderViewportWindow)
            {
                primaryViewportWindow = null;
                BroadcastChange();
            }
        }
Esempio n. 28
0
 public BuilderHierarchy(
     BuilderPaneWindow paneWindow,
     BuilderViewport viewport,
     BuilderSelection selection,
     BuilderClassDragger classDragger,
     BuilderHierarchyDragger hierarchyDragger,
     BuilderElementContextMenu contextMenuManipulator,
     HighlightOverlayPainter highlightOverlayPainter)
     : base(
         paneWindow,
         viewport,
         selection,
         classDragger,
         hierarchyDragger,
         new BuilderHierarchyContextMenu(paneWindow, selection),
         viewport.documentElement,
         true,
         highlightOverlayPainter,
         null)
 {
     viewDataKey = "builder-hierarchy";
 }
        public static bool OpenAsSubDocument(BuilderPaneWindow paneWindow, VisualTreeAsset vta, TemplateAsset vea = null)
        {
            bool didSaveChanges = paneWindow.document.CheckForUnsavedChanges();

            if (!didSaveChanges)
            {
                return(false);
            }

            // This is important because if the user chose to not save changes to the
            // parent document, we restore the VTA from backup. The problem with that
            // is that the backup VTA was made before we fixed any USS assignments on
            // root elements. This is fine when simply restoring the backup before a
            // File > New or switching documents (just prior to closing the current document),
            // but this is not ok here because we need the parent document to continue
            // staying open and usable in the UI Builder.
            paneWindow.document.activeOpenUXMLFile.PostLoadDocumentStyleSheetCleanup();

            paneWindow.document.AddSubDocument(vea);
            paneWindow.LoadDocument(vta, false);

            return(true);
        }
Esempio n. 30
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 = BuilderPackageUtilities.LoadAssetAtPath <VisualTreeAsset>(
                BuilderConstants.UIBuilderPackagePath + "/BuilderClassPill.uxml");

            m_AddClassButton.clickable.clicked    += AddStyleClass;
            m_CreateClassButton.clickable.clicked += ExtractLocalStylesToNewClass;
        }