Exemple #1
0
        public static Action Test_GetExtendPoint()
        {
            Vector2Int a_point      = new Vector2Int(-4, -4);
            Vector2Int b_point      = new Vector2Int(3, 2);
            Vector2Int target_point = AStarUtil.GetExtendPoint(a_point, b_point, 2);

            return(() => { AStarUtil.GUIShowPointList(-5, -5, 5, 5, new List <Vector2Int>()
                {
                    target_point
                }); });
        }
Exemple #2
0
        public static Action Test_FindAroundFreePoint()
        {
            Vector2Int?point = AStarUtil.FindAroundFreePoint(new AStarMapPath(grids), new Vector2Int(2, 2), 2, null,
                                                             AStarMapPathConst.Critter_Can_Pass_Obstacle_Types, AStarMapPathConst.User_Can_Pass_Terrain_Types);

            return(() =>
            {
                if (point != null)
                {
                    AStarUtil.GUIShowPointList(0, 0, 9, 9, point.Value);
                }
            });
        }
        public static Action Test_GetMostPassPoint()
        {
            Vector2Int point = AStarUtil.GetMostPassPoint(new AStarMapPath(grids), new List <Vector2Int>()
            {
                new Vector2Int(0, 0),
                new Vector2Int(1, 1),
                new Vector2Int(2, 2),
                new Vector2Int(3, 3),
                new Vector2Int(4, 4),
            }, AStarMapPathConst.Critter_Can_Pass_Obstacle_Types, AStarMapPathConst.User_Can_Pass_Terrain_Types);

            return(() => { AStarUtil.GUIShowPointList(0, 0, 9, 9, point); });
        }
Exemple #4
0
        protected override float GetG(Vector2Int p1, Vector2Int p2)
        {
            int   dx          = Math.Abs(p1.x - p2.x);
            int   dy          = Math.Abs(p1.y - p2.y);
            var   terrainType = AStarUtil.GetTerrainType(astarMapPath.GetFinalGrids()[p2.x][p2.y]);
            float cost        = AStarConst.AStarTerrainType_Dict[terrainType].cost;

            if (dx == 0 || dy == 0)             //非斜线方向
            {
                return(cost);
            }
            else             //斜线方向
            {
                return(cost * 1.414f);
            }
        }
Exemple #5
0
        public static Action Test_GetRandomMovePoint()
        {
            Vector2Int?point = AStarUtil.GetRandomMovePoint(new AStarMapPath(grids), new Vector2Int(0, 0),
                                                            new Vector2Int(3, 3)
                                                            , 2, AStarMapPathConst.Critter_Can_Pass_Obstacle_Types, AStarMapPathConst.User_Can_Pass_Terrain_Types);

            return(() =>
            {
                if (point != null)
                {
                    AStarUtil.GUIShowPointList(0, 0, 9, 9, new List <Vector2Int>()
                    {
                        point.Value
                    });
                }
            });
        }
Exemple #6
0
        //获得指定扇形的物品(仅供父级场景调用)
        public Item[] GetSectorItems(Vector2Int sectorCenterPos, Vector2 sectorDir, int sectorRadius,
                                     float sectorHalfDegrees, string belong = null, bool isNotIncludeChildScene = false)
        {
            List <Item> result = new List <Item>();
            var         items  = GetItems(null, belong, isNotIncludeChildScene);

            for (var i = 0; i < items.Length; i++)
            {
                var        item = items[i];
                Vector2Int pos  = item.GetEnv <Scene>().ToParentPos(item.GetPos(), this);
                if (AStarUtil.IsInSector(pos, sectorCenterPos, sectorDir, sectorRadius, sectorHalfDegrees))
                {
                    result.Add(item);
                }
            }

            return(result.ToArray());
        }
