安装方式
1.github https://github.com/dbrizov/NaughtyAttributes
2. AssetStore https://assetstore.unity.com/packages/tools/utilities/naughtyattributes-129996
常用特性
用法展示
Reorderablelist 数组可重排
public class NaughtyComponent : MonoBehaviour
{
[ReorderableList]
public int[] intArray;
[ReorderableList]
public List<float> floatArray;
}
Button 按钮
public class NaughtyComponent : MonoBehaviour
{
[Button]
private void MethodOne() { }
[Button("Button Text")]
private void MethodTwo() { }
}
BoxGroup 方框分组
public class NaughtyComponent : MonoBehaviour
{
[BoxGroup("Integers")]
public int firstInt;
[BoxGroup("Integers")]
public int secondInt;
[BoxGroup("Floats")]
public float firstFloat;
[BoxGroup("Floats")]
public float secondFloat;
}
ShowIf / HideIf 显示/隐藏
public class NaughtyComponent : MonoBehaviour
{
public bool showInt;
[ShowIf("showInt")]
public int myInt;
[ShowIf("AlwaysShow")]
public float myFloat;
[ShowIf("NeverShow")]
public Vector3 myVector;
public bool AlwaysShow() { return true; }
public bool NeverShow => false;
}
ShowAssetPreview 显示预制体
public class NaughtyComponent : MonoBehaviour
{
[ShowAssetPreview]
public Sprite sprite;
[ShowAssetPreview(128, 128)]
public GameObject prefab;
}
Foldout 折叠
public class NaughtyComponent : MonoBehaviour
{
[Foldout("Integers")]
public int firstInt;
[Foldout("Integers")]
public int secondInt;
}
CurveRange 曲线
public class NaughtyComponent : MonoBehaviour
{
[CurveRange(-1, -1, 1, 1)]
public AnimationCurve curve;
[CurveRange(EColor.Orange)]
public AnimationCurve curve1;
[CurveRange(0, 0, 5, 5, EColor.Red)]
public AnimationCurve curve2;
}
EnumFlags 多选枚举
public enum Direction
{
None = 0,
Right = 1 << 0,
Left = 1 << 1,
Up = 1 << 2,
Down = 1 << 3
}
public class NaughtyComponent : MonoBehaviour
{
[EnumFlags]
public Direction flags;
}
Required 要求对象不为空
public class NaughtyComponent : MonoBehaviour
{
[Required]
public Transform myTransform;
[Required("Custom required text")]
public GameObject myGameObject;
}
InfoBox 提示盒信息
public class NaughtyComponent : MonoBehaviour
{
[InfoBox("This is my int", EInfoBoxType.Normal)]
public int myInt;
[InfoBox("This is my float", EInfoBoxType.Warning)]
public float myFloat;
[InfoBox("This is my vector", EInfoBoxType.Error)]
public Vector3 myVector;
}
EnableIf / DisableIf 是否可以被修改
public class NaughtyComponent : MonoBehaviour
{
public bool enableMyInt;
[EnableIf("enableMyInt")]
public int myInt;
[EnableIf("Enabled")]
public float myFloat;
[EnableIf("NotEnabled")]
public Vector3 myVector;
public bool Enabled() { return true; }
public bool NotEnabled => false;
}
更多用法查看github文档,以及插件里的例子Scene