private static void Restore() { if (!HasValidTerrain()) { return; } Debug.Log("Script reload detected. Attempting to restore texture data..."); string path = Path.Combine(Application.dataPath, "splat.bytes"); if (File.Exists(path)) { TerrainMap <byte> byteMap = new TerrainMap <byte>(File.ReadAllBytes(path), 8); Splat = new SplatMap(byteMap); File.Delete(path); Debug.Log("Restored Splat Maps"); } path = Path.Combine(Application.dataPath, "biome.bytes"); if (File.Exists(path)) { TerrainMap <byte> byteMap = new TerrainMap <byte>(File.ReadAllBytes(path), 4); Biome = new BiomeMap(byteMap); File.Delete(path); Debug.Log("Restored Biome Maps"); } path = Path.Combine(Application.dataPath, "alpha.bytes"); if (File.Exists(path)) { TerrainMap <byte> byteMap = new TerrainMap <byte>(File.ReadAllBytes(path), 1); Alpha = new AlphaMap(byteMap); File.Delete(path); Debug.Log("Restored Alpha Maps"); } path = Path.Combine(Application.dataPath, "topology.bytes"); if (File.Exists(path)) { TerrainMap <int> byteMap = new TerrainMap <int>(File.ReadAllBytes(path), 1); Topology = new TopologyMap(byteMap); File.Delete(path); Debug.Log("Restored Topology Maps"); } path = Path.Combine(Application.dataPath, "water.bytes"); if (File.Exists(path)) { TerrainMap <short> byteMap = new TerrainMap <short>(File.ReadAllBytes(path), 1); Water = new WaterMap(byteMap); File.Delete(path); Debug.Log("Restored Water Maps"); } }
public IEnumerator Load(World.Data world) { ActionProgressBar.UpdateProgress("Loading Terrain", 0f); yield return(null); yield return(null); Splat = new SplatMap(world.splatMap); Alpha = new AlphaMap(world.alphaMap); Biome = new BiomeMap(world.biomeMap); Topology = new TopologyMap(world.topologyMap); Water = new WaterMap(world.waterMap); TerrainData terrainData = new TerrainData(); terrainData.alphamapResolution = Mathf.Clamp(Mathf.NextPowerOfTwo((int)(world.size.x * 0.50f)), 16, 2048); terrainData.baseMapResolution = Mathf.NextPowerOfTwo((int)((float)(world.size.x) * 0.01f)); terrainData.heightmapResolution = Mathf.NextPowerOfTwo((int)((float)(world.size.x) * 0.5f)) + 1; terrainData.size = world.size; terrainData.SetHeights(0, 0, world.landHeightMap); Terrain = Terrain.CreateTerrainGameObject(terrainData).GetComponent <Terrain>(); Terrain.name = Terrain.tag = "Terrain"; Terrain.gameObject.layer = 8; Terrain.transform.position = -0.5f * terrainData.size; Terrain.gameObject.AddComponent <PositionLock>(); SetSplatMaps(PaintType.Splat); CreateWaterPlane(world.size.x); }