Exemple #7
0
        //获得指定范围的物品(仅供父级场景调用)
        public Item[] GetAroundItems(Vector2Int comparePos, int radius, string belong = null,
                                     bool isNotIncludeChildScene = false)
        {
            List <Item> result = new List <Item>();
            var         items  = GetItems(null, belong, isNotIncludeChildScene);

            for (var i = 0; i < items.Length; i++)
            {
                var        item = items[i];
                Vector2Int pos  = item.GetEnv <Scene>().ToParentPos(item.GetPos(), this);
                if (AStarUtil.IsInAround(pos, comparePos, radius))
                {
                    result.Add(item);
                }
            }

            return(result.ToArray());
        }
 void DrawDataDict()
 {
     for (int gridY = _target.astarConfigData.minGridY; gridY <= _target.astarConfigData.maxGridY; gridY++)
     {
         for (int gridX = _target.astarConfigData.minGridX;
              gridX <= _target.astarConfigData.maxGridX;
              gridX++)
         {
             int value        = _target.astarConfigData.GetDataValue(gridX, gridY);
             int obstacleType = AStarUtil.GetObstacleType(value);
             int terrainType  = AStarUtil.GetTerrainType(value);
             //draw obstacleType
             if (this.isSeeObstacleType && obstacleType == AStarConst.Default_Obstacle_Type_Value)
             {
                 AStarEditorUtil.DrawObstacleTypeRect(_target, gridX, gridY, obstacleType);
             }
             // draw terrainType
             if (this.isSeeTerrainType && obstacleType == AStarConst.Default_Terrain_Type_Value)
             {
                 AStarEditorUtil.DrawdTerrainTypeRect(_target, gridX, gridY, terrainType);
             }
         }
     }
 }
 void HandleEvent()
 {
     if (e.control && (e.type == EventType.MouseDown || e.type == EventType.MouseDrag) && e.button == 0)             //press
     {
         if (!_target.astarConfigData.IsInRange(mouseGridX, mouseGridY) &&
             !_target.astarConfigData.isEnableEditOutsideBounds)
         {
             return;
         }
         int orgValue     = _target.astarConfigData.GetDataValue(mouseGridX, mouseGridY);
         int obstacleType = AStarUtil.GetObstacleType(orgValue);
         int terrainType  = AStarUtil.GetTerrainType(orgValue);
         if (isSeeObstacleType)
         {
             obstacleType = this.selectedObstacleType.value;
         }
         if (isSeeTerrainType)
         {
             terrainType = this.selectedTerrainType.value;
         }
         int value = AStarUtil.ToGridType(0, terrainType, obstacleType);
         _brush.DoPaintPressed(mouseGridX, mouseGridY, value);
     }
 }
Exemple #10
0
        //直角寻路(先横向再纵向寻路)
        public static List <Vector2Int> BorderFindPath(AStarMapPath astarMapPath, Vector2Int pointA, Vector2Int pointB,
                                                       int[] canPassObstacleTypes, int[] canPassTerrainTypes)
        {
            if (!AStarUtil.IsInRange(astarMapPath.GetFinalGrids(), pointA) ||
                !AStarUtil.IsInRange(astarMapPath.GetFinalGrids(), pointB))
            {
                return(null);
            }
            List <Vector2Int> list = new List <Vector2Int> {
                pointA
            };
            int dv = pointB.x > pointA.x ? 1 : -1;

            for (int x = pointA.x + dv; x *dv <= pointB.x *dv; x += dv)
            {
                //      LogCat.log(x, point_a.y);
                if (!AStarUtil.CanPass(astarMapPath, x, pointA.y, canPassObstacleTypes, canPassTerrainTypes))
                {
                    return(null);
                }
                list.Add(new Vector2Int(x, pointA.y));
            }

            dv = pointB.y > pointA.y ? 1 : -1;
            for (int y = pointA.y + dv; y *dv < pointB.y *dv; y += dv)
            {
                if (!AStarUtil.CanPass(astarMapPath, pointB.x, y, canPassObstacleTypes, canPassTerrainTypes))
                {
                    return(null);
                }
                list.Add(new Vector2Int(pointB.x, y));
            }

            list.Add(pointB);
            return(list);
        }
