![Control Control](/uploads/1/2/5/7/125755915/650309645.png)
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.
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?
Heisenbug
HeisenbugHeisenbug29.8k2323 gold badges113113 silver badges175175 bronze badges
5 Answers
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:
HeisenbugHeisenbug29.8k2323 gold badges113113 silver badges175175 bronze badges
You are wrong dude. Everything you see in UnityEditor must have code somewhere. Your MecanimEditor is in namespace UnityEditor.Graphs.AnimationStateMachine.
Extend GraphGUI found in UnityEditor.Graphs. This class is responsible for drawing graph.
Create new EditorWindow.
Create Graph structure. It will contains nodes and edges between nodes.
Draw Graph.
Override NodeGUI or EdgeGUI for more styling and drawing control.Copy paste code from UnityEditor.Graphs.AnimationStateMachine.GraphGUI styling done in NodeGUI and EdgeGUI.
user999913user999913
This topic is quite complicated, but if you want a nice repository of starter scripts check out this forum thread on Unity's official site http://forum.unity3d.com/threads/simple-node-editor.189230/
*Update: Someone has posted a complex tutorial series, heavily detailing how to create exactly what you've described. Enjoy https://www.youtube.com/watch?v=gHTJmGGH92w.
Edit: I've written a fully functioning Unity graph editor in a GitHub repo. Primarily focused on skill trees. It isn't perfect, but demonstrates what a fully functioning graph editor could look like. Source code in the following link.
Ash BlueAsh Blue1,74044 gold badges2222 silver badges3030 bronze badges
You could try making an Object for the data inside of each tree objects.Then you could try using System.Drawing to create a custom control(square boxes in the picture), also use System.Drawing to create those arrows to each tree object. make sure each DataObject has ID's and information for where the arrows should be pointing.If you need help on creating custom controls i have used this tutorial on YouTube in the past.
McSwaggensMcSwaggens
I've done an interface for creating custom graphs using a TreeViewer and checkboxers. Is based on an 'adjacency list' idea. If you have the checkbox of the 'root' vertex checked, it makes it adjacent to the other vertex, if you just want a few vertex to be adjacent, then you select each one separetaly. I've developed this for java, but I believe it could also work for your purpose. Here's an image that I hope that clarifies my idea.
robertwolfheartrobertwolfheart