Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

UnityEditor.Graphs - No documentation

Discussion in 'Scripting' started by SeriousBusinessFace, Nov 13, 2015.

  1. SeriousBusinessFace

    SeriousBusinessFace

    Joined:
    May 10, 2014
    Posts:
    127
    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:

    http://stackoverflow.com/questions/17593101/how-to-write-a-gui-editor-for-graph-or-tree-structures

    My code currently looks like this:

    Code (CSharp):
    1.     [MenuItem("Window/Composite Statistics/Actor Wizard")]
    2.     public static void ShowWindow()
    3.     {
    4.         GetWindow<ActorWizard>();
    5.     }
    6.  
    7.     private void RefreshGraph()
    8.     {
    9.         if (!graph)
    10.         {
    11.             graph = CreateInstance<Graph>();
    12.             // graph.hideFlags = HideFlags.HideAndDontSave;
    13.             graph.Clear();
    14.  
    15.             Node node = CreateInstance<Node>();
    16.             node.title = _actorName;
    17.             node.position = new Rect(100F, 0F, 200F, 100F);
    18.             node.AddProperty(new Property(typeof(string), "Actor"));
    19.  
    20.             graph.AddNode(node);
    21.         }
    22.  
    23.         if (!graphGUI)
    24.             graphGUI = CreateInstance<ActorWizardGraphGUI>();
    25.         // graphGUI.graph = graph;
    26.         // graphGUI.graph = null;
    27.         // graph = null;
    28.  
    29.         EditorUtility.SetDirty(graphGUI);
    30.     }
    31.  
    32.     private Graph graph;
    33.     private ActorWizardGraphGUI graphGUI;
    34.     private GameObject _actorGO;
    35.     private Actor _actor = null;
    36.     private string _actorName = "None";
    37.     private Vector2 _scrollPosition;
    38.  
    39.     void OnGUI()
    40.     {
    41.         // if (!graphGUI)
    42.             RefreshGraph();
    43.         if (graphGUI != null && graphGUI.graph != null)
    44.         {
    45.             graphGUI.BeginGraphGUI(this, new Rect(0F, 0F, position.xMax, position.yMax));
    46.             graphGUI.OnGraphGUI();
    47.             graphGUI.EndGraphGUI();
    48.         }
    49.     }
    50.  
    51.     private void CheckForActor()
    52.     {
    53.         var tempGO = (GameObject)EditorGUILayout.ObjectField("Actor: ", _actorGO, typeof(GameObject), true);
    54.         if (tempGO != _actorGO)
    55.         {
    56.             if (tempGO)
    57.             {
    58.                 var tempActor = tempGO.GetComponent<Actor>();
    59.                 if (tempActor)
    60.                 {
    61.                     _actorGO = tempGO;
    62.                     _actor = tempActor;
    63.                 }
    64.             }
    65.         }
    66.     }
    Images of what I've managed to get it to do:

    This is wrong.jpg
    This is wrong, too.jpg

    How do I fix this, so that both the grid and the node display properly?
     
    unity_AOKj7uK4VjvdWw likes this.
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    There's a link in that SO thread about writing your own node editor, which is what I would do (and have done) since there's no documentation on the Graphs namespace
     
  3. SeriousBusinessFace

    SeriousBusinessFace

    Joined:
    May 10, 2014
    Posts:
    127
    Thank you. I'm not sure how I missed those.
     
  4. SeriousBusinessFace

    SeriousBusinessFace

    Joined:
    May 10, 2014
    Posts:
    127
    Having explored those links, as far as I can tell none of them use UnityEditor.Graphs. While they do involve creating a graph, my question specifically addresses the classes found in that namespace.
     
  5. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    cant imagine there's anything in the namespace that you cant recreate.
    without docs, you'll just have to test them all using the intellisense hints (sadly, no documentation in there either) unless someone whos used them shows up.

    writing your own means you know how it works, and it won't run on 'black magic'
     
  6. SeriousBusinessFace

    SeriousBusinessFace

    Joined:
    May 10, 2014
    Posts:
    127
    Figuring it out without documentation is exactly what I'm doing right now. I'm doing quite well at it, in fact.

    However, having taught myself programming for close to two decades, I appreciate the value of good documentation, and tutorials.
     
    unity_AOKj7uK4VjvdWw likes this.
  7. Jemlink

    Jemlink

    Joined:
    Jan 2, 2019
    Posts:
    1
    I am also trying to work myself in this topic. Have you meanwhile found any documentary or do you have any tipps for someone new to graph editors?
     
    unity_AOKj7uK4VjvdWw likes this.