Beispiel #1
0
        public static TerrainConfig get(TerrainConfig terrain_config_default)
        {
            TerrainConfig terrain_config = ConfigFile.load <TerrainConfig>(ConfigFile.terrainConfigFilename, terrain_config_default);

            terrain_config.actual_chunk_size = calcurate_actual_chunk_size(terrain_config.chunk_size);
            return(terrain_config);
        }
Beispiel #2
0
        public static TerrainEntity get(string terrain_name, TerrainConfig config, GameObject parent)
        {
            file_path = file_path.Replace("{terrain_name}", terrain_name);
            TerrainEntityCore core = ConfigFile.load <TerrainEntityCore>(file_path, default_entity_core);

            return(TerrainEntityFactory.createFromCore(core, config, parent));
        }
Beispiel #3
0
        public static void create()
        {
            GameObject    terrain_gameobject = GameObject.FindWithTag(terrain_gameobject_name);
            TerrainConfig terrain_config     = TerrainConfigRepository.get(TerrainConfigRepository.createDefault());
            WorldConfig   world_config       = (SceneService.transition_scene_data as AllowWorldCreate).world_config;

            //Debug.Log("terrain_seed: " + world_config.terrain_seed);

            TerrainService.reset(terrain_gameobject, terrain_config, world_config);

            Debug.Log("TerrainFactory.create: TerrainService.createUnityTerrains: ");
            TerrainService.createUnityTerrains();

            Debug.Log("TerrainFactory.create: TerrainService.setupTerrainCollection: ");
            TerrainService.setupTerrainCollection();

            Observable.FromCoroutine(x =>
                                     TerrainService.update(0, 0)
                                     ).Subscribe(x => {
                MessageBroker.Default.Publish(new TerrainCreated {
                });
            });

            MessageBroker.Default.Receive <playerTerrainChunkMove>().Subscribe(x => {
                Debug.Log("TerrainFactory.create: " + x.x + ", " + x.z);
                MainThreadDispatcher.StartCoroutine(TerrainService.update(x.x, x.z));
            });
        }
Beispiel #4
0
 public static TerrainEntity createFromCore(TerrainEntityCore core, TerrainConfig config, GameObject parent)
 {
     return(create(
                core.pos_x,
                core.pos_z,
                core.height_map,
                config,
                parent
                ));
 }
Beispiel #5
0
        private static TerrainData createTerrainData(TerrainConfig config)
        {
            TerrainData tData = new TerrainData();

            tData.size = new Vector3(config.actual_chunk_size, config.terrain_height, config.actual_chunk_size);
            tData.heightmapResolution = config.chunk_size;
            tData.baseMapResolution   = config.base_map_resolution;
            tData.SetDetailResolution(config.detail_resolution, config.resolution_per_path);

            return(tData);
        }
        public static TerrainCollection create(TerrainConfig terrain_config, int world_size)
        {
            int terrain_size = world_size / terrain_config.chunk_size;
            //Debug.Log("TerrainCollectionFactory.create: terrain_size: " + terrain_size);

            TerrainCollection terrain_collection = new TerrainCollection();

            terrain_collection.terrain_chunk_size   = terrain_size;
            terrain_collection.terrain_chunk_offset = Mathf.FloorToInt(terrain_size / 2);
            terrain_collection.terrain_pos_start    = terrain_collection.terrain_chunk_offset * -1;
            terrain_collection.terrain_pos_end      = terrain_collection.terrain_chunk_offset;
            return(terrain_collection);
        }
Beispiel #7
0
        public static void reset(GameObject game_object, TerrainConfig terrain_config, WorldConfig world_config)
        {
            terrain_parent = game_object;
            TerrainService.terrain_config = terrain_config;
            TerrainService.world_config   = world_config;
            terrain_collection            = TerrainCollectionFactory.create(terrain_config, world_config.world_size);
            TerrainEntityRepository.reset(world_config.world_name);

            texture = ConfigData.instantiate_texture2D(
                StrOpe.i + "/Resources/" + terrain_config.texture_filepath,
                terrain_config.detail_resolution,
                terrain_config.detail_resolution
                );
        }
Beispiel #8
0
        public static TerrainEntity create(int x, int z, float[,] heights, TerrainConfig config, GameObject parent)
        {
            GameObject  game_object = createGameObject("Terrain-" + x + "-" + z, parent);
            TerrainData tData       = createTerrainData(config);

            tData.SetHeights(0, 0, heights);
            game_object.GetComponent <UnityTerrain>().terrainData    = tData;
            game_object.GetComponent <TerrainCollider>().terrainData = tData;
            game_object.transform.position = new Vector3(x * config.chunk_size, 0f, z * config.chunk_size);

            TerrainEntity entity = new TerrainEntity(
                x,
                z,
                heights,
                config.terrain_height,
                game_object,
                game_object.GetComponent <UnityTerrain>()
                );

            return(entity);
        }
Beispiel #9
0
 public static bool set(TerrainConfig terrain_config)
 {
     return(ConfigFile.save <TerrainConfig>(ConfigFile.terrainConfigFilename, terrain_config));
 }