Skip to content

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:

using UnityEngine;
using UnityEditor;
using GraphProcessor;

public class DefaultGraphWindow : BaseGraphWindow
{
	// Add the window in the editor menu
	[MenuItem("Window/01_DefaultGraph")]
	public static BaseGraphWindow Open()
	{
		var graphWindow = GetWindow< DefaultGraphWindow >();

		graphWindow.Show();

		return graphWindow;
	}

	protected override void InitializeWindow(BaseGraph graph)
	{
		// Set the window title
		titleContent = new GUIContent("Default Graph");

		// Here you can use the default BaseGraphView or a custom one (see section below)
		var graphView = new BaseGraphView(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.

Customize graph view

Example of a custom graph view which override the default contextual menu:

public class CustomContextMenuGraphView : BaseGraphView
{
	public override void BuildContextualMenu(ContextualMenuPopulateEvent evt)
	{
		evt.menu.AppendSeparator();
		
		// Add the "Hello World" menu item which print Hello World in the console
		evt.menu.AppendAction("Hello World",
			(e) => Debug.Log("Hello World"),
			DropdownMenu.MenuAction.AlwaysEnabled
		);

		base.BuildContextualMenu(evt);
	}
}
Clone this wiki locally