Is there a simple example script from start to end, that can load textures from resource files and set alpha maps using the APIs in unity 2019/2020?
The documentation out there is very poor, frustrating, and confusing me, no simple example
public class myTerrainScript1 : MonoBehaviour
{
private TerrainData _terrainData;
private float[,] _heights; // [0,1] normalized heights
SplatPrototype[ ] terrainTexture;
TerrainLayer[ ] terrainLayers;
// Start is called before the first frame update
void Start()
{
Debug.Log(“Start()”);
// terrainData stores the heightmaps of the terrain
// textures, trees and other important terrain details.
_terrainData = terrain.terrainData;
Debug.Log(“Terrain Size world Coordnates:\n” +
“X axis = terrain width =” +
_terrainData.size.x +
" Z axis = terrain length =" +
_terrainData.size.z + " Y axis = terrain height =" +
_terrainData.size.y);
// Useful for application
string sAppDataPath = Application.persistentDataPath;
string sAppStreamingAssetsPath = Application.streamingAssetsPath;
DirectoryInfo dIassets = Directory.GetParent(sAppStreamingAssetsPath);
string sAppAssetsPath = dIassets.FullName;
string texturePath = sAppAssetsPath + @“\SurfaceTextures”; //Materials";
string textureFile = texturePath + @“\MudRockyNormals”;
// string textureFile = “MudRockyNormals”;
terrainTexture = new SplatPrototype[6];
terrainLayers = new TerrainLayer[6];
// Loading resource file: Load a Texture (Assets/Resources/Textures/texture01.png)
// Audio/clip, Text/JSONfile , Text/Textfile, Sprites/mmmm (mmmm.png)
// Unity - Scripting API: Resources.Load
terrainTexture[0] = new SplatPrototype();
terrainTexture[1] = new SplatPrototype();
terrainTexture[2] = new SplatPrototype();
terrainTexture[3] = new SplatPrototype();
terrainTexture[4] = new SplatPrototype();
terrainTexture[5] = new SplatPrototype();
// Load the resources, these are the terrain textures that are supported.
terrainTexture[0].texture = Resources.Load(“Textures/SandAlbedo”);
terrainTexture[1].texture = Resources.Load(“Textures/GrassHillAlbedo”);
terrainTexture[2].texture = Resources.Load(“Textures/GrassRockyAlbedo”);
terrainTexture[3].texture = Resources.Load(“Textures/CliffAlbedoSpecular”);
terrainTexture[4].texture = Resources.Load(“Textures/MudRockyNormals”);
terrainTexture[5].texture = Resources.Load(“Textures/MudRockyAlbedoSpecular”);
// This causes an error in UNITY 2020
_terrainData.splatPrototypes = terrainTexture;
}
}
thank you
Joseph