コード例 #1
0
        public void UpdateMeshTerrain(Vector2 _viewerPosition)
        {
            viewerDstFromNearestEdge = Vector3.Distance(new Vector3(_viewerPosition.x, 0, _viewerPosition.y), meshObject.transform.position);

            int lodIndex = 0;

            //check which levelOfDetail we should have
            for (int i = 0; i < detailLevels.Length - 1; i++)
            {
                if (viewerDstFromNearestEdge > detailLevels[i].visibleDstThreshold)
                {
                    lodIndex = i + 1;
                }
                else
                {
                    break;
                }
            }

            //update the mesh if lodIndex has changed
            if (lodIndex != previousLODIndex)
            {
                LODMesh lodMesh = lodMeshes[lodIndex];
                previousLODIndex = lodIndex;
                if (lodMesh.hasMesh)
                {
                    meshFilter.mesh = lodMesh.mesh;
                }
                else
                {
                    lodMesh.GenerateLODMesh(noiseMap, meshHeightMultiplier, heightCurve);
                    meshFilter.mesh = lodMesh.mesh;
                }
            }

            //the plane the player walks on gets a mesh
            if (lodIndex == 0)
            {
                if (!collisionLODMesh.hasMesh)
                {
                    collisionLODMesh.GenerateLODMesh(noiseMap, meshHeightMultiplier, heightCurve);
                    meshCollider.sharedMesh = collisionLODMesh.mesh;
                }
                else
                {
                    meshCollider.sharedMesh = collisionLODMesh.mesh;
                }
            }
            else
            {
                meshCollider.sharedMesh = null;
            }
        }