public RequestPath ( PathfindingRequest, req, bool &result ) : List |
||
req | PathfindingRequest, | |
result | bool | |
리턴 | List |
public List<PathNode> RequestPath(PathfindingRequest req, ref bool result)
{
List<PathNode> pathResult = null;
//float time1 = 0;
//float time2 = 0;
//DateTime dt1 = DateTime.Now;
//DateTime dt2 = DateTime.Now;
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
if (FindRequest(req) != null && FpsCounter.pathfindingsCounter <= maxPathFindingPerSecond)
{
FpsCounter.pathfindingsCounter++;
requests.Remove(req);
result = true;
sw.Start();
pathResult = GetPath(req.Start, req.End);
sw.Stop();
}
else if (requests.Count == 0 && FpsCounter.pathfindingsCounter <= maxPathFindingPerSecond)
{
FpsCounter.pathfindingsCounter++;
result = true;
sw.Start();
pathResult = GetPath(req.Start, req.End);
sw.Stop();
}
else
{
result = false;
requests.Add(req);
pathResult = null;
}
if (result)
{
//Debug.Log ("Pathfinding time: " + (sw.ElapsedMilliseconds) + " ms");
FpsCounter.pathfindingTime = sw.ElapsedMilliseconds;
}
return pathResult;
}
private IEnumerator MoveToInteraction(Interactable interactable, string interaction) { Collider2D c = GetComponent <Collider2D>(); Debug.LogWarning("Moving to interaction " + interactable.ToString()); while (interactable) { if (!c.IsTouching(interactable.GetComponent <Collider2D>())) { PathfindingManager.RequestPath(new PathRequest(transform.position, interactable.transform.position, uc.OnPathFound)); yield return(new WaitForSeconds(.2f)); //might be able to extend this here? no need to be as precise? } else { uc.StopMoving(); break; } } //if the interactable is still there when we get there if (interactable != null) { interactable.Interaction(interaction); } yield break; }