はじめに
「NaughtyAttributes」を Unity プロジェクトに導入することで
26個の PropertyAttribute が使用できるようになります
目次
- はじめに
- 目次
- Slider
- MinMaxSlider
- ReorderableList
- Button
- Dropdown
- ResizableTextArea
- ShowNonSerializedField
- ShowNativeProperty
- ReadOnly
- ShowAssetPreview
- ShowIf / HideIf
- BoxGroup
- MinValue / MaxValue
- Required
- ValidateInput
- Section
- BlankSpace
- InfoBox
- OnValueChanged
- 関連記事
Slider
public class NaughtyComponent : MonoBehaviour { [Slider( 0, 10 )] public int intSlider; [Slider( 0f, 10f )] public float floatSlider; }
MinMaxSlider
public class NaughtyComponent : MonoBehaviour { [MinMaxSlider( 0f, 100f )] public Vector2 minMaxSlider; }
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 MethodOne() {} }
Dropdown
public class NaughtyComponent : MonoBehaviour { [Dropdown( "intValues" )] public int intValue; [Dropdown( "stringValues" )] public string stringValue; [Dropdown( "vectorValues" )] public Vector3 vectorValue; private int[] intValues = new [] { 1, 2, 3, 4, 5 }; private string[] stringValues = new [] { "A", "B", "C", "D", "E" }; private DropdownList<Vector3> vectorValues = new DropdownList<Vector3> { { "Right" , Vector3.right }, { "Left" , Vector3.left }, { "Up" , Vector3.up }, { "Down" , Vector3.down }, { "Forward", Vector3.forward }, { "Back" , Vector3.back }, }; }
ResizableTextArea
public class NaughtyComponent : MonoBehaviour { [ResizableTextArea] public string resizableTextArea; }
ShowNonSerializedField
public class NaughtyComponent : MonoBehaviour { [ShowNonSerializedField] private int myInt = 10; [ShowNonSerializedField] private const float PI = 3.14159f; [ShowNonSerializedField] private static readonly Vector3 CONST_VECTOR = new Vector3( 1, 1, 1 ); }
ShowNativeProperty
public class NaughtyComponent : MonoBehaviour { public List<Transform> transforms; [ShowNativeProperty] public int TransformCount { get { return transforms.Count; } } }
ReadOnly
public class NaughtyComponent : MonoBehaviour { [ReadOnly] public Vector3 forwardVector = Vector3.forward; }
ShowAssetPreview
public class NaughtyComponent : MonoBehaviour { [ShowAssetPreview] public Sprite sprite; [ShowAssetPreview( 128, 128 )] public GameObject prefab; }
ShowIf / HideIf
public class NaughtyComponent : MonoBehaviour { public bool showInt; [ShowIf( "showInt" ) public int myInt; [ShowIf( "AlwaysShow" )] public float myFloat; [ShowIf( "NeverShow" )] public Vector3 myVector; private bool AlwaysShow() { return true; } private bool NeverShow() { return false; } }
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; }
MinValue / MaxValue
public class NaughtyComponent : MonoBehaviour { [MinValue( 0 ), MaxValue( 10 )] public int myInt; [MinValue( 0f )] public float myFloat; }
Required
public class NaughtyComponent : MonoBehaviour { [Required] public Transform myTransform; [Required( "Custom required text" )] public GameObject myGameObject; }
ValidateInput
public class NaughtyComponent : MonoBehaviour { [ValidateInput( "IsNotNull" )] public Transform myTransform; [ValidateInput( "IsGreaterThanZero", "myInteger must be greater than zero" )] public int myInt; private bool IsNotNull( Transform transform ) { return transform != null; } private bool IsGreaterThanZero( int integer ) { return integer > 0; } }
Section
public class NaughtyComponent : MonoBehaviour { [Section( "Integers" )] public int firstInt; public int secondInt; [Section( "Floats" )] public float firstFloat; public float secondFloat; }
BlankSpace
public class NaughtyComponent : MonoBehaviour { public int someInt; [BlankSpace] public float someFloat; }
InfoBox
public class NaughtyComponent : MonoBehaviour { [InfoBox( "myInt is not even", InfoBoxType.Error, "IsMyIntNotEven" )] public int myInt; [InfoBox( "This is myFloat" )] public float myFloat; [InfoBox( "This is myVector", InfoBoxType.Warning )] public Vector3 myVector; private bool isMyIntNotEven() { return myInt % 2 != 0; } }
OnValueChanged
public class NaughtyComponent : MonoBehaviour { [OnValueChanged( "OnValueChanged" )] public int myInt; private void OnValueChanged() { Debug.Log( myInt ); } }