Exemplo n.º 1
0
    public virtual void FindPath(ref Conveyance currentConveyance, ref List <Destination> destinations)
    {
        //Debug.Break();

        //get walking path distance
        Vector3 guestPosition       = transform.position;
        Vector3 destinationPosition = Destination.transform.position;
        float   distance            = AgentWalkDistance(_agent, transform, guestPosition, destinationPosition, Color.yellow);

        //test all conveyances
        currentConveyance = null;
        Conveyance[] conveyances = GameObject.FindObjectsOfType <Conveyance>();
        foreach (Conveyance c in conveyances)
        {
            //guard statement,
            if (c.IsFull())
            {
                continue;             //how many people are on the conveyance
            }
            if (!c.IsConveyanceActive())
            {
                continue;                          //is conveyance active
            }
            float distToC   = AgentWalkDistance(_agent, transform, guestPosition, c.StartPosition(guestPosition, this), Color.green);
            float distC     = c.WeightedTravelDistance(guestPosition, destinationPosition, this);
            float distFromC = AgentWalkDistance(_agent, transform, c.EndPosition(destinationPosition, this), destinationPosition, Color.red);

            //Debug.DrawLine(guestPosition, c.StartPosition(), Color.black);
            Debug.DrawLine(c.StartPosition(guestPosition, this), c.EndPosition(destinationPosition, this), Color.cyan);
            //Debug.DrawLine(c.EndPosition(), destinationPosition, Color.white);

            if (distance > distToC + distC + distFromC)
            {
                currentConveyance = c;
                distance          = distToC + distC + distFromC;
            }
        }

        //if there are no conveyances, we update the destination list with current destination
        if (currentConveyance == null)
        {
            destinations.Clear();
            destinations.Add(Destination);
            UpdateDestination();
            return;
        }

        //update destinations
        if (currentConveyance.GetType() == typeof(Vehicle))
        {
            Vehicle vehicle = _currentConveyance as Vehicle;
            vehicle.SetWaiting(this);
        }

        destinations.Clear();
        destinations.Add(currentConveyance.GetDestination(guestPosition, this));
        destinations.Add(Destination);
        Destination = destinations[0];
        UpdateDestination();
    }
Exemplo n.º 2
0
    public void FindPath()
    {
        //get walking path distance
        Vector3 guestPosition       = transform.position;
        Vector3 destinationPosition = Destination.transform.position;
        float   distance            = AgentWalkDistance(guestPosition, destinationPosition, Color.magenta);

        //Debug.Break();

        //test all conveyances
        _currentConveyance = null;
        Conveyance[] conveyances = GameObject.FindObjectsOfType <Conveyance>();
        foreach (Conveyance c in conveyances)
        {
            float distToC   = AgentWalkDistance(guestPosition, c.StartPosition(), Color.green);
            float distC     = c.WeightedTravelDistance();
            float distFromC = AgentWalkDistance(c.EndPosition(), destinationPosition, Color.red);

            Debug.DrawLine(guestPosition, c.StartPosition(), Color.cyan);
            Debug.DrawLine(c.StartPosition(), c.EndPosition(), Color.cyan);
            Debug.DrawLine(c.EndPosition(), destinationPosition, Color.cyan);

            if (distance > distToC + distC + distFromC)
            {
                _currentConveyance = c;
                distance           = distToC + distC + distFromC;
            }
        }

        //if there are no conveyances, we update the destination list with current destination
        //Zixuan.Gong:Refactor repeated Lines for Extra Credits.(Also Line 67 is not needed)
        _destinations.Clear();

        if (_currentConveyance == null)
        {
            _destinations.Add(Destination);
        }
        else
        {
            _destinations.Add(_currentConveyance.GetDestination());
            _destinations.Add(Destination);
            Destination = _destinations[0];
        }
        //update destinations
        UpdateDestination();
    }
Exemplo n.º 3
0
    public void FindPath()
    {
        //get walking path distance
        Vector3 guestPosition       = transform.position;
        Vector3 destinationPosition = Destination.transform.position;
        float   distance            = AgentWalkDistance(guestPosition, destinationPosition, Color.magenta);

        Debug.Break();

        //test all conveyances
        _currentConveyance = null;
        Conveyance[] conveyances = GameObject.FindObjectsOfType <Conveyance>();
        foreach (Conveyance c in conveyances)
        {
            float distToC   = AgentWalkDistance(guestPosition, c.StartPosition(), Color.green);
            float distC     = c.WeightedTravelDistance();
            float distFromC = AgentWalkDistance(c.EndPosition(), destinationPosition, Color.red);

            Debug.DrawLine(guestPosition, c.StartPosition(), Color.cyan);
            Debug.DrawLine(c.StartPosition(), c.EndPosition(), Color.cyan);
            Debug.DrawLine(c.EndPosition(), destinationPosition, Color.cyan);

            if (distance > distToC + distC + distFromC)
            {
                _currentConveyance = c;
                distance           = distToC + distC + distFromC;
            }
        }

        if (_currentConveyance == null)
        {
            UpdateDestination(); return;
        }

        //update destinations
        _destinations.Clear();
        _destinations.Add(_currentConveyance.GetDestination());
        _destinations.Add(Destination);
        Destination = _destinations[0];
        UpdateDestination();
    }
Exemplo n.º 4
0
    public void FindPath()
    {
        NavMeshPath navMeshPath = _agent.path;

        if (!_agent.CalculatePath(Destination.transform.position, navMeshPath))
        {
            return;
        }

        Vector3[] path = navMeshPath.corners;
        if (path.Length < 2)
        {
            return;
        }

        //get walking path distance
        float distance = 0;

        for (int i = 1; i < path.Length; i++)
        {
            distance += Vector3.Distance(path[i - 1], path[i]);
            Debug.DrawLine(path[i - 1], path[i], Color.red);
        }
        Debug.Break();
        //code below break still runs

        //test all conveyances
        _currentConveyance = null;
        Vector3 guestPosition       = transform.position;
        Vector3 destinationPosition = Destination.transform.position;

        Conveyance[] conveyances = GameObject.FindObjectsOfType <Conveyance>();
        foreach (Conveyance c in conveyances)
        {
            float distToC   = Vector3.Distance(guestPosition, c.StartPosition());
            float distC     = c.WeightedTravelDistance();
            float distFromC = Vector3.Distance(c.EndPosition(), destinationPosition);

            Debug.DrawLine(guestPosition, c.StartPosition(), Color.cyan);
            Debug.DrawLine(c.StartPosition(), c.EndPosition(), Color.cyan);
            Debug.DrawLine(c.EndPosition(), destinationPosition, Color.cyan);

            if (distance > distToC + distC + distFromC)
            {
                _currentConveyance = c;
                distance           = distToC + distC + distFromC;
            }
        }

        if (_currentConveyance == null)
        {
            UpdateDestination(); return;
        }

        //update destinations
        _destinations.Clear();
        _destinations.Add(_currentConveyance.GetDestination());
        _destinations.Add(Destination);
        Destination = _destinations[0];
        UpdateDestination();
    }