public Mesh mesh ;

Description

返回指定给网格过滤器的实例化 Mesh

如果没有为网格过滤器指定网格,则会创建并指定新的网格。

If a mesh is assigned to the mesh filter already, then first query of mesh property will create a duplicate of it, and this copy will be returned. Further queries of mesh property will return this duplicated mesh instance. Once mesh property is queried, link to the original shared mesh is lost and MeshFilter.sharedMesh property becomes an alias to mesh. If you want to avoid this automatic mesh duplication, use MeshFilter.sharedMesh instead.

使用 mesh 属性只能修改单个对象的网格。使用 相同网格的其他对象不会进行修改。

It is your responsibility to destroy the automatically instantiated mesh when the game object is being destroyed. Resources.UnloadUnusedAssets also destroys the mesh but it is usually only called when loading a new level.

mesh 属性视为以下代码的快捷方式:

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { void Start() { Mesh mesh = GetComponent<MeshFilter>().sharedMesh; Mesh mesh2 = Instantiate(mesh); GetComponent<MeshFilter>().sharedMesh = mesh2; } }

mesh 属性的第一个查询时调用的内容。

Note:
If MeshFilter is a part of an asset object, quering mesh property is not allowed and only asset mesh can be assigned.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { // Distorts the mesh vertically. void Update() { // Get instantiated mesh Mesh mesh = GetComponent<MeshFilter>().mesh; // Randomly change vertices Vector3[] vertices = mesh.vertices; int p = 0; while (p < vertices.Length) { vertices[p] += new Vector3(0, Random.Range(-0.3F, 0.3F), 0); p++; } mesh.vertices = vertices; mesh.RecalculateNormals(); } }

另请参阅:Mesh 类。