Beispiel #1
0
        public void BuildGameObject(BuildOperate operate)
        {
            try {
                debug_test += "\n增加协程 " + operate.state + " " + operate.area_id + "/" + area_id + "  " + new System.Diagnostics.StackTrace();
                switch (operate.state)
                {
                case GenerateState.Wall:
                    coroutines.Add(operate.state, generate.StartCoroutine(BuildWorld(operate.state, wall_datas)));
                    break;

                case GenerateState.House:
                    coroutines.Add(operate.state, generate.StartCoroutine(BuildWorld(operate.state, house_datas)));
                    break;

                case GenerateState.Tree:
                    coroutines.Add(operate.state, generate.StartCoroutine(BuildWorld(operate.state, tree_datas)));
                    break;

                case GenerateState.Decorate:
                    coroutines.Add(operate.state, generate.StartCoroutine(BuildWorld(operate.state, decorate_datas)));
                    break;
                }
            } catch (System.Exception) {
                Debug.LogError(debug_test);
                throw;
            }
        }
Beispiel #2
0
        private void Update()
        {
            BuildOperate cur_operate = DequeueOperate();

            if (cur_operate != null)
            {
                switch (cur_operate.state)
                {
                case GenerateState.AreaTriiger:
                    Debug.Log("开始检测触发");
                    StartCoroutine(TriggerDetection());
                    //StartCoroutine(BuildWorld(triggers));
                    break;

                case GenerateState.CreateSea:
                    CreateWorldGameObject(grounds[0], -1);
                    break;

                case GenerateState.EnterArea:
                    EnterArea(cur_operate.area_id);
                    break;

                default:
                    if (area_generates.ContainsKey(cur_operate.area_id))
                    {
                        GenerateArea area = area_generates[cur_operate.area_id];
                        area.BuildGameObject(cur_operate);
                    }
                    break;
                }
            }
        }
Beispiel #3
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); // 增加创建植物的操作
        }
Beispiel #4
0
 BuildOperate DequeueOperate()
 {
     lock (build_operates) {
         if (build_operates.Count < 1)
         {
             return(null);
         }
         else
         {
             BuildOperate item = build_operates[0];
             build_operates.RemoveAt(0);
             return(item);
         }
     }
 }
Beispiel #5
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); // 增加创建大陆的操作
                }
            }
        }
Beispiel #6
0
 public void EnqueueOperate(BuildOperate operate)
 {
     lock (build_operates) {
         build_operates.Add(operate);
     }
 }