McManning / BlueGraph

Visual Scripting Framework for Unity
MIT License
237 stars 30 forks source link

Open Graph Instance at runtime #44

Open neoneper opened 3 years ago

neoneper commented 3 years ago

I am instantiating a graph at runtime and I would like to know how I could go about opening the graph window for this instance.

McManning commented 3 years ago

Something like this? Specifically the CreateWindow and Load calls

using BlueGraph.Editor;
using BlueGraphSamples;
using UnityEditor;
using UnityEngine;

public class MakeDynamicGraph : MonoBehaviour
{
    MonoBehaviourGraph graph;

    void Update()
    {
        if (Input.GetKeyUp(KeyCode.Space))
        {
            // Make sure references to editor scripts are stripped
            // while compiling a real build.
            #if UNITY_EDITOR

            if (!graph)
            {
                graph = ScriptableObject.CreateInstance<MonoBehaviourGraph>();
            }

            var editor = EditorWindow.CreateWindow<GraphEditorWindow>();
            editor.Load(graph);

            #endif
        }
    }
}