Exemplo n.º 1
0
        public static VisualPort Create(PortDescription description, IEdgeConnectorListener connectorListener)
        {
            var port = new VisualPort(Orientation.Horizontal,
                                      description.IsInputSlot ? Direction.Input : Direction.Output,
                                      description.AllowMultipleConnections ? Capacity.Multi : Capacity.Single,
                                      null)
            {
                m_EdgeConnector = new EdgeConnector <Edge>(connectorListener)
            };

            port.AddManipulator(port.m_EdgeConnector);
            port.PortDescription = description;
            port.visualClass     = "type" + port.PortDescription.PortType.Name;
            port.m_portGraphics.AddToClassList("type" + port.PortDescription.PortType.Name);
            return(port);
        }
Exemplo n.º 2
0
        private void LoadRequested()
        {
            string path = EditorUtility.OpenFilePanel("Load Graph", "Assets/", "asset");

            if (path.Length == 0)
            {
                Debug.Log("Canceled Load.");
                return;
            }

            //  Clear current graph visually
            m_graphView.DeleteElements(m_graphView.edges.ToList());
            m_graphView.DeleteElements(m_graphView.nodes.ToList());

            path = "Assets" + path.Substring(Application.dataPath.Length);

            var graph = AssetDatabase.LoadAssetAtPath <SerializedGraph>(path);

            if (graph == null)
            {
                Debug.LogError("Failed to load graph!");
                return;
            }

            m_graph = graph;


            for (int i = 0; i < graph.Nodes.Count; i++)
            {
                var node = m_searchWindowProvider.CreateNode(graph.Nodes[i]);
                AddNode(node, node.name, true);
            }

            var nodes = m_graphView.nodes.ToList();

            for (int i = 0; i < graph.Edges.Count; i++)
            {
                var serializedEdge = graph.Edges[i];

                VisualPort from = null;
                VisualPort to   = null;

                foreach (var node in nodes)
                {
                    GraphNode vNode = (GraphNode)node;

                    if (vNode.NodeGuid == serializedEdge.SourceNodeGUID)
                    {
                        from = vNode.FindSlot <PortDescription>(serializedEdge.SourcePortMemberName).VisualPort;
                    }

                    if (vNode.NodeGuid == serializedEdge.TargetNodeGUID)
                    {
                        to = vNode.FindSlot <PortDescription>(serializedEdge.TargetPortMemberName).VisualPort;
                    }
                }

                if (from == null)
                {
                    Debug.LogError("Could not find From port!");
                }
                if (to == null)
                {
                    Debug.LogError("Could not find To port!");
                }

                if (from != null && to != null)
                {
                    var edge = from.ConnectTo(to);
                    AddEdgeLoad(edge, true);
                }
            }
        }