コード例 #1
0
        /// <summary>
        /// 注意这里不应该这样写,算法要抽出去,不然系统耦合性会增加,扩展性会降低!!!时间紧迫,先将就了!!!!
        /// </summary>
        public void GeneratePerinMaze()
        {
            MapGenerator_Perlin_Config config = GetConfigFile <MapGenerator_Perlin_Config>();

            if (config != null)
            {
                //生成Perlin噪声地图
                PerlinRandom pr = new PerlinRandom();
                pr.width  = config.width;
                pr.height = config.height;
                pr.x_org  = config.random_origin_position ? Random.Range(0, C_ORITIN_BOUND) : config.x_org;
                pr.y_org  = config.random_origin_position ? Random.Range(0, C_ORITIN_BOUND) : config.y_org;
                pr.scale  = config.scale;
                pr.Generate();

                for (int y = 0; y < config.height; y++)
                {
                    for (int x = 0; x < config.width; x++)
                    {
                        m_MapData[x * config.width + y] = config.GetPrefabIndex(pr.GetValueAt(x, y));
                    }
                }
            }
            else
            {
                Debug.LogError("Error Map Config Not Found !");
            }
        }
コード例 #2
0
        public TileMapData GenerateTileMapData()
        {
            //这个以后考虑如何自动化进行。容易遗忘的操作!
            config.theme_config.RebuildTileThemeConfig();

            Debug.Log("GenerateTileMapData");
            PerlinRandom pr = new PerlinRandom();

            pr.width  = config.width;
            pr.height = config.height;
            pr.x_org  = config.random_origin_position ? config.x_org : Random.Range(0, origin_bound);
            pr.y_org  = config.random_origin_position ? config.y_org : Random.Range(0, origin_bound);
            pr.scale  = config.scale;
            pr.Generate();

            TileMapData tile_map_date = new TileMapData();

            for (int y = 0; y < config.height; y++)
            {
                for (int x = 0; x < config.width; x++)
                {
                    tile_map_date[SharedUtil.PointHash(x, y)] = config.GetPrefabIndex(pr.GetValueAt(x, y));
                }
            }

            return(tile_map_date);
        }