public LibraryTabElement(Action <string> onObjectFieldDoubleClick, CustomMenuController customMenuController, GraphTypeMetadata graphTypeMetadata)
        {
            OnObjectFieldDoubleClick = onObjectFieldDoubleClick;

            var uxmlAsset = Resources.Load <VisualTreeAsset>(ResourceAssetPaths.LibraryTabElement_UXML);

            uxmlAsset.CloneTree(this);

            m_currentGraphDisplay               = this.Q <ObjectDisplayField>(OPENED_GRAPH_FIELD);
            m_createGraphInstanceButton         = this.Q <Button>(CREATE_GRAPH_INSTANCE_BUTTON);
            m_generateGraphClassButton          = this.Q <Button>(GENERATE_GRAPH_CLASS_BUTTON);
            m_generateNodeClassButton           = this.Q <Button>(GENERATE_NODE_CLASS_BUTTON);
            m_generateNodeViewDrawerClassButton = this.Q <Button>(GENERATE_NODEVIEWDRAWER_CLASS_BUTTON);

            m_graphTypeMetadata    = graphTypeMetadata;
            m_recentsController    = new RecentsController(this);
            m_favoritesController  = new FavoritesController(this);
            m_allGraphsController  = new AllGraphsController(this);
            m_customMenuController = customMenuController;

            m_customMenuController.AddCustomMenu("CreateGraphInstance", new CreateGraphInstanceCustomMenu(m_graphTypeMetadata));
            m_customMenuController.AddCustomMenu("GenerateGraphClass", new GenerateGraphClassCustomMenu());
            m_customMenuController.AddCustomMenu("GenerateNodeClass", new GenerateNodeClassCustomMenu(m_graphTypeMetadata));
            m_customMenuController.AddCustomMenu("GenerateNodeViewDrawerClass", new GenerateNodeViewDrawerClassCustomMenu(m_graphTypeMetadata));


            m_createGraphInstanceButton.clicked         += () => { m_customMenuController.ShowCustomMenu("CreateGraphInstance"); };
            m_generateGraphClassButton.clicked          += () => { m_customMenuController.ShowCustomMenu("GenerateGraphClass"); };
            m_generateNodeClassButton.clicked           += () => { m_customMenuController.ShowCustomMenu("GenerateNodeClass"); };
            m_generateNodeViewDrawerClassButton.clicked += () => { m_customMenuController.ShowCustomMenu("GenerateNodeViewDrawerClass"); };
        }
        public NodeGraphView(GraphTypeMetadata graphTypeMetadata)
        {
            styleSheets.Add(Resources.Load <StyleSheet>(ResourceAssetPaths.NodeGraphView_StyleSheet));

            SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale);
            CustomContentDragger customContentDragger = new CustomContentDragger();

            this.AddManipulator(customContentDragger);
            SecondarySelectionDragger secondarySelectionDragger = new SecondarySelectionDragger();

            this.AddManipulator(secondarySelectionDragger); // Order here matters because the SecondarySelectionDragger allows the event to propagate
            this.AddManipulator(new SelectionDragger());
            this.AddManipulator(new RectangleSelector());

            // Grid lines
            m_gridBackground = new GridBackground();
            Insert(0, m_gridBackground);
            m_gridBackground.StretchToParentSize();

            // Minimap
            m_miniMap = new MiniMap {
                anchored = true
            };
            m_miniMap.SetPosition(new Rect(0, 0, 200, 200));
            this.RegisterCallback <GeometryChangedEvent>((GeometryChangedEvent evt) => { m_miniMap.SetPosition(new Rect(evt.newRect.xMax - 210, evt.newRect.yMax - 210, 200, 200)); });
            Add(m_miniMap);

            GraphTypeMetadata    = graphTypeMetadata;
            m_nodeCreationWindow = ScriptableObject.CreateInstance <NodeCreationWindow>();
            m_nodeCreationWindow.Setup(this, GraphTypeMetadata);

            nodeCreationRequest = context =>
            {
                SearchWindow.Open(new SearchWindowContext(context.screenMousePosition, 0, 0), m_nodeCreationWindow);
            };
            graphViewChanged += OnGraphViewChanged;

            m_edgeConectorListener  = new EdgeConnectorListener(this);
            serializeGraphElements += CopyAndSerializeGraphElements;
            unserializeAndPaste    += UnserializeAndPasteGraphElements;
            canPasteSerializedData += CanUnserializeAndPaste;

            RegisterCallback <MouseMoveEvent>(x => { m_mousePosition = x.localMousePosition; });
            RegisterCallback <MouseUpEvent>(x => { OnMouseClick?.Invoke(); });
            Undo.undoRedoPerformed += () => { SetNodeCollection(NodeGraph); };

            m_graphAxesController = new GraphAxesController(this, customContentDragger, secondarySelectionDragger);
            Add(m_graphAxesController);
            m_graphAxesController.PlaceBehind(contentViewContainer);
            m_graphAxesController.SetEnable(true);
        }
