文档

Unity Engine

Unity Engine

Unity 特性

Use Unity-specific C# attributes to define special behavior for your code.
阅读时间1 分钟最后更新于 1 个月前

C# 中的特性 (Attribute) 是可以放在类、属性或方法声明上方来指示特殊行为的元数据标记。
.NET 库中定义了许多特性,Unity 也提供了大量特定于 Unity 的自定义特性。例如,可以将
HideInInspector
特性添加到属性声明上方,从而防止检视面板 (Inspector) 显示该属性(即使是公共属性)。特性在声明上方的方括号中指定,形式如下:
[HideInInspector]public float strength;
有关
UnityEngine
特性的完整列表,请参阅脚本 API 参考中的 UnityEngine > 特性 (Attributes) 下方列表,该列表以 AddComponentMenu 开头。
有关
UnityEditor
属性的完整列表,请参阅脚本 API 参考中的 UnityEditor > 特性 (Attributes) 下方列表,该列表以 AssetPostprocessorStaticVariableIgnoreAttribute 开头。
**注意:**请勿使用 .NET ThreadStatic 特性,因为如果将 .NET ThreadStatic 特性添加到 Unity 脚本中,则会导致崩溃。

其他资源