README.html
NaughtyAttributes is an extension for the Unity Inspector.
It expands the range of attributes that Unity provides so that you can create powerful inspectors without the need of custom editors or property drawers. It also provides attributes that can be applied to non-serialized fields or functions.
Most of the attributes are implemented using Unity's CustomPropertyDrawer, so they will work in your custom editors. If you want all of the attributes to work in your custom editors, however, you must inherit from NaughtyInspector and use the NaughtyEditorGUI.PropertyField_Layout function instead of EditorGUILayout.PropertyField.
Unity 2018.3.0 or later versions. Feel free to try older version. Don't forget to include the NaughtyAttributes namespace.
openupm add com.dbrizov.naughtyattributes
"com.dbrizov.naughtyattributes": "https://github.com/dbrizov/NaughtyAttributes.git#upm"
NaughtyAttributes is an open-source project that I am developing in my free time. If you like it you can support me by donating.
Provide special draw options to serialized fields. A field can have only one DrawerAttribute. If a field has more than one, only the bottom one will be used.
Select an Animator paramater via dropdown interface.
publicclassNaughtyComponent:MonoBehaviour{publicAnimatorsomeAnimator;
[AnimatorParam("someAnimator")]publicintparamHash;
[AnimatorParam("someAnimator")]publicstringparamName;
}
A method can be marked as a button. A button appears in the inspector and executes the method if clicked. Works both with instance and static methods.
publicclassNaughtyComponent:MonoBehaviour{
[Button]privatevoidMethodOne() { }
[Button("Button Text")]privatevoidMethodTwo() { }
}
Set bounds and modify curve color for AnimationCurves
publicclassNaughtyComponent:MonoBehaviour{
[CurveRange(-1,-1,1,1)]publicAnimationCurvecurve;
[CurveRange(EColor.Orange)]publicAnimationCurvecurve1;
[CurveRange(0,0,5,5,EColor.Red)]publicAnimationCurvecurve2;
}
Provides an interface for dropdown value selection.
publicclassNaughtyComponent:MonoBehaviour{
[Dropdown("intValues")]publicintintValue;
[Dropdown("StringValues")]publicstringstringValue;
[Dropdown("GetVectorValues")]publicVector3vectorValue;privateint[]intValues=newint[] {1,2,3,4,5};privateList<string>StringValues{get{returnnewList<string>() {"A","B","C","D","E"}; } }privateDropdownList<Vector3>GetVectorValues()
{returnnewDropdownList<Vector3>()
{
{"Right",Vector3.right},
{"Left",Vector3.left},
{"Up",Vector3.up},
{"Down",Vector3.down},
{"Forward",Vector3.forward},
{"Back",Vector3.back}
};
}
}
Provides dropdown interface for setting enum flags.
publicenumDirection{None=0,Right=1\<\<0,Left=1\<\<1,Up=1\<\<2,Down=1\<\<3}publicclassNaughtyComponent:MonoBehaviour{
[EnumFlags]publicDirectionflags;
}
Make scriptable objects expandable.
publicclassNaughtyComponent:MonoBehaviour{
[Expandable]publicScriptableObjectscriptableObject;
}
publicclassNaughtyComponent:MonoBehaviour{
[HorizontalLine(color:EColor.Red)]publicintred;
[HorizontalLine(color:EColor.Green)]publicintgreen;
[HorizontalLine(color:EColor.Blue)]publicintblue;
}
Used for providing additional information.
publicclassNaughtyComponent:MonoBehaviour{
[InfoBox("This is my int",EInfoBoxType.Normal)]publicintmyInt;
[InfoBox("This is my float",EInfoBoxType.Warning)]publicfloatmyFloat;
[InfoBox("This is my vector",EInfoBoxType.Error)]publicVector3myVector;
}
Select an input axis via dropdown interface.
publicclassNaughtyComponent:MonoBehaviour{
[InputAxis]publicstringinputAxis;
}
A double slider. The min value is saved to the X property, and the max value is saved to the Y property of a Vector2 field.
publicclassNaughtyComponent:MonoBehaviour{
[MinMaxSlider(0.0f,100.0f)]publicVector2minMaxSlider;
}
publicclassNaughtyComponent:MonoBehaviour{
[ProgressBar("Health",300,EColor.Red)]publicinthealth=250;
[ProgressBar("Mana",100,EColor.Blue)]publicintmana=25;
[ProgressBar("Stamina",200,EColor.Green)]publicintstamina=150;
}
Provides array type fields with an interface for easy reordering of elements.
publicclassNaughtyComponent:MonoBehaviour{
[ReorderableList]publicint[]intArray;
[ReorderableList]publicList<float>floatArray;
}
Makes a field read only.
publicclassNaughtyComponent:MonoBehaviour{
[ReadOnly]publicVector3forwardVector=Vector3.forward;
}
A resizable text area where you can see the whole text. Unlike Unity's Multiline and TextArea attributes where you can see only 3 rows of a given text, and in order to see it or modify it you have to manually scroll down to the desired row.
publicclassNaughtyComponent:MonoBehaviour{
[ResizableTextArea]publicstringresizableTextArea;
}
Select a scene from the build settings via dropdown interface.
publicclassNaughtyComponent:MonoBehaviour{
[Scene]publicstringbootScene;// scene name[Scene]publicinttutorialScene;// scene index}
Shows the texture preview of a given asset (Sprite, Prefab...).
publicclassNaughtyComponent:MonoBehaviour{
[ShowAssetPreview]publicSpritesprite;
[ShowAssetPreview(128,128)]publicGameObjectprefab;
}
Shows native C# properties in the inspector. All native properties are displayed at the bottom of the inspector after the non-serialized fields and before the method buttons. It supports only certain types (bool, int, long, float, double, string, Vector2, Vector3, Vector4, Color, Bounds, Rect, UnityEngine.Object).
publicclassNaughtyComponent:MonoBehaviour{publicList<Transform>transforms;
[ShowNativeProperty]publicintTransformsCount=\>transforms.Count;
}
Shows non-serialized fields in the inspector. All non-serialized fields are displayed at the bottom of the inspector before the method buttons. Keep in mind that if you change a non-static non-serialized field in the code - the value in the inspector will be updated after you press Play in the editor. There is no such issue with static non-serialized fields because their values are updated at compile time. It supports only certain types (bool, int, long, float, double, string, Vector2, Vector3, Vector4, Color, Bounds, Rect, UnityEngine.Object).
publicclassNaughtyComponent:MonoBehaviour{
[ShowNonSerializedField]privateintmyInt=10;
[ShowNonSerializedField]privateconstfloatPI=3.14159f;
[ShowNonSerializedField]privatestaticreadonlyVector3CONST\_VECTOR=Vector3.one;
}
Select a tag via dropdown interface.
publicclassNaughtyComponent:MonoBehaviour{
[Tag]publicstringtagField;
}
Give the fields meta data. A field can have more than one meta attributes.
Surrounds grouped fields with a box.
publicclassNaughtyComponent:MonoBehaviour{
[BoxGroup("Integers")]publicintfirstInt;
[BoxGroup("Integers")]publicintsecondInt;
[BoxGroup("Floats")]publicfloatfirstFloat;
[BoxGroup("Floats")]publicfloatsecondFloat;
}
Makes a foldout group.
publicclassNaughtyComponent:MonoBehaviour{
[Foldout("Integers")]publicintfirstInt;
[Foldout("Integers")]publicintsecondInt;
}
publicclassNaughtyComponent:MonoBehaviour{publicboolenableMyInt;
[EnableIf("enableMyInt")]publicintmyInt;
[EnableIf("Enabled")]publicfloatmyFloat;
[EnableIf("NotEnabled")]publicVector3myVector;publicboolEnabled() {returntrue; }publicboolNotEnabled=\>false;
}
You can have more than one condition.
publicclassNaughtyComponent:MonoBehaviour{publicboolflag0;publicboolflag1;
[EnableIf(EConditionOperator.And,"flag0","flag1")]publicintenabledIfAll;
[EnableIf(EConditionOperator.Or,"flag0","flag1")]publicintenabledIfAny;
}
publicclassNaughtyComponent:MonoBehaviour{publicboolshowInt;
[ShowIf("showInt")]publicintmyInt;
[ShowIf("AlwaysShow")]publicfloatmyFloat;
[ShowIf("NeverShow")]publicVector3myVector;publicboolAlwaysShow() {returntrue; }publicboolNeverShow=\>false;
}
You can have more than one condition.
publicclassNaughtyComponent:MonoBehaviour{publicboolflag0;publicboolflag1;
[ShowIf(EConditionOperator.And,"flag0","flag1")]publicintshowIfAll;
[ShowIf(EConditionOperator.Or,"flag0","flag1")]publicintshowIfAny;
}
Override default field label.
publicclassNaughtyComponent:MonoBehaviour{
[Label("Short Name")]publicstringveryVeryLongName;
[Label("RGB")]publicVector3vectorXYZ;
}
Detects a value change and executes a callback. Keep in mind that the event is detected only when the value is changed from the inspector. If you want a runtime event, you should probably use an event/delegate and subscribe to it.
publicclassNaughtyComponent:MonoBehaviour{
[OnValueChanged("OnValueChangedCallback")]publicintmyInt;privatevoidOnValueChangedCallback()
{Debug.Log(myInt);
}
}
Used for validating the fields. A field can have infinite number of validator attributes.
Clamps integer and float fields.
publicclassNaughtyComponent:MonoBehaviour{
[MinValue(0),MaxValue(10)]publicintmyInt;
[MinValue(0.0f)]publicfloatmyFloat;
}
Used to remind the developer that a given reference type field is required.
publicclassNaughtyComponent:MonoBehaviour{
[Required]publicTransformmyTransform;
[Required("Custom required text")]publicGameObjectmyGameObject;
}
The most powerful ValidatorAttribute.
publicclass\_NaughtyComponent:MonoBehaviour{
[ValidateInput("IsNotNull")]publicTransformmyTransform;
[ValidateInput("IsGreaterThanZero","myInteger must be greater than zero")]publicintmyInt;privateboolIsNotNull(Transformtr)
{returntr!=null;
}privateboolIsGreaterThanZero(intvalue)
{returnvalue\>0;
}
}