How to make a graph in GUI?

Do anybody here know how to make a graph that can be easily positioned with GUI especially with C#?

You’ll have to code your own. I suggest you create your own class Graph with an unknown number of columns and styles. in a Draw function, you can use DrawTexture for the background and each columns according to an array of float.

Saturday, August 1, 2015

Extend GraphGUI found in UnityEditor.Graphs. This class is responsible for drawing graph.

public class GraphEditorWindow : EditorWindow
 static GraphEditorWindow graphEditorWindow;
 Graph stateMachineGraph;

 GraphGUIEx stateMachineGraphGUI;
 static void Do ()
 graphEditorWindow = GetWindow<Grapheditorwindow> ();


Create Graph structure. It will contains nodes and edges between nodes.

stateMachineGraph = ScriptableObject.CreateInstance<Graph> ();
 stateMachineGraph.hideFlags = HideFlags.HideAndDontSave;

 //create new node
 Node node=ScriptableObject.CreateInstance<Node>();
 node.position=new Rect(400,34,300,200);

 node.AddProperty(new Property(typeof(System.Int32),"integer"));
//create new node
 Node node=ScriptableObject.CreateInstance<Node>();
 node.position=new Rect(0,0,300,200);
 Slot end=node.AddInputSlot("input");
 node.AddProperty(new Property(typeof(System.Int32),"integer"));

//create edge

GraphGUIEx graphGUI = ScriptableObject.CreateInstance<GraphGUIEx>();
graphGUI.graph = graph;

Draw Graph.

void OnGUI ()
 if (graphEditorWindow && stateMachineGraphGUI != null) {
 stateMachineGraphGUI.BeginGraphGUI (graphEditorWindow, new Rect (0, 0, graphEditorWindow.position.width, graphEditorWindow.position.height));
 stateMachineGraphGUI.OnGraphGUI ();

 stateMachineGraphGUI.EndGraphGUI ();

Override NodeGUI or EdgeGUI for more styling and drawing control.