Exemple #3
0
 public void Setup(NodeGraphView nodeGraphView, GraphTypeMetadata graphTypeMetadata)
 {
     m_nodeGraphView     = nodeGraphView;
     m_graphTypeMetadata = graphTypeMetadata;
 }
Exemple #4
0
        /// <summary>
        /// When the UI is enabled, it sets up all the VisualElement references and loads in the window data.
        /// </summary>
        private void OnEnable()
        {
            //==================================Load Initial Data======================================//
            var uxmlAsset = Resources.Load <VisualTreeAsset>(ResourceAssetPaths.LogicalGraphWindow_UXML);

            uxmlAsset.CloneTree(rootVisualElement);
            m_mainSplitView     = rootVisualElement.Q <UIElements.TwoPaneSplitView>(MAIN_SPLITVIEW);
            m_graphTypeMetadata = new GraphTypeMetadata();
            //=========================================================================================//=

            //==================================Register Toolbar=======================================//
            m_toolbar = rootVisualElement.Q <Toolbar>(TOOLBAR);

            // Save Button
            m_saveGraphButton = new ToolbarButton(() =>
            {
                if (m_openedGraphInstance != null)
                {
                    EditorUtility.SetDirty(m_openedGraphInstance);
                    AssetDatabase.SaveAssets();
                }
            });
            m_saveGraphButton.text = "Save";
            m_toolbar.Add(m_saveGraphButton);
            //=========================================================================================//

            //====================================Register Panels======================================//
            // Left panel is dependent on the right (NodeGraphView) so ordering is important!
            VisualElement mainPanelRight = rootVisualElement.Q <VisualElement>(MAIN_PANEL_RIGHT);
            VisualElement mainPanelLeft  = rootVisualElement.Q <VisualElement>(MAIN_PANEL_LEFT);

            // Populate right panel
            m_nodeGraphView = new NodeGraphView(m_graphTypeMetadata);
            m_nodeGraphView.StretchToParentSize();
            m_nodeGraphView.OnAddToSelection      += OnGraphElementSelectionAdded;
            m_nodeGraphView.OnRemoveFromSelection += OnGraphElementSelectionRemoved;
            m_nodeGraphView.OnClearSelection      += OnGraphElementSelectionCleared;
            mainPanelRight.Add(m_nodeGraphView);

            m_customMenuController = new CustomMenuController(mainPanelRight, m_nodeGraphView);

            // Populate left panel
            List <(string, TabContentElement)> tabs = new List <(string, TabContentElement)>();

            tabs.Add(("Library", m_libraryTab = new LibraryTabElement((string guid) => { OpenGraph(guid); }, m_customMenuController, m_graphTypeMetadata)));
            tabs.Add(("Inspector", m_inspectorTab = new InspectorTabElement(m_nodeGraphView)));
            m_nodeGraphView.OnRemoveNode += (node) => { m_inspectorTab.SetNode(null, null); };
            m_mainTabGroup = new TabGroupElement(tabs);
            m_mainTabGroup.StretchToParentSize();
            m_nodeGraphView.OnMouseClick += () => { m_mainTabGroup.SelectTab(m_inspectorTab); };
            mainPanelLeft.Add(m_mainTabGroup);

            // Other setup
            m_inspectorTab.GraphInspector.OnBlackboardElementChanged += (undoGroup) => { m_nodeGraphView.CallAllNodeViewDrawerBlackboardElementChanged(undoGroup); };
            //=========================================================================================//

            //==================================Callback Listeners=====================================//
            GraphModificationProcessor.OnGraphCreated    += OnNewGraphCreated;
            GraphModificationProcessor.OnGraphWillDelete += OnGraphWillDelete;
            //=========================================================================================//

            // Deserialize the editor window data.
            DeserializeData();
        }