Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
antiero opened this issue Nov 8, 2024 · 0 comments
Assignees
Labels

Comments

@antiero
Copy link

antiero commented Nov 8, 2024

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");
        }
@keijiro keijiro self-assigned this Nov 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants