Exemplo n.º 1
0
 /// <summary>
 /// 方便的函数,直接遍历Rect内的所有值,并设置其Type。
 /// </summary>
 /// <param name="save_data"></param>
 /// <param name="config"></param>
 /// <param name="target_type"></param>
 public static void SetMapTileType(this TileRect rect, TileMapData save_data, TileThemeConfig theme_config, string type)
 {
     for (int iy = rect.y; iy <= rect.y_end; iy++)
     {
         for (int ix = rect.x; ix <= rect.x_end; ix++)
         {
             save_data[SharedUtil.PointHash(ix, iy)] = theme_config.GetTilePrefabConfigIndex(type);
         }
     }
 }
Exemplo n.º 2
0
        private void MakeSureShowIndices(TileRect tr)
        {
            m_PendingGenCells.Clear();
            int index_of_tile;
            int prefabid_of_tile;

            //第一步,计算玩家EndDrag的时候,需要显示的新的格子
            for (int ix = tr.x; ix <= tr.x_end; ix++)
            {
                for (int iy = tr.y; iy <= tr.y_end; iy++)
                {
                    index_of_tile    = ix * m_Config.width + iy;
                    prefabid_of_tile = m_ArchiveFile[index_of_tile];

                    m_PendingGenCells.Add(index_of_tile, prefabid_of_tile);

                    //这里先添加到SpawingCells中去,真正的Spawn和Delete都在Update里面进行的。
                    //可以延迟加载和删除,防止卡顿。
                    if (m_ActiveCells.ContainsKey(index_of_tile) == false)
                    {
                        m_SpawningCells[index_of_tile] = new TilePoint(ix, iy);
                    }

                    SpawnGeneration++;

                    //如果这个格子在死亡格子里面,那么,取消他的死刑。
                    if (m_DyingCells.ContainsKey(index_of_tile))
                    {
                        m_DyingCells.Remove(index_of_tile);
                    }
                }
            }

            //Debug.Log("m_spawing cells count is " + m_SpawningCells.Count);

            foreach (int key in m_ActiveCells.Keys)
            {
                //pending里面不包含这个格子,那么他是将要删掉的格子。
                if (m_PendingGenCells.ContainsKey(key) == false)
                {
                    m_DyingCells[key] = Time.timeSinceLevelLoad + deleteDelay;

                    //对于将要删除的格子,判断他是不是将要生成的格子,避免尴尬
                    if (m_SpawningCells.ContainsKey(key))
                    {
                        m_SpawningCells.Remove(key);
                    }
                }
            }

            //Debug.Log("Dying Key count " + m_DyingCells.Count);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 获得本次移动的位置
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        private TileRect DecideShowRange(int x, int y)
        {
            int x1 = Mathf.Max(0, x - halfViewportSize);
            int y1 = Mathf.Max(0, y - halfViewportSize);
            int x2 = Mathf.Min(m_Config.width - 1, x + halfViewportSize);
            int y2 = Mathf.Min(m_Config.height - 1, y + halfViewportSize);

            TileRect tr = new TileRect();

            tr.SetByTwoPoint(x1, y1, x2, y2);

            return(tr);
        }
Exemplo n.º 4
0
        public override void ShowMapAt(int x, int y)
        {
            if (m_Config.CheckValidXY(x, y))
            {
                TileRect rect = DecideShowRange(x, y);
                MakeSureShowIndices(rect);

                if (Application.isPlaying == false)
                {
                    DeadOrAlive(true);
                }
            }

            //MapTilePrefabPool pool = m_ResourceLoader as MapTilePrefabPool;
            //if (pool != null)
            //    Debug.Log(pool.ToString());
        }
Exemplo n.º 5
0
        /// <summary>
        /// 不是特别完美,和map_data产生了耦合,不过只把他当成内部类,也无妨,只不过,其他类调用的时候,返回的是这个类的成员变量而不是临时变量!
        /// </summary>
        /// <returns></returns>
        public TileMapData GenerateTileMapData()
        {
            //重置
            TileMapData temp_data = new TileMapData();

            config.theme_config.RebuildTileThemeConfig();
            int tile_size_x     = config.tile_size_x;
            int tile_size_y     = config.tile_size_y;
            int total_thickness = config.wall_thickness + config.road_thickness;

            //初始化地图
            for (int iy = 0; iy < tile_size_y; iy++)
            {
                for (int ix = 0; ix < tile_size_x; ix++)
                {
                    int key = SharedUtil.PointHash(ix, iy);
                    temp_data[key] = config.theme_config.GetTilePrefabConfigIndex(config.road_name);
                }
            }

            MazeAlgorithm algorithm =
                (MazeAlgorithm)System.Activator.CreateInstance(System.Type.GetType("TileMazeMaker.Algorithm.Maze." + config.maze_algorithm.ToString()));

            //处理Mask
            algorithm.SetMazeMaskCells(config.maze_mask);

            //设置后期处理
            for (int i = 0; i < config.post_process.Count; i++)
            {
                if (config.post_process[i] != EMazePostProcess.None)
                {
                    algorithm.AddPostProcesser(config.post_process[i].ToString());
                }
            }

            algorithm.BuildMaze <MazeCell>(config.width, config.height);

            dig_list.Add(DigNorth);
            dig_list.Add(DigWest);
            dig_list.Add(DigSouth);
            dig_list.Add(DigEast);

            for (int iy = 0; iy < config.height; iy++)
            {
                for (int ix = 0; ix < config.width; ix++)
                {
                    IMazeCell cell = algorithm.GetAt(ix, iy);
                    if (cell != null)
                    {
                        TileRect out_rect = new TileRect(
                            ix * total_thickness,
                            iy * total_thickness,
                            config.road_thickness + 2 * config.wall_thickness,
                            config.road_thickness + 2 * config.wall_thickness);

                        out_rect.SetMapTileType(temp_data, config.theme_config, config.wall_name);

                        TileRect rect = new TileRect(
                            ix * total_thickness + config.wall_thickness,
                            iy * total_thickness + config.wall_thickness,
                            config.road_thickness,
                            config.road_thickness);

                        rect.SetMapTileType(temp_data, config.theme_config, config.road_name);

                        for (int i = 0; i < (int)EMazeDirection.DirectionCount; i++)
                        {
                            if (cell.IsConnectedTo((EMazeDirection)i))
                            {
                                dig_list[i](temp_data, rect);
                            }
                        }
                    }
                }
            }

            return(temp_data);
        }
Exemplo n.º 6
0
        protected void DigWest(TileMapData data, TileRect rect)
        {
            TileRect dig_rect = new TileRect(rect.x - config.wall_thickness, rect.y, config.wall_thickness, config.road_thickness);

            dig_rect.SetMapTileType(data, config.theme_config, config.road_name);
        }