Exemple #11
0
        //先对角线查找,再直角查找
        public static List <Vector2Int> DirectFindPath(AStarMapPath astarMapPath, Vector2Int pointA, Vector2Int pointB,
                                                       int[] canPassObstacleTypes, int[] canPassTerrainTypes)
        {
            if (!AStarUtil.IsInRange(astarMapPath.GetFinalGrids(), pointA) ||
                !AStarUtil.IsInRange(astarMapPath.GetFinalGrids(), pointB))
            {
                return(null);
            }
            List <Vector2Int> list = null;

            if (pointA.Equals(pointB))             // 同一点
            {
                list = new List <Vector2Int> {
                    pointA
                };
            }
            else if (pointA.x == pointB.x)
            {
                list = new List <Vector2Int> {
                    pointA
                };
                int dv = pointB.y > pointA.y ? 1 : -1;
                for (int y = pointA.y + dv; y *dv < pointB.y *dv; y += dv)
                {
                    if (!AStarUtil.CanPass(astarMapPath, pointA.x, y, canPassObstacleTypes, canPassTerrainTypes))
                    {
                        return(null);
                    }
                    list.Add(new Vector2Int(pointA.x, y));
                }

                list.Add(pointB);
            }
            else if (pointA.y == pointB.y)
            {
                list = new List <Vector2Int> {
                    pointA
                };
                int dv = pointB.x > pointA.x ? 1 : -1;
                for (int x = pointA.x + dv; x *dv < pointB.x *dv; x += dv)
                {
                    if (!AStarUtil.CanPass(astarMapPath, x, pointA.y, canPassObstacleTypes, canPassTerrainTypes))
                    {
                        return(null);
                    }
                    list.Add(new Vector2Int(x, pointA.y));
                }

                list.Add(pointB);
            }
            else
            {
                //先对角线查找,再直角查找
                list = DiagonallyFindPath(astarMapPath, pointA, pointB, canPassObstacleTypes,
                                          canPassTerrainTypes);
                if (list == null)
                {
                    list = DiagonallyFindPath(astarMapPath, pointB, pointA, canPassObstacleTypes,
                                              canPassTerrainTypes);
                    if (list == null)
                    {
                        list = BorderFindPath(astarMapPath, pointA, pointB, canPassObstacleTypes,
                                              canPassTerrainTypes);
                        if (list == null)
                        {
                            list = BorderFindPath(astarMapPath, pointB, pointA, canPassObstacleTypes,
                                                  canPassTerrainTypes);
                            list?.Reverse();
                        }
                    }
                    else
                    {
                        list.Reverse();
                    }
                }
            }

            return(list);
        }
Exemple #12
0
        //////////////////////////////////////GetXXX/////////////////////////////////////


        //////////////////////////////////////SetXXX/////////////////////////////////////


        /////////////////////////////////////////////////////////

        public bool IsInAround(Vector2Int comparePos, int radius)
        {
            return(AStarUtil.IsInAround(this.GetPos(), comparePos, radius));
        }
Exemple #13
0
 public bool IsInSector(Vector2Int sectorCenterPos, Vector2 sectorDir, int sectorRadius,
                        float sectorHalfDegrees)
 {
     return(AStarUtil.IsInSector(this.GetPos(), sectorCenterPos, sectorDir, sectorRadius, sectorHalfDegrees));
 }
Exemple #14
0
 public static void Test_IsNeighborBlock()
 {
     LogCat.log(AStarUtil.IsNeighborBlock(new Vector2Int(2, 2), new Vector2Int(2, 3)));
 }
Exemple #15
0
 public static void Test_IsValidObstacleType()
 {
     LogCat.log(AStarUtil.IsValidObstacleType(255));
 }
Exemple #16
0
 //检测某个点是否可通过
 // can_out 是否允许在场景外
 public bool CanPass(int x, int y, int[] canPassObstacleTypes,
                     int[] canPassTerrainTypes, bool isCanOut = false)
 {
     return(AStarUtil.CanPass(this, x, y, canPassObstacleTypes, canPassTerrainTypes, isCanOut));
 }
Exemple #17
0
 public static void Test_GetBlockPoint()
 {
     LogCat.log(AStarUtil.GetBlockPoint(new Vector2Int(4, 7)));
 }
Exemple #18
0
 public static void Test_GetTerrainType()
 {
     LogCat.log(AStarUtil.GetTerrainType(24));
 }
Exemple #19
0
 public static void Test_GetField()
 {
     LogCat.log(AStarUtil.GetField((int)Math.Pow(2, 9)));
 }
Exemple #20
0
 //获得两点间可通过的最远点
 // can_out  是否允许通过场景外
 public Vector2Int GetMostLinePassPoint(Vector2Int lp, Vector2Int tp,
                                        int[] canPassObstacleTypes, int[] canPassTerrainTypes, bool isCanOut = false)
 {
     return(AStarUtil.GetMostLinePassPoint(this, lp, tp, canPassObstacleTypes, canPassTerrainTypes,
                                           isCanOut));
 }
Exemple #21
0
 public static void Test_GetObstacleType()
 {
     LogCat.log(AStarUtil.GetObstacleType(2));
 }
Exemple #22
0
 public static void Test_IsInRange()
 {
     LogCat.log(AStarUtil.IsInRange(grids, new Vector2Int(4, 5)));
 }
Exemple #23
0
 //检测两点间直线是否可通过
 public bool CanLinePass(Vector2Int pointA, Vector2Int pointB, int[] canPassObstacleTypes,
                         int[] canPassTerrainTypes, bool isCanOut = false)
 {
     return(AStarUtil.CanLinePass(this, pointA, pointB, canPassObstacleTypes, canPassTerrainTypes,
                                  isCanOut));
 }
