33 lines
956 B
C#
33 lines
956 B
C#
using UnityEngine;
|
|
|
|
namespace AmazingAssets.TerrainToMesh.Example
|
|
{
|
|
[RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))]
|
|
public class ExportMeshWithEdgeFall : MonoBehaviour
|
|
{
|
|
public TerrainData terrainData;
|
|
|
|
public int vertexCountHorizontal = 100;
|
|
|
|
public int vertexCountVertical = 100;
|
|
|
|
[Space(10f)]
|
|
public EdgeFall edgeFall = new EdgeFall(0f, true);
|
|
|
|
public Texture2D edgeFallTexture;
|
|
|
|
private void Start()
|
|
{
|
|
if (!(terrainData == null))
|
|
{
|
|
Mesh sharedMesh = terrainData.TerrainToMesh().ExportMesh(vertexCountHorizontal, vertexCountVertical, Normal.CalculateFromMesh, edgeFall);
|
|
GetComponent<MeshFilter>().sharedMesh = sharedMesh;
|
|
Material material = new Material(Shader.Find("Standard"));
|
|
Material material2 = new Material(Shader.Find("Standard"));
|
|
material2.SetTexture("_MainTex", edgeFallTexture);
|
|
GetComponent<Renderer>().sharedMaterials = new Material[2] { material, material2 };
|
|
}
|
|
}
|
|
}
|
|
}
|