NaughtyAttributes
repository·master·Indexed 26 days ago
https://github.com/dbrizov/naughtyattributesA Unity Inspector extension (version 2.1.6) that expands the range of available attributes, allowing developers to create functional inspectors without writing custom editors or property drawers. It supports attributes on non-serialized fields and functions, providing tools for conditional visibility (ShowIf, HideIf), validation (Required, ValidateInput), layout (BoxGroup, Foldout), and specialized input interfaces (Dropdown, MinMaxSlider, ProgressBar).
What's inside NaughtyAttributes
- NaughtyAttributes is available for download directly from the Unity Asset Store.
Install NaughtyAttributes via OpenUPM
masterYou can install NaughtyAttributes using the OpenUPM registry via the
openupm-cli.openupm add com.dbrizov.naughtyattributesInstall NaughtyAttributes via Git URL
masterAdd the following entry to your Unity
manifest.jsonfile to install the package via Git."com.dbrizov.naughtyattributes": "https://github.com/dbrizov/NaughtyAttributes.git#upm"Ensure attribute compatibility in Custom Editors
masterMost attributes use Unity's
CustomPropertyDrawerand work in custom editors. However, meta attributes and certain drawer attributes (ReorderableList,Button,ShowNonSerializedField, andShowNativeProperty) will NOT work in standard custom editors.To make all attributes work in your custom editors:
- Inherit from
NaughtyInspector. - Use
NaughtyEditorGUI.PropertyField_Layoutinstead ofEditorGUILayout.PropertyField.
- Inherit from
Integrate NaughtyAttributes with Custom Editors
masterMost NaughtyAttributes are implemented using Unity's
CustomPropertyDrawer, meaning they will work automatically in your custom editors.However, if you want all attributes to work within a custom editor, you must:
- Inherit your editor from
NaughtyInspector. - Use
NaughtyEditorGUI.PropertyField_Layoutinstead ofEditorGUILayout.PropertyFieldto layout your fields.
- Inherit your editor from
Install NaughtyAttributes
masterNaughtyAttributes can be installed in your Unity project using one of the following three methods:
Via OpenUPM CLI (Recommended): Use the
openupm-clito add the package.Via Git URL: Add the following entry to your
manifest.jsonfile:Via Unity Asset Store: Download the package directly from the Asset Store.
Use InputAxis attribute
masterProvides a dropdown interface to select an input axis.
public class NaughtyComponent : MonoBehaviour { [InputAxis] public string inputAxis; }Conditionally enable or disable fields with EnableIf / DisableIf
masterUse
[EnableIf("fieldName")]or[DisableIf("fieldName")]to enable or disable a field in the Inspector based on the value of another field, property, or method.You can also use logical operators by providing an
EConditionOperatorand multiple field names.Supported operators via
EConditionOperator:EConditionOperator.And(all conditions must be true)EConditionOperator.Or(any condition must be true)
public class NaughtyComponent : MonoBehaviour { public bool flag0; public bool flag1; [EnableIf(EConditionOperator.And, "flag0", "flag1")] public int enabledIfAll; [EnableIf(EConditionOperator.Or, "flag0", "flag1")] public int enabledIfAny; }Mark fields as required with Required
masterUse the
[Required]attribute to visually remind developers that a reference type field must be assigned. You can provide a custom error message string:[Required("Custom message")].public class NaughtyComponent : MonoBehaviour { [Required] public Transform myTransform; [Required("Custom required text")] public GameObject myGameObject; }Use ProgressBar attribute
masterDisplays a progress bar in the inspector. Requires a label string, a max value, and an
EColor.public class NaughtyComponent : MonoBehaviour { [ProgressBar("Health", 300, EColor.Red)] public int health = 250; [ProgressBar("Mana", 100, EColor.Blue)] public int mana = 25; [ProgressBar("Stamina", 200, EColor.Green)] public int stamina = 150; }Use Expandable attribute
masterMakes
ScriptableObjectfields expandable directly within the inspector.public class NaughtyComponent : MonoBehaviour { [Expandable] public ScriptableObject scriptableObject; }Use SortingLayer attribute
masterProvides a dropdown interface to select a Sorting Layer. Can be used for
string(layer name) orint(layer ID) fields.public class NaughtyComponent : MonoBehaviour { [SortingLayer] public string layerName; [SortingLayer] public int layerId; }