14.09.2019»»суббота

Unity Custom Graph Control

14.09.2019
    32 - Comments
Unity Custom Graph Control 8,9/10 2599 reviews

Unity3D's Mecanim animations system has a custom EditorWindow that allows to define a tree (a blend tree in this case) thorough GUI.

  1. Unity Custom Graph Controller
  2. Unity Custom Graph Control Chart

So if I want to control more than one character with the same graph, I need to create a separate graph for each character, and create all the elements for all the graphs individually. I hoped AnimationPlayableUtilities.Play might do it, but it was crashing Unity (maybe because the graph has an AnimationControllerPlayable which uses a unique.

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
HeisenbugHeisenbug
29.9k23 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

Unity Custom Graph Controller

29.9k23 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,7454 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.

Unity custom graph controls
robertwolfheartrobertwolfheart

Unity Custom Graph Control Chart

Not the answer you're looking for? Browse other questions tagged c#unity3d or ask your own question.