public void CreateTerrainButton() { WorldCreationSettings worldCreationSettings = ScriptableObject.CreateInstance <WorldCreationSettings>(); worldCreationSettings.m_xTiles = xTiles; worldCreationSettings.m_zTiles = zTiles; worldCreationSettings.m_tileSize = tileSize; worldCreationSettings.m_tileHeight = tileHeight; worldCreationSettings.m_seaLevel = seaLevel; worldCreationSettings.m_createInScene = createTerrainsInScenes; worldCreationSettings.m_autoUnloadScenes = autoUnloadScenes; worldCreationSettings.m_applyFloatingPointFix = applyFloatingPointFix; //worldCreationSettings.m_gaiaDefaults = new GaiaDefaults(); //worldCreationSettings.m_spawnerPresetList = new List<BiomeSpawnerListEntry>() { } GaiaSessionManager.CreateWorld(worldCreationSettings, executeWorldCreation); }
public void CreateWorldMapTerrain() { //Remove old world map terrain, if any Terrain oldWMTerrain = TerrainHelper.GetWorldMapTerrain(); if (oldWMTerrain != null) { #if UNITY_EDITOR if (EditorUtility.DisplayDialog("Delete old world map?", "You are about to create a new world map in this scene. This will delete the existing world map and the stamp tokens on it. This will only affect the small world map terrain, the actual full scene terrain tiles will not be removed. Continue?", "Continue", "Cancel")) { DestroyImmediate(oldWMTerrain.gameObject); } else { return; } #else Destroy(oldWMTerrain.gameObject); #endif } GaiaSettings gaiaSettings = GaiaUtils.GetGaiaSettings(); GaiaDefaults currentDefaults = gaiaSettings.m_currentDefaults; GaiaSessionManager gsm = GaiaSessionManager.GetSessionManager(); //Collect some info from the existing world, if any. //We need the average height from the terrains to create the height of the worldmap accordingly in scale double averageHeight = currentDefaults.m_terrainHeight; //We need the heightmap resolution and terrain size stored in the session //To properly scale between world map and local map even when one of the two is not loaded at the moment int count = 0; foreach (Terrain t in Terrain.activeTerrains) { averageHeight += t.terrainData.size.y; if (!TerrainHelper.IsWorldMapTerrain(t)) { m_localHeightmapRes = t.terrainData.heightmapResolution; m_localTileSize = t.terrainData.size.x; } count++; } //} //only calculate an average if there is at least one placeholder or terrain if (count > 0) { averageHeight /= count; } BoundsDouble bounds = new BoundsDouble(); TerrainHelper.GetTerrainBounds(ref bounds); //Collect the new world settings for world creation WorldCreationSettings worldCreationSettings = ScriptableObject.CreateInstance <WorldCreationSettings>(); worldCreationSettings.m_xTiles = 1; worldCreationSettings.m_zTiles = 1; worldCreationSettings.m_tileSize = (count > 0) ? Mathd.RoundToInt(bounds.size.x) : gaiaSettings.m_tilesX * currentDefaults.m_terrainSize; worldCreationSettings.m_tileHeight = currentDefaults.m_terrainHeight; worldCreationSettings.m_createInScene = false; worldCreationSettings.m_autoUnloadScenes = false; worldCreationSettings.m_applyFloatingPointFix = false; worldCreationSettings.m_applyFloatingPointFix = false; worldCreationSettings.m_centerOffset = Vector3.zero; //(count > 0) ? new Vector2Double(bounds.center.x + bounds.extents.x + worldCreationSettings.m_tileSize, bounds.center.z) : Vector2Double.zero; worldCreationSettings.m_isWorldMap = true; //clone defaults so we can inject our custom heightmap resolution for the worldmap GaiaDefaults clonedDefaults = Instantiate(currentDefaults); clonedDefaults.m_heightmapResolution = (int)m_heightmapResolution; worldCreationSettings.m_gaiaDefaults = clonedDefaults; m_currentWorldCreationSettings = worldCreationSettings; GaiaSessionManager.OnWorldCreated -= OnWorldMapCreate; GaiaSessionManager.OnWorldCreated += OnWorldMapCreate; GaiaSessionManager.CreateWorld(worldCreationSettings); }