コード例 #1
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);
            }
        }
    }
コード例 #2
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);
    }
コード例 #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;
        }
    }
コード例 #5
0
    // Start is called before the first frame update
    void Start()
    {
        InitialiseText();
        myTaxi = this.gameObject;
        Application.targetFrameRate = 120;
        old_position = transform.position;
        myTaxi.transform.position = start.transform.position;



        // 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);
            }
        }

        GameObject randomNode;

        randomNode = RandomSeed();


        for (int i = 0; i < NumberToSpawn; i++)
        {
            myPassengers.Add(Instantiate(PersonPrefab, randomNode.transform.position - new Vector3(-3.0f + i, 0f, -3.0f), Quaternion.identity));
            myPassengers[i].gameObject.tag  = "Passenger";
            myPassengers[i].gameObject.name = myTaxi.name + " Passenger " + (i + 1);
        }


        end = randomNode;
        Debug.Log(myTaxi.name + " is collecting " + myPassengers.Count + " passengers from " + end.name);    // THIS WORKS



        if (start == null || end == null)
        {
            Debug.Log("No start or end waypoints.");
            return;
        }

        // 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(start, end);
    }