using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
/// Base class for all node graphs
[Serializable, CreateAssetMenu(fileName = "NewNodeGraph", menuName = "Node Graph")]
public class NodeGraph : ScriptableObject {
/// All nodes in the graph.
/// See:
[NonSerialized] public List nodes = new List();
/// Serialized nodes.
[SerializeField] public string[] s_nodes;
public T AddNode() where T : Node {
T node = default(T);
return AddNode(node) as T;
}
public Node AddNode(Type type) {
Node node = (Node)Activator.CreateInstance(type);
return AddNode(node);
}
public Node AddNode(string type) {
Debug.Log(type);
Node node = (Node)Activator.CreateInstance(null,type).Unwrap();
return AddNode(node);
}
public Node AddNode(Node node) {
if (node == null) {
Debug.LogError("Node could node be instanced");
return null;
}
nodes.Add(node);
node.graph = this;
return node;
}
/// Safely remove a node and all its connections
///
public void RemoveNode(Node node) {
node.ClearConnections();
nodes.Remove(node);
}
public void Clear() {
nodes.Clear();
}
private class NodeTyper {
public string nodeType = "Node";
}
}