private static Mesh CreateMesh(LandformRenderer renderer) { var collisionMesh = new Mesh(); collisionMesh.name = MeshName; UpdateMesh(collisionMesh, renderer); return(collisionMesh); }
private void Awake() { MeshFilter meshFilter = GetComponent <MeshFilter>(); MeshRenderer meshRenderer = GetComponent <MeshRenderer>(); MeshCollider meshCollider = GetComponent <MeshCollider>(); Mesh = new LandformMesh(meshFilter); Renderer = new LandformRenderer(meshRenderer); Collider = new LandformCollider(meshCollider, Renderer); }
/// <summary> /// 获取到高度对应的顶点坐标; /// </summary> private static Vector3[] GetVertices(LandformRenderer renderer) { List <Vector3> vertices = new List <Vector3>(); foreach (var pair in LandformCollider.vertices) { Vector3 vertice = pair.Key; vertice.y = renderer.GetHeight(pair.Value); vertices.Add(vertice); } return(vertices.ToArray()); }
public LandformCollider(MeshCollider meshCollider, LandformRenderer renderer) { if (meshCollider == null) { throw new ArgumentNullException(nameof(meshCollider)); } if (renderer == null) { throw new ArgumentNullException(nameof(renderer)); } this.meshCollider = meshCollider; this.renderer = renderer; meshCollider.sharedMesh = collisionMesh = new Mesh(); }
private static void UpdateMesh(Mesh collisionMesh, LandformRenderer renderer) { collisionMesh.Clear(); collisionMesh.vertices = GetVertices(renderer); collisionMesh.triangles = triangles; }