Skip to content

Nexerate/nodes

Repository files navigation

Nexerate Nodes

Nexerate Nodes is a framework for creating node based hierarchy tools.

How to install through the Unity Package Manager:

  1. Copy this link
https://github.com/Nexerate/nodes.git
  1. Open the Package Manager and navigate to the plus icon in the upper left corner.
  2. Choose Add package from git URL, paste the URL in, and click Add.

Basic Setup:

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> 
{

}

Features:

  • Node Asset

    • A NodeAsset is the ScriptableObject that holds your Node hierarchy. It can be created by adding the [CreateAssetMenu] attribute to your class that derives from NodeAsset<T>. T is the minimum requiremenent for nodes in your hierarchy. Only nodes of type T or nodes derived from T will 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).
  • Node

    • The hierarchy is built up of nodes that are linked together through their relationship with their parent Node. The Node class 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.

    This is possible through the following methods:

    • Node.LockChildren() Lock the children directly below this Node. These children can be moved around, but not reparented to other nodes, and they cannot be deleted.
    • Node.LockHierarchy() Lock the entire hierarchy below this Node. No nodes with this Node as 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 a Node. The rest of the hierarchy is free to do what it wants, but you will be unable to change the parent of this Node. You will also be unable to delete it.
  • Component Node

    • A ComponentNode is a Node that can have node components.
  • Node Component

    • A NodeComponent<T> can be added to component nodes that either are of type T or derive from T. By themselves, node components don't do much, but here are some examples of how they can be used:

    Input

    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;
            }
        }
    }

    Iterate over

    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);
        }
    }
  • Attributes:

    • [AddNodeMenu] Decide where in the "Add Node" menu your Node should show up.
    • [RequireNodeComponents] Decide what components are required by this ComponentNode. Required components are added automatically, and cannot be removed. Attribute is inherited.
    • [DisallowMultiple] Add this attribute to a NodeComponent to disallow multiple components of this type on the same Node.

About

Framework for creating node-based hierarchy tools in Unity.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages