Unity is the ultimate game development platform. Use Unity to build high-quality 3D and 2D games, deploy them across mobile, desktop, VR/AR, consoles or the Web, and connect with loyal and enthusiastic players and customers. Can be extended to work with any custom render pipeline. Build your shaders with a visual editor. Unity 2018.1 brought new levels of control and flexibility, and introduced Shader Graph. Whether you’re a beginner or a pro, it helps you create a range of shaders – flowing lava, gooey slime, beautiful lakes, flashing LEDs, and more.
-->
Heisenbug
Example
The following example shows how to create and use an instance of Grid by using either Extensible Application Markup Language (XAML) or code. This example uses three ColumnDefinition objects and three RowDefinition objects to create a grid that has nine cells, such as in a worksheet. Each cell contains a TextBlock element that represents data, and the top row contains a TextBlock with the ColumnSpan property applied. To show the boundaries of each cell, the ShowGridLines property is enabled.
Either approach will generate a user interface that looks much the same, like the one below.
See also
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
Heisenbug
![Unity Unity](/uploads/1/2/4/7/124726247/257492083.png)
29.8k23 gold badges113 silver badges175 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:
HeisenbugHeisenbug
29.8k23 gold badges113 silver badges175 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 Blue
1,7404 gold badges22 silver badges30 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