- Notifications
You must be signed in to change notification settings - Fork 435
Graph Window API
Antoine Lelievre edited this page Jul 16, 2020
·
2 revisions
Here is an example of how to create a new window for the base graph view:
usingUnityEngine;usingUnityEditor;usingGraphProcessor;publicclassDefaultGraphWindow:BaseGraphWindow{// Add the window in the editor menu[MenuItem("Window/01_DefaultGraph")]publicstaticBaseGraphWindowOpen(){vargraphWindow=GetWindow<DefaultGraphWindow>();graphWindow.Show();returngraphWindow;}protectedoverridevoidInitializeWindow(BaseGraphgraph){// Set the window titletitleContent=newGUIContent("Default Graph");// Here you can use the default BaseGraphView or a custom one (see section below)vargraphView=newBaseGraphView(this);rootView.Add(graphView);}}In the InitializeWindow function you assign the graph view to the root view of a window, you can then add more things on top of the graph like a minimap graphView.Add(new MiniMapView(graphView)); for example.
Example of a custom graph view which override the default contextual menu:
publicclassCustomContextMenuGraphView:BaseGraphView{publicoverridevoidBuildContextualMenu(ContextualMenuPopulateEventevt){evt.menu.AppendSeparator();// Add the "Hello World" menu item which print Hello World in the consoleevt.menu.AppendAction("Hello World",(e)=>Debug.Log("Hello World"),DropdownMenu.MenuAction.AlwaysEnabled);base.BuildContextualMenu(evt);}}