1
0
mirror of https://github.com/Siccity/xNode.git synced 2025-12-20 01:06:01 +08:00
xNode/Scripts/NodeGraph.cs
Thor Brigsted 6a92f18618 Connections now draw under port handles
Modulized code. Too many minor changes to address
2017-09-30 22:27:01 +02:00

37 lines
1.0 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
/// <summary> Base class for all node graphs </summary>
[Serializable]
public abstract class NodeGraph : ScriptableObject {
/// <summary> All nodes in the graph. <para/>
/// See: <see cref="AddNode{T}"/> </summary>
[SerializeField] public List<Node> nodes = new List<Node>();
public T AddNode<T>() where T : Node {
return AddNode(typeof(T)) as T;
}
public virtual Node AddNode(Type type) {
Node node = (Node)Activator.CreateInstance(type);
nodes.Add(node);
node.graph = this;
return node;
}
/// <summary> Safely remove a node and all its connections </summary>
/// <param name="node"></param>
public void RemoveNode(Node node) {
node.ClearConnections();
nodes.Remove(node);
}
/// <summary> Remove all nodes and connections from the graph </summary>
public void Clear() {
nodes.Clear();
}
}