Exemple #1
0
 public virtual void SetWalkable(bool value, PathGrid grid)
 {
     //TODO::这里算坐标的方式设一个建筑根据nodexz和spanxz来设定建筑不可走区域,可以改的更灵活
     UpdateSpanPos();
     foreach (Vector3 v in m_spanPosArray)
     {
         grid.SetWalkable(Mathf.FloorToInt(v.x / world.cellSize), Mathf.FloorToInt(v.z / world.cellSize), value);
     }
 }
Exemple #2
0
        public PathGrid Clone()
        {
            PathGrid gird = new PathGrid(this.m_gridX, this.m_gridZ);

            for (int i = 0; i < m_gridX; ++i)
            {
                for (int j = 0; j < m_gridZ; ++j)
                {
                    gird.GetNode(i, j).walkable = this.GetNode(i, j).walkable;
                }
            }
            return(gird);
        }
Exemple #3
0
        public virtual bool GetRotatable(PathGrid grid)
        {
            if (spanX == spanZ)
            {
                return(true);
            }

            SetWalkable(true, grid);
            m_isRotated = !m_isRotated;
            UpdateSpanPos();
            bool flag = GetWalkable(grid);

            //还原
            m_isRotated = !m_isRotated;
            SetWalkable(false, grid);
            return(flag);
        }
Exemple #4
0
        public virtual bool GetWalkable(PathGrid grid)
        {
            bool flag = false;

            foreach (Vector3 v in m_spanPosArray)
            {
                int nodeX = Mathf.FloorToInt(v.x / world.cellSize);
                int nodeY = Mathf.FloorToInt(v.z / world.cellSize);
                if (nodeX < 0 || nodeX > grid.gridX - 1)
                {
                    return(false);
                }
                if (nodeY < 0 || nodeY > grid.gridZ - 1)
                {
                    return(false);
                }
                flag = grid.GetNode(nodeX, nodeY).walkable;
                if (!flag)
                {
                    return(false);
                }
            }
            return(true);
        }
Exemple #5
0
 public Astar(PathGrid grid)
 {
     this.m_grid = grid;
     heuristic   = Euclidian2;
     m_open      = new BinaryHeap(JustMin);
 }