//TODO: need to move to another component
    #region Moving logic
    public void MoveTo(Vector3 position, Action <bool> movingOverCallback)
    {
        SettlersEngine.Point startPoint = new SettlersEngine.Point()
        {
            X = (int)this.transform.position.x,
            Y = (int)this.transform.position.z
        };
        SettlersEngine.Point endPoint = new SettlersEngine.Point()
        {
            X = (int)position.x,
            Y = (int)position.z
        };
        IEnumerable <AStarPathNode> path = AStarManager.GetInstance().Search(startPoint, endPoint);

        if (path != null)
        {
            if (currentMoveEnumerator != null)
            {
                StopCoroutine(currentMoveEnumerator);
            }
            currentMoveEnumerator = StartCoroutine(StartMoveTo(path, movingOverCallback));
        }
        else
        {
            movingOverCallback(false);
        }
    }
示例#2
0
 public LinkedList <AStarPathNode> Search(SettlersEngine.Point startPoint, SettlersEngine.Point endPoint)
 {
     if (currentSolver == null)
     {
         return(null);
     }
     else
     {
         return(currentSolver.Search(startPoint, endPoint, null));
     }
 }
    private static object Convert(SettlersEngine.Point point, Type type)
    {
        switch (type.FullName)
        {
        case "Vector2Int":
            return(new Vector2Int(point.X, point.Y));

        default:
            Debug.LogError("Can't convert unknown type " + type.FullName);
            return(null);
        }
    }
示例#4
0
 public LinkedList <AStarPathNode> SearchClosest(SettlersEngine.Point startPoint, SettlersEngine.Point endPoint)
 {
     if (currentSolver == null)
     {
         return(null);
     }
     else
     {
         SearchOptions opt = new SearchOptions();
         opt.forceWalkable.Add(endPoint);
         LinkedList <AStarPathNode> result = currentSolver.Search(startPoint, endPoint, opt);
         if (result != null && result.Count > 0)
         {
             result.RemoveLast();
         }
         return(result);
     }
 }
 public static T Convert <T>(SettlersEngine.Point point)
 {
     return((T)Convert(point, typeof(T)));
 }