示例#1
0
        private void TunnelTwoRoom(CForestRoomData a, CForestRoomData b)
        {
            bool v = CheckTunnelDoor(a, b);

            if (!v)
            {
                return;
            }

            m_starGrid.SetStartNode(a.DoorForTunnel);
            m_starGrid.SetEndNode(b.DoorForTunnel);
            m_astar.FindPath(m_starGrid);
            var path = m_astar.Path;

            foreach (var node in path)
            {
                SetTileData(node.Col, node.Row, "-1", CForestRoomTileType.OuterRoad);
            }
        }
示例#2
0
        /// <summary>
        /// 根据可通行性显示格子
        /// 请自行保证之前是全部隐藏的
        /// </summary>
        public void Show(int range, CStarGrid grid, Vector3 center)
        {
            //如果放在hero下面, hero会旋转, 这样我们的格子也会被旋转.
            //所以需要设置格子的旋转.否则显示的和可通行数据对不上
            m_tran.rotation = Quaternion.identity;
            Vector2Int pos = new Vector2Int((int)center.x, (int)center.z);

            DectectGridRange(range);
            CopyWalkableData(range, grid, pos);

            int gap = m_maxView - range;

            m_grid.SetStartNode(range, range);
            for (int c = 0; c < m_grid.NumCols; c++)
            {
                for (int r = 0; r < m_grid.NumRows; r++)
                {
                    int dist = Math.Abs(c - range) + Math.Abs(r - range);
                    if (dist > range)
                    {
                        continue;
                    }
                    m_grid.SetEndNode(c, r);

                    var  go = m_dict[(r + gap) * 1000 + (c + gap)];
                    bool w  = m_star.FindPath(m_grid, true);
                    //如果不可通行, 或者通行的路径大于range
                    if (!w || m_star.Path.Count >= range)
                    {
                        go.SetActive(false);
                    }
                    else
                    {
                        go.SetActive(true);
                    }
                }
            }
        }