Skip to content

Feature request: Example to show Klak Graphs being built in C# Script for runtime graph changes #47

@antiero

Description

@antiero

I may be missing something obvious, but it doesn't seem like the Klak system is geared up to creating Node Graphs via scripting, and it's always linked to the Editor Window objects?

I've inspected the EditorWindow stuff and can see how it should be possible to create scripts to do this, but it would be lovely to see an example of Creating a Klak graph using some C# scripting.

The logic for creating Nodes seems to be in GraphGUI.cs, which is fine, but I'd love to do the same and create connections via scripting if possible, to allow runtime changes to be made to the Klak graph.

        void CreateMenuItemCallback(object data)
        {
            var type = data as Type;

            // Create a game object.
            var name = ObjectNames.NicifyVariableName(type.Name);
            var gameObject = new GameObject(name);
            var nodeRuntime = (Wiring.NodeBase)gameObject.AddComponent(type);
            gameObject.transform.parent = ((Graph)graph).patch.transform;

            // Add it to the graph.
            var node = Node.Create(nodeRuntime);
            node.position = new Rect((Vector2)m_contextMenuMouseDownPosition, Vector2.zero);
            node.Dirty();
            graph.AddNode(node);

            // Select the new node.
            ClearSelection();
            selection.Add(node);
            UpdateUnitySelection();

            // Make it undo-able.
            Undo.RegisterCreatedObjectUndo(gameObject, "New Node");
        }

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions