Пример #1
0
        /// <summary>
        /// fetches pathnode data from the scene and constructs the levelgraph 
        /// </summary>
        public static void SetupGraph(GraphData data)
        {
            graph = new Graph();
            if(data.hasContent())
            {
                //	create nodes
                var nodes = data.nodes.Select((graphNode n)=> {
                    Node node = new Node();
                    node.pos = n.position;
                    node.ID = n.ID;
                    return node;
                })
                .ToList();

                //	create edges
                var edges = data.edges.Select((graphConnection c)=> {

                    Node a = nodes.Find(x=> x.ID==c.A);
                    Node b = nodes.Find(x=> x.ID==c.B);
                    if(a == null || b == null)
                    {
                        throw new System.Exception("could not load edge, wrong IDs stored: "
                                                   + c.A + " / " + c.B + " nodecount: " + nodes.Count);
                    }

                    if(!c.supressed
                       && (c.forced || GetEdgeCost(a, b) <= data.autoConnectionDist))
                    {
                        Edge e = new Edge(a, b, c.dir, GetEdgeCost(a, b));
                        a.AdjacentEdges.Add(e);
                        b.AdjacentEdges.Add(e);
                        return e;
                    }
                    else
                        return null;
                })
                .Where(z=> z != null)
                .ToList();

                //	create graph
                graph.Nodes = nodes;
                graph.Edges = edges;

                Debug.Log(graph.PrintEdges());

            }
            else
            {
                throw new System.Exception("could not load graph; Graphdata is empty.");
            }
        }
 public bool Compare( Edge edge )
 {
     return (edge.A == A && edge.B == B )
             || (edge.A == B  && edge.B == A );
 }