Exemple #24
0
 //检测轨迹是否可通过
 // can_out 是否允许在场景外
 public bool CanPass(List <Vector2Int> trackList, int[] canPassObstacleTypes,
                     int[] canPassTerrainTypes, bool isCanOut = false)
 {
     return(AStarUtil.CanPass(this, trackList, canPassObstacleTypes, canPassTerrainTypes, isCanOut));
 }
Exemple #25
0
        //对角线寻路
        public static List <Vector2Int> DiagonallyFindPath(AStarMapPath astarMapPath, Vector2Int pointA,
                                                           Vector2Int pointB,
                                                           int[] canPassObstacleTypes,
                                                           int[] canPassTerrainTypes)
        {
            if (!AStarUtil.IsInRange(astarMapPath.GetFinalGrids(), pointA) ||
                !AStarUtil.IsInRange(astarMapPath.GetFinalGrids(), pointB))
            {
                return(null);
            }
            List <Vector2Int> list = new List <Vector2Int>();

            int dx = pointB.x - pointA.x;
            int dy = pointB.y - pointA.y;

            if (Math.Abs(dx) > Math.Abs(dy))
            {
                int x1;
                if (dx > 0)
                {
                    x1 = pointA.x + Math.Abs(dy);
                }
                else
                {
                    x1 = pointA.x - Math.Abs(dy);
                }
                Vector2Int p = new Vector2Int(x1, pointB.y);
                if (!AStarUtil.CanPass(astarMapPath, p.x, p.y, canPassObstacleTypes, canPassTerrainTypes))
                {
                    return(null);
                }
                List <Vector2Int> list1 = AStarUtil.GetLinePointList(pointA, p);
                if (!AStarUtil.CanPass(astarMapPath, list1, canPassObstacleTypes, canPassTerrainTypes))
                {
                    return(null);
                }
                List <Vector2Int> list2 = AStarUtil.GetLinePointList(p, pointB);
                if (!AStarUtil.CanPass(astarMapPath, list2, canPassObstacleTypes, canPassTerrainTypes))
                {
                    return(null);
                }
                list.AddRange(list1);
                list.RemoveLast();                 //删掉p
                list.AddRange(list2);
            }
            else
            {
                int y1;
                if (dy > 0)
                {
                    y1 = pointA.y + Math.Abs(dx);
                }
                else
                {
                    y1 = pointA.y - Math.Abs(dx);
                }
                Vector2Int p = new Vector2Int(pointB.x, y1);
                if (!AStarUtil.CanPass(astarMapPath, p.x, p.y, canPassObstacleTypes, canPassTerrainTypes))
                {
                    return(null);
                }
                List <Vector2Int> list1 = AStarUtil.GetLinePointList(pointA, p);
                if (!AStarUtil.CanPass(astarMapPath, list1, canPassObstacleTypes, canPassTerrainTypes))
                {
                    return(null);
                }
                List <Vector2Int> list2 = AStarUtil.GetLinePointList(p, pointB);
                if (!AStarUtil.CanPass(astarMapPath, list2, canPassObstacleTypes, canPassTerrainTypes))
                {
                    return(null);
                }
                list.AddRange(list1);
                list.RemoveLast();                 //删掉p
                list.AddRange(list2);
            }

            return(list);
        }
Exemple #26
0
 public static void Test_IsSameField()
 {
     LogCat.log(AStarUtil.IsSameField((int)Math.Pow(2, 9), (int)Math.Pow(2, 8)));
 }
Exemple #27
0
        public static Action Test_GetNeighborList()
        {
            List <Vector2Int> pointList = AStarUtil.GetNeighborList(new Vector2Int(2, 2));

            return(() => { AStarUtil.GUIShowPointList(0, 0, 9, 9, pointList); });
        }
Exemple #28
0
 //获取离a,b最近的点
 public Vector2Int GetNearestPoint(Vector2Int pointA, Vector2Int pointB,
                                   int[] canPassObstacleTypes, int[] canPassTerrainTypes)
 {
     return(AStarUtil.GetNearestPoint(this, pointA, pointB, canPassObstacleTypes, canPassTerrainTypes));
 }
Exemple #29
0
 public static void Test_IsInRangeX()
 {
     LogCat.log(AStarUtil.IsInRangeX(grids, 6));
 }
Exemple #30
0
 public static void Test_ToGridType()
 {
     LogCat.log(AStarUtil.GetObstacleType(AStarUtil.ToGridType(1, 1, 2)));
 }