Beispiel #1
0
 public PathEdge(
     Vector2 source,
     Vector2 destination,
     Node fromNode,
     Node toNode,
     Edge edge,
     PathManager pathManager,
     GameObject movingObject)
 {
     Source = source;
     Destination = destination;
     FromNode = fromNode;
     ToNode = toNode;
     Edge = edge;
     PathManager = pathManager;
     MovingObject = movingObject;
     MovingEntity = movingObject.GetComponent<MovingEntity>();
 }
Beispiel #2
0
        /// <summary>
        /// Use this to add an edge to the graph. The method will ensure that the edge passed as a
        /// parameter is valid before adding it to the graph. If the graph is a digraph then a
        /// similar edge connecting the nodes in the opposite direction will be automatically added.
        /// </summary>
        /// <param name="edge">The edge.</param>
        public void AddEdge(Edge edge)
        {
            // first make sure the from and to nodes exist within the graph
            if (edge.From >= NextNodeIndex || edge.To >= NextNodeIndex)
            {
                Debug.LogError("SparseGraph.AddEdge: invalid node index.");
                throw new System.Exception("SparseGraph.AddEdge: invalid node index.");
            }

            // make sure both nodes are active before adding the edge
            if (Node.IsInvalidIndex(Nodes[edge.To].Index) ||
                Node.IsInvalidIndex(Nodes[edge.From].Index))
            {
                return;
            }

            // add the edge, first making sure it is unique
            if (UniqueEdge(edge.From, edge.To))
            {
                Edges[edge.From].AddLast(edge);
            }

            // if the graph is undirected we must add another connection
            // in the opposite direction
            if (IsDigraph)
            {
                return;
            }

            // check to make sure the edge is unique before adding
            if (!UniqueEdge(edge.To, edge.From))
            {
                return;
            }

            var newEdge = new Edge(edge) { To = edge.From, From = edge.To };
            Edges[edge.To].AddLast(newEdge);
        }
Beispiel #3
0
 public Edge(Edge src)
     : this(src.From,
         src.To,
         src.Cost)
 {
 }