public void GeneratePathToPosition(Vector3 pos, OnPathfindingArrival onArrival)
    {
        OnPathFound = OnIndoorPathFound;
        Vector3 pos_ = new Vector3(pos.x, customer.modelHeight, pos.z);

        DispensaryPathRequestManager.RequestPath(customer.dm.dispensary.grid, transform.position, pos, OnPathFound);
        SetOnArrival(onArrival);
    }
예제 #2
0
    public void GeneratePathToPosition(Vector3 pos, OnPathfindingArrival onArrival)
    {
        Func <Vector3[], bool, Vector3[]> getPath = OnPathFound_ToPosition;
        Vector3 pos_ = new Vector3(pos.x, staff.modelHeight, pos.z);

        DispensaryPathRequestManager.RequestPath(staff.dm.dispensary.grid, transform.position, pos, getPath);
        SetOnArrival(onArrival);
    }
 public void GetOutdoorPath(Vector3 pos, OnPathfindingArrival onArrival)
 {
     if (outdoorGrid == null)
     {
         outdoorGrid = GameObject.Find("OutdoorPlane").GetComponent <OutdoorGrid>();
     }
     outdoorTargetNode = outdoorGrid.NodeFromWorldPoint(pos);
     OutdoorPathRequestManager.RequestPath(transform.position, pos, OnOutdoorPathFound);
     SetOnArrival(onArrival);
 }
    IEnumerator FollowIndoorPath()
    {
        Vector3 currentWaypoint = Vector3.zero;

        try
        {
            followingIndoorPath = true;
            currentWaypoint     = path[0];
            targetIndex         = 0;
        }
        catch (IndexOutOfRangeException)
        {
            yield break;             // Ends the coroutine;
        }
        while (true)
        { // While loop runs constantly without freezing game because its inside a coroutine and yields each frame
            #region TestMovementMethod
            if (useRaycasting)
            {
                try
                {
                    int forCount = 0;
                    for (int i = targetIndex; i < path.Length; i++)
                    {
                        Vector3    dir      = (transform.position - path[i]).normalized;
                        float      distance = Vector3.Distance(transform.position, path[i]);
                        Ray        ray      = new Ray(path[i], dir);
                        RaycastHit hit;
                        Debug.DrawRay(ray.origin + new Vector3(0, .5f, 0), ray.direction * distance);
                        if (!Physics.Raycast(ray.origin + new Vector3(0, .5f, 0), ray.direction * distance, out hit, distance))                       // Raise the ray to y = .5 so the ray can hit obstacles
                        {
                            //print ("Not hitting anything (" + i + ")");
                            forCount++;
                            continue;
                        }
                        else
                        {
                            if (hit.transform.gameObject.layer == 9)                             // 9 is the unwalkable layer
                            {
                                //print ("Hitting something when testing next waypoint! (" + i + ")" + "\n" + hit.transform.name);
                                int temp = i - 1;
                                currentWaypoint = path[temp];
                                targetIndex     = temp;
                                break;
                            }
                        }
                        if (i == path.Length - 1)                       // Clear shot to target
                        {
                            int temp = path.Length;
                            currentWaypoint = path [path.Length - 1];
                            targetIndex     = path.Length - 1;
                        }
                    }
                }
                catch (IndexOutOfRangeException)
                {
                    print("Following path using raycasting simplification method has failed");
                }
            }
            #endregion // Tries to navigate paths by cutting corners
            if (transform.position == currentWaypoint)
            {
                targetIndex++;
                if (targetIndex >= path.Length)
                {
                    // End of the path reached
                    followingIndoorPath = false;
                    path = null;
                    if (currentAction == CustomerAction.leavingStore)
                    {
                        outside   = true;
                        leftStore = true;
                        GeneratePathToSidewalkEnd();
                    }
                    if (currentAction == CustomerAction.goingToComponent)
                    {
                    }
                    if (OnArrival != null)
                    {
                        OnArrival.Invoke();
                        OnArrival = null;
                    }
                    yield break;                     // Ends the coroutine
                }
                currentWaypoint = path[targetIndex];
            }
            float customerSpeed = 0;
            customerSpeed      = (currentAction == CustomerAction.wandering) ? wanderingSpeed : speed;
            currentWaypoint    = new Vector3(currentWaypoint.x, .5f, currentWaypoint.z);
            transform.position = Vector3.MoveTowards(transform.position, currentWaypoint, customerSpeed * Time.deltaTime);
            yield return(null);
        }
    }
 public void SetOnArrival(OnPathfindingArrival del)
 {
     OnArrival = del;
 }