예제 #1
0
        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);
        }
        public NodeGraphVariable(NodeGraphVariableData data)
        {
            Name = data.Name;
            ID   = data.ID;

            SetValueWrapperFromType(Type.GetType(data.VariableType));
            WrappedValue.SetFromString(data.Value);
        }
예제 #3
0
        NodeGraphVariable AddVariable(NodeGraphVariableData graphVariableData)
        {
            NodeEditor.Assertions.IsFalse(Variables.Any(x => x.ID == graphVariableData.ID), "Tried to spawn a variable that has the same ID as an existing variable.");

            var variable = new NodeGraphVariable(graphVariableData);

            variable.NameChangeRequested += Variable_NameChangeRequested;
            Variables.Add(variable);

            NodeEditor.Logger.Log <NodeGraph>("Added variable '{0}' ({1})", variable.Name, variable.GetType());

            VariableAdded.InvokeSafe(variable);
            Edited.InvokeSafe(this);

            return(variable);
        }