Exemplo n.º 1
0
    public virtual bool LoadGraphData(string inputPath)
    {
        SerializableGraphData graphData = AssetDatabase.LoadAssetAtPath <SerializableGraphData>(inputPath);

        if (graphData == null)
        {
            return(false);
        }

        // create the nodes
        List <Node> createdNodes = new List <Node>();

        for (int i = 0; i < graphData.m_graphNodes.Count; ++i)
        {
            Node node = DeserializeNode(graphData.m_graphNodes[i]);
            createdNodes.Add(node);
            m_GraphView.AddElement(node);
        }

        //connect the nodes
        for (int i = 0; i < graphData.m_graphNodes.Count; ++i)
        {
            for (int iEdge = 0; iEdge < graphData.m_graphNodes[i].m_outputs.Count; ++iEdge)
            {
                SerializableGraphData.SerializableGraphEdge edge = graphData.m_graphNodes[i].m_outputs[iEdge];
                Port outputPort = createdNodes[i].outputContainer[edge.m_sourcePort] as Port;
                Port inputPort  = createdNodes[edge.m_targetNode].inputContainer[edge.m_targetPort] as Port;
                m_GraphView.AddElement(outputPort.ConnectTo(inputPort));
            }
        }

        return(true);
    }
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();
    }