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;
        }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
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(); });
        }