Example #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>();
 }
Example #2
0
        /// <summary>
        /// Given a node this method first checks to see if the node has been added previously but
        /// is now inactive. If it is, it is reactivated.
        /// 
        /// If the node has not been added previously, it is checked to make sure its index matches
        /// the next node index before being added to the graph.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <returns>The node index.</returns>
        public int AddNode(Node node)
        {
            if (node.Index < Nodes.Count)
            {
                // make sure the client is not trying to add a node with the same
                // Id as a currently active node
                if (!Node.IsInvalidIndex(Nodes[node.Index].Index))
                {
                    Debug.LogError(
                        "SparseGraph.AddNode: Attempting to add a node with a duplicate Id.");
                    throw new System.Exception(
                        "SparseGraph.AddNode: Attempting to add a node with a duplicate Id.");
                }

                Nodes[node.Index] = node;

                return NextNodeIndex;
            }

            // make sure the new node has been indexed correctly
            if (node.Index != NextNodeIndex)
            {
                Debug.LogError("SparseGraph.AddNode: invalid index.");
                throw new System.Exception("SparseGraph.AddNode: invalid index.");
            }

            Nodes.Add(node);
            Edges.Add(new LinkedList<Edge>());

            return NextNodeIndex++;
        }