Unity-NaughtAttributes
Special Attributes
AllowNesting
Struct需要嵌套时使用
Drawer Attributes
Animator显示下拉参数
public Animator someAnimator;
[AnimatorParam("someAnimator")]
public int paramHash;
Button直接执行函数
[Button("Button Text")]
private void MethodTwo() { }
AnimationCurves
[CurveRange(0, 0, 5, 5, EColor.Red)]
public AnimationCurve curve2;
Dropdown
[Dropdown("intValues")]
public int intValue;
private int[] intValues = new int[] { 1, 2, 3, 4, 5 };
EnumFlags
public enum Direction
{
None = 0,
B = 1 << 0,
C = 1 << 1,
D = 1 << 2,
E = 1 << 3,
F = 1 << 4,
G = 1 << 5,
H = 1 << 6,
I = 1 << 7,
J = 1 << 8,
k = 1 << 9,
All = ~0
}
public class NaughtyComponent : MonoBehaviour
{
[EnumFlags]
public Direction flags;
}
Expandable
ScriptableObject可展开
HorizontalLine(height, color)
分割线
InfoBox
信息提示框
[InfoBox("Normal", EInfoBoxType.Normal)]
[InfoBox("Warning", EInfoBoxType.Warning)]
[InfoBox("Error", EInfoBoxType.Error)]
InputAxis
输入系统下拉框
[InputAxis]
public string inputAxis0;
Layer/SortingLayer/Tag
层级下拉[Layer][SortingLayer]
支持string layername和int layerindex
MinMaxSlider
[MinMaxSlider(0.0f, 100.0f)]
public Vector2 minMaxSlider;
ProgressBar进度条
[ProgressBar("Health", 300, EColor.Red)]
ReorderableList
可重排序list, [ReorderableList]
ShowAssetPreview
显示Sprite, Prefab,Texture缩略图
ShowNativeProperty
显示属性,仅支持以下类型
bool, int, long, float, double, string, Vector2, Vector3, Vector4, Color, Bounds, Rect, UnityEngine.Object;
Nest中无法显示属性;
属性显示的顺序在字段后;
ShowNonSerializedField
显示私有字段,且使其不可更改;
Meta Attributes元组特性
BoxGroup
[BoxGroup("Integers")]
public int firstInt;
[BoxGroup("Integers")]
public int secondInt;
Foldout
[Foldout("Integers")]
public int firstInt;
[Foldout("Integers")]
public int secondInt;
EnableIf / DisableIf
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;
//多个条件
public bool flag0;
public bool flag1;
[EnableIf(EConditionOperator.And, "flag0", "flag1")]
public int enabledIfAll;
[EnableIf(EConditionOperator.Or, "flag0", "flag1")]
public int enabledIfAny;
ShowIf / HideIf
public bool showInt;
[ShowIf("showInt")]
public int myInt;
Label
[Label("Short Name")]
public string veryVeryLongName;
OnValueChanged
[OnValueChanged("OnValueChangedCallback")]
public int myInt;
private void OnValueChangedCallback()
{
Debug.Log(myInt);
}
ReadOnly
[ReadOnly]
public Vector3 forwardVector = Vector3.forward;
Validator Attributes
MinValue / MaxValue
[MinValue(0), MaxValue(10)]
public int myInt;
[MinValue(0.0f)]
public float myFloat;
Required
[Required]
public Transform myTransform;
[Required("Custom required text")]
public GameObject myGameObject;
ValidateInput
[ValidateInput("IsNotNull")]
public Transform myTransform;
[ValidateInput("IsGreaterThanZero", "myInteger must be greater than zero")]
public int myInt;
private bool IsNotNull(Transform tr)
{
return tr != null;
}
private bool IsGreaterThanZero(int value)
{
return value > 0;
}
Life is too short for so much sorrow.
本博客所有文章除特别声明外,均采用
CC BY-NC-SA 4.0 许可协议。转载请注明来自 小紫苏!