Пример #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
    private void InitAStarManager()
    {
        /// Get all waypoints in the active scene
        GameObject[] allWaypoints = GameObject.FindGameObjectsWithTag("Waypoint");
        foreach (GameObject waypoint in allWaypoints)
        {
            WaypointCON tempCon = waypoint.GetComponent <WaypointCON>();
            if (tempCon)
            {
                m_allWaypoints.Add(waypoint);
            }
        }

        /// Add connections from waypoints into the AStarManager
        foreach (GameObject waypoint in m_allWaypoints)
        {
            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);
            }
        }
    }
Пример #3
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);
 }
Пример #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;
        }
    }