public static NodeConstantData Convert(NodeConstant constant)
        {
            // Convert base node data.
            var nodeData = NodeData.Convert(constant);

            var constantData = new NodeConstantData()
            {
                ClassType    = nodeData.ClassType,
                Name         = nodeData.Name,
                ID           = nodeData.ID,
                Position     = nodeData.Position,
                ConstantType = constant.ValueWrapper.ValueType.ToString(),
                Value        = constant.ValueWrapper.ToString(),
            };

            //switch (constant.PinType)
            //{
            //    case NodeConstantType.None: constantData.Value = string.Empty; break;
            //    case NodeConstantType.Float: constantData.Value = constant.GetFloat().ToString(); break;
            //    case NodeConstantType.Int: constantData.Value = constant.GetInt().ToString(); break;
            //    case NodeConstantType.Bool: constantData.Value = constant.GetBool().ToString(); break;
            //    case NodeConstantType.String: constantData.Value = constant.GetString(); break;
            //};

            return(constantData);
        }
Exemple #2
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);
        }
        NodeConstant AddNodeConstant(NodeConstantData nodeConstantData)
        {
            var nodeInstance = AddNode(nodeConstantData) as NodeConstant;

            nodeInstance.Set(nodeConstantData);
            return(nodeInstance);
        }
        public void Set(NodeConstantData nodeConstantData)
        {
            var constantType = Type.GetType(nodeConstantData.ConstantType);

            SetType(Type.GetType(nodeConstantData.ConstantType));
            ValueWrapper.SetFromString(nodeConstantData.Value);
        }