Пример #1
0
        protected void AddNeighbor(List <AStarNode> neighborList, Vector2Int basePoint, int dx, int dy)
        {
            int newX = basePoint.x + dx;
            int newY = basePoint.y + dy;

            // 测试边界
            if (!IsInRange(newX, newY))
            {
                return;
            }

            // 跳过不能通过的障碍
            if (!CanPass(newX, newY))
            {
                return;
            }

            // 当前点(p.x,p.y)与该检测邻居点(new_x,new_y)如果是斜线的话, 垂直于当前点(p.x,p.y)与该检测邻居点(new_x,new_y)对角线的两个点中其中一个是阻挡的,则该检测邻居点忽略,不考虑
            // 判断左上角邻居节点
            if (dx == -1 && dy == 1 && IsSkiped(DirectionInfoUtil.GetDirectionInfo(dx, dy), newX, newY))
            {
                return;
            }

            // 判断左下角邻居节点
            if (dx == -1 && dy == -1 && IsSkiped(DirectionInfoUtil.GetDirectionInfo(dx, dy), newX, newY))
            {
                return;
            }

            // 判断右上角邻居节点
            if (dx == 1 && dy == 1 && IsSkiped(DirectionInfoUtil.GetDirectionInfo(dx, dy), newX, newY))
            {
                return;
            }

            // 判断右下角邻居节点
            if (dx == 1 && dy == -1 && IsSkiped(DirectionInfoUtil.GetDirectionInfo(dx, dy), newX, newY))
            {
                return;
            }

            var neighbor_node = PoolCatManagerUtil.Spawn <AStarNode>(null, astarNode => astarNode.Init(newX, newY));

            neighborList.Add(neighbor_node);
        }
Пример #2
0
        //获得轨迹中可通过的最远点
        public static Vector2Int GetMostPassPoint(AStarMapPath astarMapPath, List <Vector2Int> trackList,
                                                  int[] canPassObstacleTypes,
                                                  int[] canPassTerrainTypes, bool canOut = false)
        {
            Vector2Int lp = trackList[0];
            Vector2Int tp = lp;

            for (int i = 1; i < trackList.Count; i++)
            {
                Vector2Int p = trackList[i];
                if (!CanPass(astarMapPath, p.x, p.y, canPassObstacleTypes, canPassTerrainTypes, canOut))
                {
                    break;
                }

                DirectionInfo directionInfo = DirectionInfoUtil.GetDirectionInfo(p.x - lp.x, p.y - lp.y);
                //      directionInfo = DirectionConst.GetDirectionInfo(0, 0); // 不再判断临边障碍 2012-10-29
                //      LogCat.log(directionInfo.name);
                if (directionInfo == DirectionInfoConst.LeftTopDirectionInfo)                 // 左上角
                {
                    if (!CanPass(astarMapPath, p.x + 1, p.y, canPassObstacleTypes, canPassTerrainTypes, canOut))
                    {
                        break;
                    }
                    if (!CanPass(astarMapPath, p.x, p.y - 1, canPassObstacleTypes, canPassTerrainTypes, canOut))
                    {
                        break;
                    }
                }
                else if (directionInfo == DirectionInfoConst.RightTopDirectionInfo)                 // 右上角
                {
                    if (!CanPass(astarMapPath, p.x - 1, p.y, canPassObstacleTypes, canPassTerrainTypes, canOut))
                    {
                        break;
                    }
                    if (!CanPass(astarMapPath, p.x, p.y - 1, canPassObstacleTypes, canPassTerrainTypes, canOut))
                    {
                        break;
                    }
                }
                else if (directionInfo == DirectionInfoConst.RightBottomDirectionInfo)                 // 右下角
                {
                    if (!CanPass(astarMapPath, p.x - 1, p.y, canPassObstacleTypes, canPassTerrainTypes, canOut))
                    {
                        break;
                    }
                    if (!CanPass(astarMapPath, p.x, p.y + 1, canPassObstacleTypes, canPassTerrainTypes, canOut))
                    {
                        break;
                    }
                }
                else if (directionInfo == DirectionInfoConst.LeftBottomDirectionInfo)                 // 左下角
                {
                    if (!CanPass(astarMapPath, p.x + 1, p.y, canPassObstacleTypes, canPassTerrainTypes, canOut))
                    {
                        break;
                    }
                    if (!CanPass(astarMapPath, p.x, p.y + 1, canPassObstacleTypes, canPassTerrainTypes, canOut))
                    {
                        break;
                    }
                }

                lp = p;
                tp = lp;
            }

            return(tp);
        }
Пример #3
0
        //检测轨迹是否可通过
        // can_out 是否允许在场景外
        public static bool CanPass(AStarMapPath astarMapPath, List <Vector2Int> trackList, int[] canPassObstacleTypes,
                                   int[] canPassTerrainTypes, bool canOut = false)
        {
            if (trackList.Count == 0)
            {
                return(true);
            }
            Vector2Int lp = trackList[0];

            if (trackList.Count == 1)
            {
                return(CanPass(astarMapPath, lp.x, lp.y, canPassObstacleTypes, canPassTerrainTypes, canOut));
            }
            for (int i = 1; i < trackList.Count; i++)
            {
                Vector2Int p = trackList[i];
                if (!CanPass(astarMapPath, p.x, p.y, canPassObstacleTypes, canPassTerrainTypes, canOut))
                {
                    return(false);
                }

                DirectionInfo directionInfo = DirectionInfoUtil.GetDirectionInfo(p.x - lp.x, p.y - lp.y);
                //      directionInfo = DirectionConst.GetDirectionInfo(0, 0);
                if (directionInfo == DirectionInfoConst.LeftTopDirectionInfo)                 // 左上角
                {
                    if (!CanPass(astarMapPath, p.x + 1, p.y, canPassObstacleTypes, canPassTerrainTypes, canOut))
                    {
                        return(false);
                    }
                    if (!CanPass(astarMapPath, p.x, p.y - 1, canPassObstacleTypes, canPassTerrainTypes, canOut))
                    {
                        return(false);
                    }
                }
                else if (directionInfo == DirectionInfoConst.RightTopDirectionInfo)                 // 右上角
                {
                    if (!CanPass(astarMapPath, p.x - 1, p.y, canPassObstacleTypes, canPassTerrainTypes, canOut))
                    {
                        return(false);
                    }
                    if (!CanPass(astarMapPath, p.x, p.y - 1, canPassObstacleTypes, canPassTerrainTypes, canOut))
                    {
                        return(false);
                    }
                }
                else if (directionInfo == DirectionInfoConst.RightBottomDirectionInfo)                 // 右下角
                {
                    if (!CanPass(astarMapPath, p.x - 1, p.y, canPassObstacleTypes, canPassTerrainTypes, canOut))
                    {
                        return(false);
                    }
                    if (!CanPass(astarMapPath, p.x, p.y + 1, canPassObstacleTypes, canPassTerrainTypes, canOut))
                    {
                        return(false);
                    }
                }
                else if (directionInfo == DirectionInfoConst.LeftBottomDirectionInfo)                 // 左下角
                {
                    if (!CanPass(astarMapPath, p.x + 1, p.y, canPassObstacleTypes, canPassTerrainTypes, canOut))
                    {
                        return(false);
                    }
                    if (!CanPass(astarMapPath, p.x, p.y + 1, canPassObstacleTypes, canPassTerrainTypes, canOut))
                    {
                        return(false);
                    }
                }

                lp = p;
            }

            return(true);
        }