How to write a GUI editor for Graph or Tree structures
c#, unity-game-engine
Solution
I was not asking "for a find a tool, library or favorite off-site resource". I would like to know how reproduce a `Mecanim` like graph editor using `Unity3D` API or some available components provided by the engine itself (sorry if the question wasn't clear).
Here's my answer:
No, there's isn't an available component usable as is to draw that kind of graph, but it's quite easy to write your own. Here's a snippet with a simple example using draggable GUI.Window to represent nodes and Handles.DrawBezier to draw the edges:
public class GraphEditorWindow : EditorWindow
{
Rect windowRect = new Rect (100 + 100, 100, 100, 100);
Rect windowRect2 = new Rect (100, 100, 100, 100);
[MenuItem ("Window/Graph Editor Window")]
static void Init () {
EditorWindow.GetWindow (typeof (GraphEditorWindow));
}
private void OnGUI()
{
Handles.BeginGUI();
Handles.DrawBezier(windowRect.center, windowRect2.center, new Vector2(windowRect.xMax + 50f,windowRect.center.y), new Vector2(windowRect2.xMin - 50f,windowRect2.center.y),Color.red,null,5f);
Handles.EndGUI();
BeginWindows();
windowRect = GUI.Window (0, windowRect, WindowFunction, "Box1");
windowRect2 = GUI.Window (1, windowRect2, WindowFunction, "Box2");
EndWindows();
}
void WindowFunction (int windowID)
{
GUI.DragWindow();
}
}
Problem
`Unity3D`'s `Mecanim` animations system has a custom `EditorWindow` that allows to define a tree (a blend tree in this case) thorough GUI. It looks like: It offers the possibility of creating nodes (states) and connect them (transitions). Now, I'm developing some graph and and tree structure and I would like to write an editor extension in order to allow my game designer to populate those structures. I want pretty most recreate exactly an `EditorWindow` like the one of Mecanim animator (figure above). My question is: are there any available components that I can use for such a task? Is there any builtin class used for the drawing and connecting boxes and arrow? Or I need to write completely the GUI elements by my own?