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"); }; }
/// <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(); }