Exemplo n.º 1
0
    Node DeserializeNode(SerializableGraphData.SerializableGraphNode graphNode)
    {
        Node node = graphNode.m_title == "Start" ? CreateRootNode() : CreateNode(graphNode.m_title, 1, 1);

        node.SetPosition(new Rect(graphNode.m_position, Vector2.zero));
        return(node);
    }
Exemplo n.º 2
0
    public virtual void SaveGraphData(List <Node> nodes, string outputPath)
    {
        SerializableGraphData graphData = ScriptableObject.CreateInstance <SerializableGraphData>();

        graphData.m_graphNodes = new List <SerializableGraphData.SerializableGraphNode>();
        for (int i = 0; i < nodes.Count; ++i)
        {
            SerializableGraphData.SerializableGraphNode graphNode = new SerializableGraphData.SerializableGraphNode();
            Node currentNode = nodes[i];

            graphNode.m_title    = currentNode.title;
            graphNode.m_position = currentNode.GetPosition().position;
            graphNode.m_outputs  = new List <SerializableGraphData.SerializableGraphEdge>();

            foreach (Port port in currentNode.outputContainer)
            {
                foreach (Edge edge in port.connections)
                {
                    SerializableGraphData.SerializableGraphEdge serializedEdge = new SerializableGraphData.SerializableGraphEdge();
                    serializedEdge.m_sourcePort = currentNode.outputContainer.IndexOf(edge.output);
                    serializedEdge.m_targetNode = nodes.IndexOf(edge.input.node);
                    serializedEdge.m_targetPort = edge.input.node.inputContainer.IndexOf(edge.input);
                    graphNode.m_outputs.Add(serializedEdge);
                }
            }
            graphData.m_graphNodes.Add(graphNode);
        }

        AssetDatabase.CreateAsset(graphData, outputPath);
        AssetDatabase.SaveAssets();
    }