public static void CreateTerrain() { IRTE editor = IOC.Resolve <IRTE>(); TerrainData terrainData = new TerrainData(); terrainData.SetDetailResolution(1024, 32); terrainData.heightmapResolution = 513; terrainData.size = new Vector3(200, 20, 200); terrainData.terrainLayers = new[] { #if UNITY_2019_2 //2019.2.12 unity terrain issue fix (2 same layers to make texture visibile) new TerrainLayer() { diffuseTexture = (Texture2D)Resources.Load("Textures/RTT_DefaultGrass") }, #endif new TerrainLayer() { diffuseTexture = (Texture2D)Resources.Load("Textures/RTT_DefaultGrass") } }; GameObject go = Terrain.CreateTerrainGameObject(terrainData); go.isStatic = false; if (go != null) { editor.AddGameObjectToScene(go); } }
public static void CreateTerrain() { IRTE editor = IOC.Resolve <IRTE>(); TerrainData terrainData = TerrainDataExt.DefaultTerrainData(); GameObject terrainObject = Terrain.CreateTerrainGameObject(terrainData); if (RenderPipelineInfo.Type != RPType.Standard) { terrainObject.GetComponent <Terrain>().materialTemplate = RenderPipelineInfo.DefaultTerrainMaterial; } terrainObject.isStatic = false; if (terrainObject != null) { editor.AddGameObjectToScene(terrainObject); } }
public static void CreateTerrain() { IRTE editor = IOC.Resolve <IRTE>(); TerrainData terrainData = new TerrainData(); terrainData.SetDetailResolution(1024, 32); terrainData.heightmapResolution = 513; terrainData.size = new Vector3(200, 20, 200); ITerrainSettings terrainSettings = IOC.Resolve <ITerrainSettings>(); terrainData.terrainLayers = new[] { new TerrainLayer() { diffuseTexture = terrainSettings != null ? terrainSettings.DefaultTexture : (Texture2D)Resources.Load("Textures/RTT_DefaultGrass") } }; float[,,] alphaMaps = terrainData.GetAlphamaps(0, 0, terrainData.alphamapWidth, terrainData.alphamapHeight); int amapY = alphaMaps.GetLength(0); int amapX = alphaMaps.GetLength(1); for (int y = 0; y < amapY; y++) { for (int x = 0; x < amapX; x++) { alphaMaps[y, x, 0] = 1; } } terrainData.SetAlphamaps(0, 0, alphaMaps); GameObject go = Terrain.CreateTerrainGameObject(terrainData); go.isStatic = false; if (go != null) { editor.AddGameObjectToScene(go); } }