combine | 要合并的网格的描述。 |
mergeSubMeshes | Defines whether Meshes should be combined into a single sub-Mesh. |
useMatrices | 定义是应使用还是忽略在 CombineInstance 数组中提供的变换。 |
将多个网格合并到此网格中。
合并网格对性能优化很有用。
If mergeSubMeshes
is true, all the Meshes are combined to a single sub-Mesh. Otherwise, each Mesh
goes into a different sub-Mesh. If all Meshes share the same Material, set this to true.
如果 useMatrices
为 true,则使用 CombineInstance 结构中的变换矩阵。否则,忽略它们。
将 hasLightmapData
设置为 true 可按 CombineInstance 结构中的光照贴图缩放偏移数据变换输入网格光照贴图 UV 数据。网格必须共享相同的光照贴图纹理。
using UnityEngine; using System.Collections;
[RequireComponent(typeof(MeshFilter))] [RequireComponent(typeof(MeshRenderer))] public class ExampleClass : MonoBehaviour { void Start() { MeshFilter[] meshFilters = GetComponentsInChildren<MeshFilter>(); CombineInstance[] combine = new CombineInstance[meshFilters.Length]; int i = 0; while (i < meshFilters.Length) { combine[i].mesh = meshFilters[i].sharedMesh; combine[i].transform = meshFilters[i].transform.localToWorldMatrix; meshFilters[i].gameObject.active = false; i++; } transform.GetComponent<MeshFilter>().mesh = new Mesh(); transform.GetComponent<MeshFilter>().mesh.CombineMeshes(combine); transform.gameObject.active = true; } }