public static NodeGraphData GetGraphData(NodeGraph graph) { NodeEditor.Logger.Log <NodeGraphState>("Serializing graph state..."); var outGraphData = new NodeGraphData(); outGraphData.GraphType = graph.GraphType.GetType().ToString(); // TODO: Find a nicer way to do this... graph.Nodes.ForEach(node => { if (node.GetType() == typeof(NodeConstant)) { outGraphData.Constants.Add(NodeConstantData.Convert(node as NodeConstant)); } else if (node.GetType() == typeof(NodeVariable)) { outGraphData.VariableNodes.Add(NodeVariableData.Convert(node as NodeVariable)); } else { outGraphData.Nodes.Add(NodeData.Convert(node)); } }); graph.Connections.ForEach(connection => outGraphData.Connections.Add(NodeConnectionData.Convert(connection))); graph.Variables.ForEach(variable => outGraphData.Variables.Add(NodeGraphVariableData.Convert(variable))); return(outGraphData); }
NodeVariable AddNodeVariable(NodeVariableData nodeVariableData) { var foundVariable = Variables.Find(x => x.ID == nodeVariableData.VariableID); NodeEditor.Assertions.WarnIsNotNull(foundVariable, string.Format("The specified variable ({0}) does not exist in the graph.", nodeVariableData.VariableID)); var nodeInstance = AddNode(nodeVariableData) as NodeVariable; nodeInstance.Set(foundVariable, nodeVariableData.AccessorType); return(nodeInstance); }
public NodeVariable AddNodeVariable(AddNodeVariableArgs addNodeVariableArgs) { var variableData = new NodeVariableData(addNodeVariableArgs.Variable, addNodeVariableArgs.AccessorType, GetNewGuid()); var node = CreateNodeInstance(typeof(NodeVariable)) as NodeVariable; node.Initialize(variableData); node.Set(addNodeVariableArgs.Variable, addNodeVariableArgs.AccessorType); return(node); }
public static NodeVariableData Convert(NodeVariable nodeVariable) { var nodeData = NodeData.Convert(nodeVariable); var variableData = new NodeVariableData() { ClassType = nodeData.ClassType, Name = nodeData.Name, ID = nodeData.ID, Position = nodeData.Position, VariableID = nodeVariable.VariableID, AccessorType = nodeVariable.AccessorType, }; return(variableData); }