// Check for a new path on move request
    public IEnumerator UpdateThreadPath()
    {
        // Avoid the first frame spike when the game is first started, so that if we have any moving units, they are not effected by this.
        if (Time.timeSinceLevelLoad < .3f)
        {
            yield return(PathfindingRequestManager.WaitPathUpdatePeriod);
        }
        // Request the path calculation for unit movement with the specific struct
        PathfindingRequestManager.RequestThreadPath(new PathRequestData(transform.position, MoveTarget, null, OnPathFound));
        // If our soldier can track objects and we are using a target object's dynamic position as the MoveTarget rather than a solid node position.
        if (CanTrack)
        {
            // Squared distance comparison is faster for the path request move threshold ( In-case our move target moves, like following some object)
            float   sqrMoveThreshold  = PathfindingRequestManager.PathUpdateMoveThreshold * PathfindingRequestManager.PathUpdateMoveThreshold;
            Vector2 lastPathTargetPos = MoveTarget;
            while (true)
            {
                // Avoid running every frame, just calculate once every decided path update periods
                yield return(PathfindingRequestManager.WaitPathUpdatePeriod);

                // Move target has moved more than the specified threshold
                if ((MoveTarget - lastPathTargetPos).sqrMagnitude > sqrMoveThreshold)
                {
                    PathfindingRequestManager.RequestThreadPath(new PathRequestData(transform.position, MoveTarget, null, OnPathFound));
                    lastPathTargetPos = MoveTarget;
                }
            }
        }
    }
Beispiel #2
0
 //
 void Awake()
 {
     if (_instance == null)
     {
         _instance = this;
     }
     _pathFindingManager = GetComponent <PathfindingManager>();
 }
Beispiel #3
0
 //
 public static PathfindingRequestManager GetInstance()
 {
     // Uses lazy initialization.
     if (_instance == null)
     {
         _instance = new PathfindingRequestManager();
     }
     return(_instance);
 }