Nexerate Nodes is a framework for creating node based hierarchy tools.
- Copy this link
https://github.com/Nexerate/nodes.git
- Open the Package Manager and navigate to the plus icon in the upper left corner.
- Choose
Add package from git URL, paste the URL in, and clickAdd.
using Nexerate.Nodes;
using System;
[Serializable]
[AddNodeMenu("Example/Node")]
public class ExampleNode : Node
{
}using Nexerate.Nodes;
using UnityEngine;
[CreateAssetMenu(fileName = "Example Hierarchy", menuName = "Example/Example Hierarchy")]
public class ExampleHierarchy : NodeAsset<ExampleNode>
{
}-
- A
NodeAssetis theScriptableObjectthat holds yourNodehierarchy. It can be created by adding the[CreateAssetMenu]attribute to your class that derives fromNodeAsset<T>.Tis the minimum requiremenent for nodes in your hierarchy. Only nodes of typeTor nodes derived fromTwill show up in the "Add Node" menu. This has the main purpose of predictability (you know what type of nodes you have to deal with), but also separation (your nodes will not be mixed with the nodes of other people, unless designed to).
- A
-
- The hierarchy is built up of nodes that are linked together through their relationship with their parent
Node. TheNodeclass itself is abstract, but you can derive from it to create custom nodes for your tool. Nodes have their own hierarchies that you can lock to prevent people from changing them.
Node.LockChildren()Lock the children directly below thisNode. These children can be moved around, but not reparented to other nodes, and they cannot be deleted.Node.LockHierarchy()Lock the entire hierarchy below thisNode. No nodes with thisNodeas an ancestor can be reparented. You can also not add any new nodes to its hierarchy nor delete any nodes in it.Node.LockParent()Lock the parent of aNode. The rest of the hierarchy is free to do what it wants, but you will be unable to change the parent of thisNode. You will also be unable to delete it.
- The hierarchy is built up of nodes that are linked together through their relationship with their parent
-
- A
ComponentNodeis aNodethat can have node components.
- A
-
- A
NodeComponent<T>can be added to component nodes that either are of typeTor derive fromT. By themselves, node components don't do much, but here are some examples of how they can be used:
using Nexerate.Nodes; using UnityEngine; [Serializable] [RequireNodeComponents(typeof(ExampleComponent))] public class ExampleNode : ComponentNode { [SerializeReference] ExampleComponent input; //On the NodeAsset, iterate over all nodes and call Debug public void Debug() { Debug.Log(input.a * input.b); } [Serializable, DisallowMultiple] public class ExampleComponent : NodeComponent<ExampleNode> { public float a = 2; public float b = 5; public ExampleComponent(ExampleNode target) : base(target) { target.input = this; } } }
using Nexerate.Nodes; using UnityEngine; [Serializable] [RequireNodeComponents(typeof(ExampleComponent))] public class ExampleNode : ComponentNode { [SerializeReference] ExampleComponent input; //On the NodeAsset, iterate over all nodes and call Debug public void Debug() { for (int i = 0; i < components.Count; i++) { var component = (ExampleComponent)components[i]; component.Debug(); } } } [Serializable] [AddNodeComponentMenu("Example/Component")] public class ExampleComponent : NodeComponent<ExampleNode> { public float a = 2; public float b = 5; public void Debug() { Debug.Log(a * b); } }
- A
-
[AddNodeMenu]Decide where in the "Add Node" menu yourNodeshould show up.[RequireNodeComponents]Decide what components are required by thisComponentNode. Required components are added automatically, and cannot be removed. Attribute is inherited.[DisallowMultiple]Add this attribute to aNodeComponentto disallow multiple components of this type on the sameNode.