Пример #1
0
        void Generate()
        {
            int seed = int.Parse(generate.seed.ToString() + (groundData.pos.x).ToString() + (groundData.pos.z).ToString());

            MapTools.SetRandomSeed(seed, out rand);

            if (spaceData.type == SpaceType.City)
            {
                if (!generate.map_data.GetHouseData(out wall_datas, out house_datas, area_id))
                {
                    // 创建城市
                    GenerateCity(spaceData);
                    generate.map_data.SetHouseData(wall_datas, house_datas, area_id);
                }

                debug_test += "\n增加操作 " + GenerateState.Wall + " " + area_id + "  " + new System.Diagnostics.StackTrace();
                debug_test += "\n增加操作 " + GenerateState.House + " " + area_id + "  " + new System.Diagnostics.StackTrace();
                BuildOperate wall_operate = new BuildOperate()
                {
                    area_id = area_id, state = GenerateState.Wall
                };
                generate.EnqueueOperate(wall_operate); // 增加创建围墙的操作
                BuildOperate house_operate = new BuildOperate()
                {
                    area_id = area_id, state = GenerateState.House
                };
                generate.EnqueueOperate(house_operate); // 增加创建房子的操作
            }

            if (!generate.map_data.GetDecorateData(out tree_datas, out decorate_datas, area_id))
            {
                // 创建地表
                GenerateOther();
                generate.map_data.SetDecorateData(tree_datas, decorate_datas, area_id);
            }
            city_rects = null;
            if (tree_datas.Length > 0)
            {
                debug_test += "\n增加操作 " + GenerateState.Tree + " " + area_id + "  " + new System.Diagnostics.StackTrace();
                BuildOperate tree_operate = new BuildOperate()
                {
                    area_id = area_id, state = GenerateState.Tree
                };
                generate.EnqueueOperate(tree_operate); // 增加创建树的操作
            }
            debug_test += "\n增加操作 " + GenerateState.Decorate + " " + area_id + "  " + new System.Diagnostics.StackTrace();
            BuildOperate decorate_operate = new BuildOperate()
            {
                area_id = area_id, state = GenerateState.Decorate
            };

            generate.EnqueueOperate(decorate_operate); // 增加创建植物的操作
        }
Пример #2
0
        public void GenerateWorld()
        {
            MapTools.SetRandomSeed(seed, out rand);
            generate_progress = 0;
            onGenerateMap     = true;
            if (seed < 0)
            {
                DateTime start_time = DateTime.Now;
                seed = (int)start_time.Second;
            }
            map_data = new MapData(this, seed, generate_size);
            // 城市区域
            if (!readfile || !map_data.GetCityData(out citys))
            {
                citys = CreateSpacePos(city_count, city_min, city_max, city_dis, SpaceType.City);
                map_data.SetCityData(citys);
            }
            // 森林区域
            if (!readfile || !map_data.GetForestData(out forests))
            {
                forests = CreateSpacePos(forest_count, forest_min, forest_max, forest_dis, SpaceType.Forest);
                map_data.SetForestData(forests);
            }
            // 地块区域
            if (!readfile || !map_data.GetGroundData(out grounds, out triggers))
            {
                grounds  = new SpaceData[(citys.Length + forests.Length) * 2 + 1];
                triggers = new SpaceData[citys.Length + forests.Length];
                int create_area_idx = 0;
                for (int i = 0; i < citys.Length; i++)
                {
                    CreateGround(citys[i], grounds, create_area_idx, triggers);
                    create_area_idx += 1;
                }
                for (int i = 0; i < forests.Length; i++)
                {
                    CreateGround(forests[i], grounds, create_area_idx, triggers);
                    create_area_idx += 1;
                }
                map_data.SetGroundData(grounds, triggers);
                int     map_size  = this.map_size / 2 + map_edge;
                Vector3 map_pos   = new Vector3(map_size, sea_height, map_size);
                Vector3 sea_scale = new Vector3(this.map_size * 8 + 1000, 1, this.map_size * 8 + 1000);
                grounds[0] = new SpaceData(map_pos, sea_scale, SpaceType.Sea, useMeshScale: true);
            }
            BuildOperate sea_operate = new BuildOperate()
            {
                area_id = -1, state = GenerateState.CreateSea
            };

            EnqueueOperate(sea_operate); // 增加创建大海的操作
            if (isTrigger)
            {
                BuildOperate triiger_operate = new BuildOperate()
                {
                    area_id = -1, state = GenerateState.AreaTriiger
                };
                EnqueueOperate(triiger_operate); // 增加创建触发器的操作
            }
            else
            {
                int count = triggers.Length;
                for (int area_id = 0; area_id < count; area_id++)
                {
                    BuildOperate area_operate = new BuildOperate()
                    {
                        area_id = area_id, state = GenerateState.EnterArea
                    };
                    EnqueueOperate(area_operate); // 增加创建大陆的操作
                }
            }
        }