public NodeGraph() { // Default graph type. GraphType = new NodeGraphType(); Nodes = new List <Node>(); Connections = new List <NodeConnection>(); Variables = new List <NodeGraphVariable>(); Helper = new NodeGraphHelper(this); State = new NodeGraphState(this); }
public void Load(NodeGraphData graphData) { NodeEditor.Logger.Log <NodeGraph>("Initializing..."); Unload(); NodeEditor.Logger.Log <NodeGraph>("Reading from graph data..."); if (string.IsNullOrEmpty(graphData.GraphType)) { NodeEditor.Logger.LogWarning <NodeGraph>("Loading graph with no graph type. Defaulting..."); GraphType = _defaultGraphType; } else { var type = Type.GetType(graphData.GraphType); NodeEditor.Assertions.IsNotNull(type, "Invalid graph type."); if (type != null) { GraphType = Activator.CreateInstance(type) as NodeGraphType; NodeEditor.Logger.Log <NodeGraph>("Graph type set to '{0}'", GraphType.GetType().ToString()); } else { GraphType = _defaultGraphType; NodeEditor.Logger.Log <NodeGraph>("Graph type invalid. Setting to default."); } } graphData.Variables.ForEach(variable => AddVariable(variable)); graphData.Nodes.ForEach(x => AddNode(x)); graphData.Constants.ForEach(x => AddNodeConstant(x)); graphData.VariableNodes.ForEach(x => AddNodeVariable(x)); graphData.Connections.ForEach(connectionData => Connect(connectionData)); if (PostLoad != null) { PostLoad.Invoke(this, graphData); } }
public void SetDefaultGraphType <T>(T graphType) where T : NodeGraphType { _defaultGraphType = graphType; }