Пример #1
0
    void ReturnToStart()
    {
        Debug.Log(myTaxi.name + " is delivering.");
        returning = true;


        // Go through the waypoints and create connections.
        foreach (GameObject waypoint in Waypoints)
        {
            WaypointCON tmpWaypointCon = waypoint.GetComponent <WaypointCON>();
            // Loop through a waypoints connections.
            foreach (GameObject WaypointConNode in tmpWaypointCon.Connections)
            {
                Connection aConnection = new Connection
                {
                    FromNode = waypoint,
                    ToNode   = WaypointConNode
                };
                AStarManager.AddConnection(aConnection);
            }
        }
        // Run A Star...
        // ConnectionArray stores all the connections in the route to the goal / end node.
        ConnectionArray = AStarManager.PathfindAStar(end, start);
    }
Пример #2
0
 // Start is called before the first frame update
 void Start()
 {
     if (start == null || end == null)
     {
         Debug.Log("No start or end waypoints.");
         return;
     }
     // Find all the waypoints in the level.
     GameObject[] GameObjectsWithWaypointTag;
     GameObjectsWithWaypointTag = GameObject.FindGameObjectsWithTag("Waypoint");
     foreach (GameObject waypoint in GameObjectsWithWaypointTag)
     {
         WaypointCON tmpWaypointCon = waypoint.GetComponent <WaypointCON>();
         if (tmpWaypointCon)
         {
             Waypoints.Add(waypoint);
         }
     }
     // Go through the waypoints and create connections.
     foreach (GameObject waypoint in Waypoints)
     {
         WaypointCON tmpWaypointCon = waypoint.GetComponent <WaypointCON>();
         // Loop through a waypoints connections.
         foreach (GameObject WaypointConNode in tmpWaypointCon.Connections)
         {
             Connection aConnection = new Connection();
             aConnection.FromNode = waypoint;
             aConnection.ToNode   = WaypointConNode;
             AStarManager.AddConnection(aConnection);
         }
     }
     // Run A Star...
     // ConnectionArray stores all the connections in the route to the goal / end node.
     ConnectionArray = AStarManager.PathfindAStar(start, end);
 }
Пример #3
0
    /// <summary>
    /// Navigates using AStar from a start Waypoint GameObject to an End Waypoint GameObject
    /// and stores the waypoint path in m_destinationPath
    /// </summary>
    /// <param name="start">The start waypoint gameobject</param>
    /// <param name="end">The end waypoint gameobject</param>
    /// <returns>If the AStar path was able to determine a path</returns>
    protected List <Connection> NavigateAStar(GameObject start, GameObject end)
    {
        /// Validate start and end are legit
        if (start == null || end == null)
        {
            return(null);
        }

        /// Pathfind from start to end and check connection path is valid
        List <Connection> connectionPath = m_astarManager.PathfindAStar(start, end);

        if (connectionPath == null || connectionPath != null && connectionPath.Count <= 0)
        {
            return(null);
        }

        /// Set destination array and return true
        //m_destinationPath = connectionPath;
        return(connectionPath);
    }
Пример #4
0
    private void Start()
    {
        if (m_start == null || m_end == null)
        {
            Debug.Log("No start or end waypoints");
            return;
        }

        GameObject[] goWithWaypointTags = GameObject.FindGameObjectsWithTag("Waypoint");

        foreach (GameObject waypoint in goWithWaypointTags)
        {
            WaypointCON tempCon = waypoint.GetComponent <WaypointCON>();
            if (tempCon)
            {
                m_waypoints.Add(waypoint);
            }
        }

        foreach (GameObject waypoint in m_waypoints)
        {
            WaypointCON tempCon = waypoint.GetComponent <WaypointCON>();
            foreach (GameObject waypointConNode in tempCon.Connections)
            {
                Connection aConnection = new Connection();
                aConnection.FromNode = waypoint;
                aConnection.ToNode   = waypointConNode;

                m_aStarManager.AddConnection(aConnection);
            }
        }

        m_connectionArray = m_aStarManager.PathfindAStar(m_start, m_end);

        // If no target node set, set initial position and target position
        if (m_currentTargetNode == null)
        {
            m_currentTargetNode     = m_connectionArray[m_currentTargetNodeIndex].ToNode;
            this.transform.position = m_currentTargetNode.transform.position;
        }
    }