动态更换地形纹理图

更改terrain地形中的纹理贴图,代码如下:

public class TerrainTextureAssigner : MonoBehaviour
{
	public Texture2D[] TerrainTextures;//更换的纹理贴图
    public Texture2D[] PingChangTerrainTextures;//原纹理图
	private SplatPrototype[] oriPrototypes;
	private SplatPrototype[] newPrototypes;
	public Material mat;//地形的材质球
	private TerrainData terraindata;
	public Terrain terrain;
	private bool isIR = false;
	
	public void CreateTerrain(){
		newPrototypes = new SplatPrototype [TerrainTextures.Length];
		for (int i=0; i 0)
        {
            newPrototypes = new SplatPrototype[PingChangTerrainTextures.Length];
            for (int i = 0; i < PingChangTerrainTextures.Length; i++)
            {
                newPrototypes[i] = new SplatPrototype();
                //newPrototypes [i] = oriPrototypes [i];
                newPrototypes[i].texture = PingChangTerrainTextures[i];    //Sets the texture
                newPrototypes[i].texture.filterMode = FilterMode.Point;
                newPrototypes[i].normalMap = oriPrototypes[i].normalMap;
                newPrototypes[i].tileSize = oriPrototypes[i].tileSize;    //Sets the size of the texture            
            }
            terraindata.splatPrototypes = newPrototypes;
        }
    }
}


你可能感兴趣的:(Unity)