//获取P点四周为的可以通过的点 public static Vector2Int?FindAroundFreePoint(AStarMapPath astarMapPath, Vector2Int basePoint, List <Vector2Int> exceptPointList, int[] canPassObstacleTypes, int[] canPassTerrainTypes, RandomManager randomManager = null) { randomManager = randomManager ?? Client.instance.randomManager; if (!IsInRange(astarMapPath.GetFinalGrids(), basePoint)) { return(null); } if (CanPass(astarMapPath, basePoint.x, basePoint.y, canPassObstacleTypes, canPassTerrainTypes) && (exceptPointList == null || !exceptPointList.Contains(basePoint))) { return(basePoint); } int max = Math.Max(Math.Max(basePoint.x, astarMapPath.Width() - basePoint.x), Math.Max(basePoint.y, astarMapPath.Height() - basePoint.y)); for (int i = 1; i <= max; i++) { List <Vector2Int> list = GetAroundFreePointList(astarMapPath, basePoint, i, canPassObstacleTypes, canPassTerrainTypes); if (exceptPointList != null) { list.RemoveElementsOfSub(exceptPointList); } if (list.Count > 0) { return(list[randomManager.RandomInt(0, list.Count)]); } } return(null); }
protected int[] canPassTerrainTypes; // 可通过地形表 public AStarImpl(AStarMapPath astarMapPath, AStarHType astarHType, int[] canPassObstacleTypes, int[] canPassTerrainTypes) { this.astarMapPath = astarMapPath; SetAStarHType(astarHType); SetCanPassType(canPassObstacleTypes, canPassTerrainTypes); SetRange(0, 0, astarMapPath.Height() - 1, astarMapPath.Width() - 1); }
int GetHeight() { return(astarMapPath.Height()); }