Unity 常用 Attribute todo
csharp
// 首次打开 Unity 工程时,以及代码被重新编译时
[InitializeOnLoad]
// 被修饰的 MonoBehaviour 会在编辑器模式下运行,例如其中的 Start() 方法
[ExecuteInEditMode]
// 禁止在同一个 GameObject 添加多个该脚本
[DisallowMultipleComponent]
// 给 IComponentData 和 IBufferElementData 自动生成 Authoring 的逻辑
[GenerateAuthoringComponent]
// 被该特性修饰的 MonoBehaviour 所挂载的物体也必须同时挂载 xxx 类型
[RequireComponent(typeof(xxx))]
// 在 Inspector 中显示被修饰的字段,且使其可被序列化
[SerializeField]
// 在 Inspector 中隐藏
[HideInInspector]
// 用于修饰枚举中元素,使得被修饰的元素在 Inspector 中以别名显示
[InspectorName("name")]
// 显示在 Inspector 中作为被修饰字段的标题
[Head("name")]
// 限制被修饰的字段在 Inspector 中的可调范围,并以滑动条的形式显示
[Range(-100, 100)]
// 限制被修饰字段在 Inspector 中的最小值
[Min(min: 1F)]
// 禁止可枚举字段在 Inspector 中的重排序
[NonReorderable]
// 被修饰的 Color 类型字段在 Inspector 中是否可调节 Alpha,是否可设置 HDR 颜色
[ColorUsage(showAlpha: false, hdr: true)]
// 被修饰的 Gradient 类型字段在 Inspector 中是否可设置 HDR,处于哪种色彩空间
[GradientUsage(hdr: false, ColorSpace.Gamma)]
// 被修饰的字段在 Inspector 中相比于上一个字段的间隔
[Space]
[Space(height: 9F)]
// 用于修饰 string 类型的字段,使其在 Inspector 中以文字输入框的形式显示
[TextArea]
[TextArea(minLines: 3, maxLines: 3)]
// 鼠标移动到 Inspector 上悬停会显示被修饰字段的相关描述
[Tooltip("description")]
// 在 Inspector 面板中右键调用被修饰的方法
[ContextMenu("method name")]
// 用于修饰字段,在 Inspector 中右键字段可以调用方法
[ContextMenuItem("display name", "method name")]
// 在工程目录中右键空白处,Create 中,创建新的文件
[CreateAssetMenu(fileName = "name", menuName = "directory/name", order = 0)]
// 在 Inspectory 中点击 AddComponent,可以在指定目录中创建该脚本
[AddComponentMenu("directory/name")]
// 修改被序列化的变量名时, 为了不丢失引用
[UnityEngine.Serialization.FormerlySerializedAs("xxx")]