Ejemplo n.º 1
0
        //Create Data from Object
        public static NodeGraphData CreateData(NodeGraph graph)
        {
            NodeGraphData graphData = new NodeGraphData();
            graphData.Name = graph.Name;
            graphData.scrollPos = graph.scrollPos;

            for (int i = 0; i < graph.nodes.Count; i++)
            {
                NodeData nData = new NodeData();
                nData.NodeType = graph.nodes[i].GetNodeType;
                nData.NodeID = graph.nodes[i].ID;
                nData.properties.CopyPropertiesDataFrom(graph.nodes[i].properties);
                nData.NodePos = new Vector2(graph.nodes[i].rect.x, graph.nodes[i].rect.y);

                var connections = graph.nodes[i].GetAllConnections();
                for (int n = 0; n < connections.Length; n++)
                {
                    ConnectionData cData = new ConnectionData();
                    cData.OutNodeID = connections[n].startSocket.parentNode.ID;
                    cData.OutNodeSocketID = connections[n].startSocket.ID;
                    cData.InNodeID = connections[n].endSocket.parentNode.ID;
                    cData.InNodeSocketID = connections[n].endSocket.ID;

                    if (graphData.connections != null)
                    {
                        int index = graphData.connections.FindIndex(item => item.ID == cData.ID);
                        if (index == -1)
                            graphData.connections.Add(cData);
                    }
                }

                graphData.nodes.Add(nData);
            }

            return graphData;
        }