Returns either a new mesh or a duplicate of the existing mesh, and assigns it to the mesh filter.
如果没有为网格过滤器指定网格,则会创建并指定新的网格。
If a mesh is assigned to the mesh filter already, then the 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
属性只能修改单个对象的网格。使用
相同网格的其他对象不会进行修改。
由您负责在游戏对象销毁时将自动实例化网格销毁。Resources.UnloadUnusedAssets
也会销毁网格,但是通常仅当加载新关卡时调用。
将 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
属性的第一个查询时调用的内容。
**注意:**\
如果 MeshFilter 是资源对象的一部分,则不允许查询 mesh
属性,只能指定资源网格。
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 类。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.