Unity 的属性扩展
NaughtyAttributes 是一个 Unity Inspector 的扩展。
它扩展了 Unity 提供的属性(Attribute)范围,让你无需编写自定义编辑器或属性绘制器(Property Drawer)即可创建功能强大的 Inspector。它还提供了可应用于非序列化字段或函数的属性。
大多数特性都是通过 Unity 的 CustomPropertyDrawer 实现的,因此它们可以在你的自定义编辑器中使用。
在你的自定义编辑器中无法使用的特性是元特性(meta attributes)以及一些 drawer 特性,例如
ReorderableList、Button、ShowNonSerializedField 和 ShowNativeProperty。
不过,如果你希望所有特性都能在你的自定义编辑器中使用,你必须继承 NaughtyInspector,并使用 NaughtyEditorGUI.PropertyField_Layout 函数来代替 EditorGUILayout.PropertyField。
NaughtyAttributes 需要 2022.3 或更高版本。
openupm add com.dbrizov.naughtyattributes"com.dbrizov.naughtyattributes": "https://github.com/dbrizov/NaughtyAttributes.git#upm"在某些情况下,当你希望元特性(meta attributes)在可序列化的嵌套结构体或类中生效时,必须使用此特性。 你可以在这里查看哪些情况需要使用它。
public class NaughtyComponent : MonoBehaviour
{
public MyStruct myStruct;
}
[System.Serializable]
public struct MyStruct
{
public bool enableFlag;
[EnableIf("enableFlag")]
[AllowNesting] // Because it's nested we need to explicitly allow nesting
public int integer;
}为序列化字段提供特殊的绘制选项。
暂无开放 Issues,或尚未同步最近议题。