Siccity / xNode

Unity Node Editor: Lets you view and edit node graphs inside Unity
MIT License
3.27k stars 581 forks source link

Converting sceneGraph to cs script #280

Open TheBricktop opened 4 years ago

TheBricktop commented 4 years ago

I have an idea to make the xnode simple scripting tool for artists, but as i've understand from wiki currently there is no way to create a prefabs with graphs for reusability. If there was a way to convert the scriptable asset to a conventional cs script it would be nice to know where to start. Anybody had any experience with creating procedural code that way?

Siccity commented 4 years ago

xNode is not a visual scripting framework. Generating procedural code from graphs is possible, but completely outside the scope of xNode.

While prefabs cannot contain graphs due to engine limitations, a prefab can reference any other graph asset. On prefab instantiation you can call graph.Copy(), and you'll have a fresh graph copy to work with for your prefab.

TheBricktop commented 4 years ago

Thanks for answering my question, so for example if I'm going to make a graph that controls transform position of the gameobject I have to create scene graph and a script for instantiating the referenced control graph?

Siccity commented 4 years ago

You can override SceneGraph and have the same script handle both things. Something like this

public class MySceneGraph : SceneGraph<MyGraph> {
  private void Awake() {
    graph = graph.Copy();
    graph.transformTarget = this;
  }
}