如果网格支持读/写,则返回 true,否则返回 false。
当网格支持读/写时,Unity 会将网格数据上传到 GPU 可寻址内存,但也会将其保存在 CPU 可寻址内存中。当网格不支持读/写时,Unity 会将网格数据上传到 GPU 可寻址内存,然后从 CPU 可寻址内存中删除网格数据。
将模型导入 Unity 时,可以使用 Read/Write Enabled 复选框设置此值。要在运行时将值设置为 false,需设置 Mesh.UploadMeshData 的 markNoLongerReadable
参数。
在大多数情况下,应禁用此选项以节省运行时内存使用量。只有在以下情况下才能启此选项:
- 在代码中读取或写入网格数据。
- 将网格传递到 StaticBatchingUtility.Combine()
以在运行时合并网格。
- 将网格传递到 CanvasRenderer.SetMesh 时。
- 使用网格以在运行时使用 NavMesh 构建组件来烘焙 NavMesh。
- 当网格是凸面时,可将网格与网格碰撞体一起使用,并且网格碰撞体的变换具有负缩放(例如 (–1, 1, 1))。
- 将网格与网格碰撞体一起使用,并且网格碰撞体的变换倾斜或截断(例如,当旋转的变换具有缩放的父变换时)。
- 将网格与网格碰撞体一起使用并且网格碰撞体的 Cooking Options 标志设置为默认值以外的任何值时。
- 将网格与粒子系统的 Shape 模块或 Renderer 模块使用时(未使用 GPU 实例化时)。
请注意,在通过检视面板分配时,粒子系统会自动将网格更改为可读状态
注意:
当 Unity 通过脚本创建一个网格时,该值最初设置为 true。
未标记为可读的网格在运行时从脚本访问任何数据数组时将抛出错误。
在 Unity Editor 中,在游戏和渲染循环之外始终允许访问,无论此设置如何。
另请参阅:StaticBatchingUtility.Combine。
using UnityEngine; using System.Collections;
public class ExampleClass : MonoBehaviour { void Start() { Mesh mesh = GetComponent<MeshFilter>().sharedMesh; print(mesh.isReadable); } }
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.