Exemple #1
0
 public static void FindNearestOutpost(Vector3 unitPosition, Action<Outpost> callBack)
 {
     FindNearestOutpostQueryRequest request = new FindNearestOutpostQueryRequest() { location = unitPosition, CallBack = callBack };
     Instance.FindNearestOutpostQueryQueue.Enqueue(request);
     Instance.TryProcessNextFindOutpost();
 }
Exemple #2
0
 IEnumerator QueryOutpost(FindNearestOutpostQueryRequest request)
 {
     var outposts = FindObjectsOfType<Outpost>();
     if (outposts != null)
     {
         float minDistance = float.MaxValue;
         Outpost closestOutpost = null;
         foreach (var post in outposts)
         {
             float dist = Vector2.Distance(request.location, post.transform.position);
             if (dist < minDistance)
             {
                 minDistance = dist;
                 closestOutpost = post;
             }
         }
         yield return null;
         request.CallBack(closestOutpost);
         Instance.IsProcessingOutpostQuery = false;
         Instance.TryProcessNextFindOutpost();
     }
 }