コード例 #1
0
        private static Mesh CreateMesh(LandformRenderer renderer)
        {
            var collisionMesh = new Mesh();

            collisionMesh.name = MeshName;
            UpdateMesh(collisionMesh, renderer);
            return(collisionMesh);
        }
コード例 #2
0
ファイル: LandformChunk.cs プロジェクト: midgithub/KouXiaGu
        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);
        }
コード例 #3
0
        /// <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());
        }
コード例 #4
0
        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();
        }
コード例 #5
0
 private static void UpdateMesh(Mesh collisionMesh, LandformRenderer renderer)
 {
     collisionMesh.Clear();
     collisionMesh.vertices  = GetVertices(renderer);
     collisionMesh.triangles = triangles;
 }