void Start()
        {
            // create the graph
            Graph.Graph graph = new Graph.Graph();

            // create an operator node
            var operator01 = (NumberOperatorNode)graph.CreateNode <NumberOperatorNode>();

            operator01.X = 200;
            operator01.Y = 40;
            operator01.SetMode(Operator.Add);
            graph.AddNode(operator01);

            // create a display node
            var diplay01 = (NumberDisplayNode)graph.CreateNode <NumberDisplayNode>();

            diplay01.X = 330;
            diplay01.Y = 80;
            graph.AddNode(diplay01);

            // link the nodes
            graph.Link(
                (InputSocket)diplay01.GetSocket(typeof(INumberConnection), typeof(InputSocket), 0),
                (OutputSocket)operator01.GetSocket(typeof(INumberConnection), typeof(OutputSocket), 0));

            // cerate a perlin noise node
            var perlinNoise = graph.CreateNode <UnityPerlinNoiseNode>();

            perlinNoise.X = 80;
            perlinNoise.Y = 250;
            graph.AddNode(perlinNoise);

            // create a display map node
            var displayMap = graph.CreateNode <DisplayMapNode>();

            displayMap.X = 300;
            displayMap.Y = 280;
            graph.AddNode(displayMap);

            // link the nodes
            graph.Link(
                (InputSocket)displayMap.GetSocket(typeof(INumberConnection), typeof(InputSocket), 0),
                (OutputSocket)perlinNoise.GetSocket(typeof(INumberConnection), typeof(OutputSocket), 0));


            // to test the serialization...

            // create a json out of the graph
            var serializedJSON = graph.ToJson();
            // dezeiralize the json back to a graph
            var deserializedGraph = Graph.Graph.FromJson(serializedJSON);

            // add the graph to the launcher to see it in the editor.
            Launcher.Instance.AddGraph(deserializedGraph);
        }
示例#2
0
        /// <summary>
        /// Implementation of a BFS algorithm for a given starting node.
        /// This doesn't work with a destination node, but rather returns
        /// the whole "reachability graph".
        /// </summary>
        /// <param name="startingNode">The node from which to get the reachability graph</param>
        /// <returns>The reachability graph from the node given</returns>
        private Graph.Graph Bfs(INode startingNode)
        {
            var visited = new Dictionary <INode, bool>();
            var queue   = new Queue <INode>();

            visited[startingNode] = true;

            var graph = new Graph.Graph();

            queue.Enqueue(startingNode);

            while (queue.Count > 0)
            {
                var node = queue.Dequeue();
                graph.AddNode(node);
                graph.AddEdges(node.GetOutwardsEdges());

                foreach (var child in node.GetChilds())
                {
                    if (child == null)
                    {
                        continue;
                    }

                    if (visited.ContainsKey(child))
                    {
                        continue;
                    }
                    queue.Enqueue(child);
                    visited[child] = true;
                }
            }

            return(graph);
        }