I’m trying to write an editor window graph GUI, using UnityEditor.Graphs. Unfortunately, there’s no official documentation that I can find, and I only found a single post on StackOverflow here:
My code currently looks like this:
[MenuItem("Window/Composite Statistics/Actor Wizard")]
public static void ShowWindow()
{
GetWindow<ActorWizard>();
}
private void RefreshGraph()
{
if (!graph)
{
graph = CreateInstance<Graph>();
// graph.hideFlags = HideFlags.HideAndDontSave;
graph.Clear();
Node node = CreateInstance<Node>();
node.title = _actorName;
node.position = new Rect(100F, 0F, 200F, 100F);
node.AddProperty(new Property(typeof(string), "Actor"));
graph.AddNode(node);
}
if (!graphGUI)
graphGUI = CreateInstance<ActorWizardGraphGUI>();
// graphGUI.graph = graph;
// graphGUI.graph = null;
// graph = null;
EditorUtility.SetDirty(graphGUI);
}
private Graph graph;
private ActorWizardGraphGUI graphGUI;
private GameObject _actorGO;
private Actor _actor = null;
private string _actorName = "None";
private Vector2 _scrollPosition;
void OnGUI()
{
// if (!graphGUI)
RefreshGraph();
if (graphGUI != null && graphGUI.graph != null)
{
graphGUI.BeginGraphGUI(this, new Rect(0F, 0F, position.xMax, position.yMax));
graphGUI.OnGraphGUI();
graphGUI.EndGraphGUI();
}
}
private void CheckForActor()
{
var tempGO = (GameObject)EditorGUILayout.ObjectField("Actor: ", _actorGO, typeof(GameObject), true);
if (tempGO != _actorGO)
{
if (tempGO)
{
var tempActor = tempGO.GetComponent<Actor>();
if (tempActor)
{
_actorGO = tempGO;
_actor = tempActor;
}
}
}
}
Images of what I’ve managed to get it to do:
How do I fix this, so that both the grid and the node display properly?
