Coder Social home page Coder Social logo

naughtyattributes's Introduction

NaughtyAttributes

Unity 2019.4+ openupm License: MIT

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. The attributes that won't work in your custom editors are the meta attributes and some drawer attributes such as ReorderableList, Button, ShowNonSerializedField and ShowNativeProperty.
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.

System Requirements

Unity 2019.4 or later versions. Don't forget to include the NaughtyAttributes namespace.

Installation

  1. The package is available on the openupm registry. You can install it via openupm-cli.
openupm add com.dbrizov.naughtyattributes
  1. You can also install via git url by adding this entry in your manifest.json
"com.dbrizov.naughtyattributes": "https://github.com/dbrizov/NaughtyAttributes.git#upm"
  1. You can also download it from the Asset Store

Documentation

Support

NaughtyAttributes is an open-source project that I am developing in my free time. If you like it you can support me by donating.

Overview

Special Attributes

AllowNesting

This attribute must be used in some cases when you want meta attributes to work inside serializable nested structs or classes. You can check in which cases you need to use it here.

public class NaughtyComponent : MonoBehaviour
{
    public MyStruct myStruct;
}

[System.Serializable]
public struct MyStruct
{
    public bool enableFlag;

    [EnableIf("enableFlag")]
    [AllowNesting] // Because it's nested we need to explicitly allow nesting
    public int integer;
}

Drawer Attributes

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.

AnimatorParam

Select an Animator paramater via dropdown interface.

public class NaughtyComponent : MonoBehaviour
{
	public Animator someAnimator;

	[AnimatorParam("someAnimator")]
	public int paramHash;

	[AnimatorParam("someAnimator")]
	public string paramName;
}

inspector

Button

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.

public class NaughtyComponent : MonoBehaviour
{
	[Button]
	private void MethodOne() { }

	[Button("Button Text")]
	private void MethodTwo() { }
}

inspector

CurveRange

Set bounds and modify curve color for AnimationCurves

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;
}

inspector

Dropdown

Provides an interface for dropdown value selection.

public class NaughtyComponent : MonoBehaviour
{
	[Dropdown("intValues")]
	public int intValue;

	[Dropdown("StringValues")]
	public string stringValue;

	[Dropdown("GetVectorValues")]
	public Vector3 vectorValue;

	private int[] intValues = new int[] { 1, 2, 3, 4, 5 };

	private List<string> StringValues { get { return new List<string>() { "A", "B", "C", "D", "E" }; } }

	private DropdownList<Vector3> GetVectorValues()
	{
		return new DropdownList<Vector3>()
		{
			{ "Right",   Vector3.right },
			{ "Left",    Vector3.left },
			{ "Up",      Vector3.up },
			{ "Down",    Vector3.down },
			{ "Forward", Vector3.forward },
			{ "Back",    Vector3.back }
		};
	}
}

inspector

EnumFlags

Provides dropdown interface for setting enum flags.

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;
}

inspector

Expandable

Make scriptable objects expandable.

public class NaughtyComponent : MonoBehaviour
{
	[Expandable]
	public ScriptableObject scriptableObject;
}

inspector

HorizontalLine

public class NaughtyComponent : MonoBehaviour
{
	[HorizontalLine(color: EColor.Red)]
	public int red;

	[HorizontalLine(color: EColor.Green)]
	public int green;

	[HorizontalLine(color: EColor.Blue)]
	public int blue;
}

inspector

InfoBox

Used for providing additional information.

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;
}

inspector

InputAxis

Select an input axis via dropdown interface.

public class NaughtyComponent : MonoBehaviour
{
	[InputAxis]
	public string inputAxis;
}

inspector

Layer

Select a layer via dropdown interface.

public class NaughtyComponent : MonoBehaviour
{
	[Layer]
	public string layerName;

	[Layer]
	public int layerIndex;
}

inspector

MinMaxSlider

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.

public class NaughtyComponent : MonoBehaviour
{
	[MinMaxSlider(0.0f, 100.0f)]
	public Vector2 minMaxSlider;
}

inspector

ProgressBar

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;
}

inspector

ReorderableList

Provides array type fields with an interface for easy reordering of elements.

public class NaughtyComponent : MonoBehaviour
{
	[ReorderableList]
	public int[] intArray;

	[ReorderableList]
	public List<float> floatArray;
}

inspector

ResizableTextArea

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.

public class NaughtyComponent : MonoBehaviour
{
	[ResizableTextArea]
	public string resizableTextArea;
}

inspector

Scene

Select a scene from the build settings via dropdown interface.

public class NaughtyComponent : MonoBehaviour
{
	[Scene]
	public string bootScene; // scene name

	[Scene]
	public int tutorialScene; // scene index
}

inspector

ShowAssetPreview

Shows the texture preview of a given asset (Sprite, Prefab...).

public class NaughtyComponent : MonoBehaviour
{
	[ShowAssetPreview]
	public Sprite sprite;

	[ShowAssetPreview(128, 128)]
	public GameObject prefab;
}

inspector

ShowNativeProperty

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).

public class NaughtyComponent : MonoBehaviour
{
	public List<Transform> transforms;

	[ShowNativeProperty]
	public int TransformsCount => transforms.Count;
}

inspector

ShowNonSerializedField

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).

public class NaughtyComponent : MonoBehaviour
{
	[ShowNonSerializedField]
	private int myInt = 10;

	[ShowNonSerializedField]
	private const float PI = 3.14159f;

	[ShowNonSerializedField]
	private static readonly Vector3 CONST_VECTOR = Vector3.one;
}

inspector

SortingLayer

Select a sorting layer via dropdown interface.

public class NaughtyComponent : MonoBehaviour
{
	[SortingLayer]
	public string layerName;

	[SortingLayer]
	public int layerId;
}

inspector

Tag

Select a tag via dropdown interface.

public class NaughtyComponent : MonoBehaviour
{
	[Tag]
	public string tagField;
}

inspector

Meta Attributes

Give the fields meta data. A field can have more than one meta attributes.

BoxGroup

Surrounds grouped fields with a box.

public class NaughtyComponent : MonoBehaviour
{
	[BoxGroup("Integers")]
	public int firstInt;
	[BoxGroup("Integers")]
	public int secondInt;

	[BoxGroup("Floats")]
	public float firstFloat;
	[BoxGroup("Floats")]
	public float secondFloat;
}

inspector

Foldout

Makes a foldout group.

public class NaughtyComponent : MonoBehaviour
{
	[Foldout("Integers")]
	public int firstInt;
	[Foldout("Integers")]
	public int secondInt;
}

inspector

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;
}

inspector

You can have more than one condition.

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;
}

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;
}

inspector

You can have more than one condition.

public class NaughtyComponent : MonoBehaviour
{
	public bool flag0;
	public bool flag1;

	[ShowIf(EConditionOperator.And, "flag0", "flag1")]
	public int showIfAll;

	[ShowIf(EConditionOperator.Or, "flag0", "flag1")]
	public int showIfAny;
}

Label

Override default field label.

public class NaughtyComponent : MonoBehaviour
{
	[Label("Short Name")]
	public string veryVeryLongName;

	[Label("RGB")]
	public Vector3 vectorXYZ;
}

inspector

OnValueChanged

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.

public class NaughtyComponent : MonoBehaviour
{
	[OnValueChanged("OnValueChangedCallback")]
	public int myInt;

	private void OnValueChangedCallback()
	{
		Debug.Log(myInt);
	}
}

ReadOnly

Make a field read only.

public class NaughtyComponent : MonoBehaviour
{
	[ReadOnly]
	public Vector3 forwardVector = Vector3.forward;
}

inspector

Validator Attributes

Used for validating the fields. A field can have infinite number of validator attributes.

MinValue / MaxValue

Clamps integer and float fields.

public class NaughtyComponent : MonoBehaviour
{
	[MinValue(0), MaxValue(10)]
	public int myInt;

	[MinValue(0.0f)]
	public float myFloat;
}

inspector

Required

Used to remind the developer that a given reference type field is required.

public class NaughtyComponent : MonoBehaviour
{
	[Required]
	public Transform myTransform;

	[Required("Custom required text")]
	public GameObject myGameObject;
}

inspector

ValidateInput

The most powerful ValidatorAttribute.

public class _NaughtyComponent : MonoBehaviour
{
	[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;
	}
}

inspector

naughtyattributes's People

Contributors

aka3eka avatar atatrkgl avatar blumbye avatar cmlewis89 avatar dbrizov avatar drachenkurve avatar favoyang avatar fmoo avatar if-act avatar jupotter avatar krisrok avatar maximetinu avatar muitsonz avatar peeweek avatar purejenix avatar rhys-vdw avatar roytazz avatar shinao avatar sichenn avatar smkplus avatar stromkuo avatar theosabattie avatar uniquecorn avatar wokarol avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

naughtyattributes's Issues

Add to readme a note about incompatibility with vanilla UnityEditor.CustomEditor attribute

Awesome plugin. Saves me a lot of time with setting up simple editor goodies. However it does not work on Components with existing vanilla custom editor scripts (as shown here: https://unity3d.com/learn/tutorials/topics/interface-essentials/building-custom-inspector).

using UnityEngine;
using UnityEditor;

[CustomEditor(typeof(NaughtyComponent))]
public class NaughtyComponentEditor : Editor {}

Deleting the existing scripts makes the NaughtyAttributes work as expected, and thats fine since the idea is to replace the vanilla way anyway. Would be nice though to have a hint in the readme to help out those migrating from the Unity way of doing this.

ArgumentException spam

Everything in the inspector is working fine all the attributes are working and it doesn't prevent me from running my game but every time the project compiles my console gets spammed with the following
image
I've tried to remove all the attributes and pinpoint whats causing it but whether I'm using attributes or not these errors are always spammed to the console.

NaughtyAttributes doesn't work in NetworkBehaviour

Any NaughtyAttributes doesn't do anything when used on a NetworkBehaviour

public class Test : NetworkBehaviour {
    #region inspector variables
    [Header("Map Properties")]
    public string mapName;
    public Sprite mapPreview;
    public GameModes gameMode = GameModes.LastManStanding;
    [ReorderableList]
    public string[] mapPlaylists;
    public bool playMusicAutomatically = false;
    public bool stopMusicOnDestroy = false;
    public Vector2 mapBoundaries;
    public bool mapHaveStartAnimation = false;

    [Header("Player Properties")]
    public Weapons defaultWeapon = Weapons.Null;
    public GameObject playerSpawnVFX;
    public GameObject playerDeathVFX;
    public float playerSpawnInterval = 0.2f;
    public float spawnRadiusCheck = 2f;
    public bool randomizeSpawnPos = false;
    public bool randomizeSpawnPosIndex = true;

    [Header("Camera Properties")]
    public float cameraMinDistance = 20f;
    public bool targetPlayers = true;
    [ShowIf("targetPlayers")]
    public float targetGroupRadius = 4;
    [ShowIf("targetPlayers")]
    public float targetGroupWeight = 1;
    public bool targetMap = false;
    [ShowIf("targetMap")]
    public float mapTargetGroupRadius = 1;
    [ShowIf("targetMap")]
    public float mapTargetGroupWeight = 1;
    [ReorderableList]
    public List<GameObject> mapTargets;
    public CinemachineTargetGroup targetGroup;
    public CinemachineVirtualCamera virtualCamera;
    private CinemachineGroupComposer groupComposer;
    private CameraShake cameraShake;

    [Header("End Round Properties")]
    public float lastPlayerPointDelay = 1f;
    public float lastPlayerZoomDelay = 2f;
    #endregion
}

image

Reorderable List doesn't work with an array of structs/classes

I have a struct Keybind and an array of Keybinds shown below.

    [System.Serializable]
    public struct Keybind
    {
        public string Id;
        public KeyCode KeyCode;
    }
    
    [ReorderableList, SerializeField] protected Keybind[] m_Keybinds;

However, it is not showing in the inspector when I use the ReorderableList attribute: Screenshot

Attributes are not working in structs

Hi,

The attributes I am trying to use are not working in a struct I made Serializable. (System.Serializable)
These are the attributes I'm trying to use: "ReadOnly" and "OnValueChanged".

CodeGenerator fails when a type from a different namespace is used

Hello, thanks for this helpful utility!

While creating my own validator (checking if an object is null when using JetBrains.Annotations.NotNullAttribute), I realized the Update Attributes Database generates a typo because it assumes JetBrains.Annotations is imported. I temporarily solved this issue by replacing type.Name with type.FullName in line 66. However, I don't think this works when using generic types.

ShowIf, HideIf, and DisableIf do not work with properties

These attributes work with bool fields and methods that return a bool, but they do not work with get-enabled bool properties. Adding support shouldn't be too hard because you can use reflection to get the property's GetMethod and use that.

CodeGenerator doesn't work in OSX

CodeGenerator.cs

Replace("/", "\\")

This process required only for WindowsOS.

Works on OSX, Example

private static readonly string GENERATED_CODE_TARGET_FOLDER =
    (Application.dataPath.Replace("Assets", string.Empty) + AssetDatabase.GUIDToAssetPath(AssetDatabase.FindAssets("CodeGenerator")[0]))
    #if UNITY_EDITOR_WIN
    .Replace("CodeGenerator.cs", string.Empty).Replace("/", "\\");
    #else
    .Replace("CodeGenerator.cs", string.Empty);
    #endif

IMPROVEMENT: Show sprite in the Inspector

Hi, first of all, awesome work of yours. Keep up the good work.

Let's move to the point, I am not raising an issue but maybe chance for an improvement.

Is there any chance you develop an attribute like this:

[ShowSpriteInTheInspector]
public Sprite PlayerSprite;

And that specific sprite will become visible in the inspector.

I hope I have explained it well, thank you very much.

NaughtyAttributes don't work on custom Inspector Editors

Normally if I define a custom PropertyDrawer with an Attribute and apply that Attribute to a field for a MonoBehaviour that has a Custom Inspector and I use EditorGUILayout.PropertyField(field); do draw that field in the Custom Inspector's OnInspectorGUI() then the custom PropertyDrawer will still be used for that field in the Custom Inspector.

If I apply a NaughtyAttributes Attribute like ShowIf to a field in a MonoBehaviour then it draws as expected with the Default Inspector but if I have a Custom Inspector and draw that field with EditorGUILayout.PropertyField() it won't use the custom NaughtyAttributes PropertyDrawer. Is there any way to get this to work inside a Custom Inspector?

Draw the override method many times

Thanks for the gerat plugin! one small problem here:
If i mark a virtual Method using [Button] Attribute, all it's override Method will be Drawn too. Will it be better to ignore the override method?

File Not Found PropertyMetaDatabase.txt

This is on a Mac on Sierra on Unity 2017.2.0f3 (64bit).

FileNotFoundException: Could not find file "/Users/jason/Desktop/swatchtest/swatchtest/\Users\jason\Desktop\swatchtest\swatchtest\Assets\Plugins\NaughtyAttributes\Scripts\Editor\CodeGeneration\Templates\PropertyMetaDatabaseTemplate.txt".
System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/FileStream.cs:305)
System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean isAsync, Boolean anonymous)
System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access)
(wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess)
NaughtyAttributes.Editor.IOUtility.ReadFromFile (System.String filePath) (at Assets/Plugins/NaughtyAttributes/Scripts/Editor/Utility/IOUtility.cs:26)
NaughtyAttributes.Editor.CodeGenerator.GenerateScript[PropertyMeta,PropertyMetaAttribute] (System.String scriptName, System.String templateName, System.String entryFormat) (at Assets/Plugins/NaughtyAttributes/Scripts/Editor/CodeGeneration/CodeGenerator.cs:53)
NaughtyAttributes.Editor.CodeGenerator.GenerateCode () (at Assets/Plugins/NaughtyAttributes/Scripts/Editor/CodeGeneration/CodeGenerator.cs:29)

This can be fixed by using templateRelativePath instead of templateFullPath in CodeGenerator.GenerateScript's IOUtility.ReadFromFile call.

I'd submit a pull request but I assume that templateFullPath exists for some reason.

better asset distribution (use github releases, and unity packagemanager)

Just a few suggestions:

Unity 2018.3 supports including packages via packagemanager from git repositorys.

  • Refactor the repository such that Assets/* is your root
  • add a package.json for integration with the package manager.

see unity-atoms for reference: https://github.com/AdamRamberg/unity-atoms/tree/v1.0.0
for more info about that see the issue to those changes unity-atoms/unity-atoms#13


the *.unitypackage file should be an "realese" here on github. so users could simply download the package, instead the whole project and then using the package.

Updated to 2017.3.1f1 and NA stopped working

Even tried getting the latest version from GIT but no succes. Buttons are not being drawn in the inspector and my script attached to OnValueChanged is not firing. Not sure what else i can add to find the issue...

Dropdown not working in Unity 2017.4.14f1

The Dropdown feature doesn't work in Unity 2017.4.14f1. Tried with int values and strings. Tried with option list fields set to public and private. Tried with arrays and DropdownList for the options. To no avail - the field is still rendered as a plain string input field in the inspector.

Any possibility to get a List<T> that can be populated by drag and drop?

Hello all,
I was wondering if requests can be made for what you would like to see? I saw that Odin had something similar to the reorderable list, but the list was also able to be populated with gameobjects, transforms, or whatever you wanted by simply selecting them and then dragging them all at once to the inspector. Is that something that is able to be done with something like this?

Thanks,
-MH

ReorderableList doesn't work right with complex elements

I have a list of custom objects

public class Points : ScriptableObject {
    [ReorderableList] public List<Point> value = new List<Point>();
    [Serializable] public struct Point {
        public string name;
        public Vector3 position;
        ...
    }
}

It shows up as follows.
image
I can't expand elements anymore. And reordering them is difficult, as Foldout is rendered on top of reordering button.

Compatibility with 2018.1?

Hi, I'm wondering which commit is the latest to still work with Unity 2018.1.
I tried the most recent and it isn't working, even when importing the namespace and putting Naughty Attributes in my Assets root directory.
Any suggestions appreciated other than upgrading Unity. Thanks!

InspectorFoldoutGroup

Please Add Foldout like this

https://github.com/dimmpixeye/InspectorFoldoutGroup


I tried to make foldout by changing your boxGroup but not work

using UnityEditor;
using UnityEngine;

namespace NaughtyAttributes.Editor
{
    [PropertyGrouper(typeof(BoxGroupAttribute))]
    public class BoxGroupPropertyGrouper : PropertyGrouper
    {
        bool status = true;

        public override void BeginGroup(string label)
        {
            status = EditorGUILayout.Foldout(status,"Test");
            if(!status){
            return;
            }
        }

        public override void EndGroup()
        {
            EditorGUILayout.EndVertical();
            
        }
    }
}

[Issue] ReorderableList has compatibility issue with AssetReference

        [SerializeField]
        [ReorderableList]
        private List<AssetLabelReference> _BuildModeAssetLabels = null;

Screen Shot 2019-04-08 at 11 28 17

Result in a very nice looking UI, but is not actually usable, in that clicking on the dropdown menu has no effects:

Not sure this can be fixed on the NaughtyAttributes side or not. So far removing [ReorderableList] is the only workaround.

Unity Asset Store

Hello,
I absolutely love this package, it's super useful for quickly making user-friendly inspectors for classes! Most of these attributes should be built into Unity.

But why isn't this on the asset store? It took me a while to find it (through unitylist.com).

Draw ordering

Hello.

I'd love a way to say: << Draw my fields below the upper class' ones >>

As in :

public class A{
public int intField;
}

public class B{
public string stringField;
}

Inspector

| [] intField |
| [
] stringField |

Is it possible?
I'm thinking maybe an attribute like [DrawInheritedFields], that you can place where-ever, and it will take into account its line position relative to the other attributes.

ShowIf will always show BoxGroup name

private bool MoveSelected() { return animationType == AnimationType.Move; }
[ShowIf("MoveSelected")] [BoxGroup("Move")] [SerializeField] Vector3 targetPosition;

we will always see BoxGroup title:

image

NaughtyAttributes doesn't work in StateMachineBehaviour

NaughtyAttributes doesn't do anything when attached to attributes in a StateMachineBehaviour

`public class SetRandomParameter : StateMachineBehaviour {

public string parameter;
            
public enum ParameterType { integer, floatingPoint };
[SerializeField]
private ParameterType _parameterType;

[ShowIf("IsInt")]
public int min;
[ShowIf("IsInt")]
public int max;

[ShowIf("IsFloat")]
public Vector2 range;

private bool IsInt()
{
    return _parameterType == ParameterType.integer;
}
private bool IsFloat()
{
    return _parameterType == ParameterType.floatingPoint;
}


// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
        
}

}`

image

Attributes that add or remove GUI elements dynamically will often change the active control

This makes it nearly impossible to use the validation tools without making unintentional changes.
Some times it will randomly work for a bit, but it always breaks again if you inspect a different asset and then go back to the one with the validation on.

NaughtyAttributesControl

The test was made with Unity 2019.1.0f2 with NaughtyAttributes 1.0.3.

The example script used:

using NaughtyAttributes;
using UnityEngine;

public class NaughtyTest : MonoBehaviour
{
	[ValidateInput(nameof(IsShortString))]
	public string exampleString;
	public string exampleString1;

	[ValidateInput(nameof(IsShortString))]
	public string exampleString2;
	public string exampleString3;

	[ShowIf(nameof(ShowCondition))]
	public bool exampleBool1;

	[HideIf(nameof(HideCondition))]
	public bool exampleBool2;

	public string exampleString4;
	public string exampleString5;

	public string exampleString6;
	[InfoBox("string is short", InfoBoxType.Normal, nameof(InfoShowCondition))]
	public string exampleString7;
	public string exampleString8;

	[ValidateInput(nameof(ValidateArray))]
	public string[] exampleStringArray;

	public string[] exampleStringArray2;

	private bool ShowCondition() => IsShortString(exampleString5);
	private bool HideCondition() => IsShortString(exampleString6);

	private bool InfoShowCondition() => IsShortString(exampleString7);

	private bool IsShortString(string val)
	{
		return val?.Length < 5;
	}

	private bool ValidateArray(string[] arr)
	{
		foreach (string s in arr)
		{
			if (string.IsNullOrWhiteSpace(s))
			{
				return false;
			}
		}

		return true;
	}
}

Console errors after import

Using Unity 2017.1.0p4 after importing my console is is filled with 6 times the same error:

NullReferenceException: Object reference not set to an instance of an object
UnityEditor.Scripting.ScriptCompilation.EditorCompilation.DirtyScript (System.String path) (at C:/buildslave/unity/build/Editor/Mono/Scripting/ScriptCompilation/EditorCompilation.cs:88)
UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface.DirtyScript (System.String path) (at C:/buildslave/unity/build/Editor/Mono/Scripting/ScriptCompilation/EditorCompilationInterface.cs:44)
UnityEditor.AssetDatabase:Refresh()
NaughtyAttributes.Editor.CodeGenerator:GenerateCode() (at Assets/NaughtyAttributes/Scripts/Editor/CodeGeneration/CodeGenerator.cs:36)

Also warnings about inconsistent line end, but that is easily fixeable. After clearing console it does work, just the warning comes up everytime opening the project.

Can't add button in boxGroup

Hi,

I'm trying to create a box group with a button inside of it. I try it as follow :

    [BoxGroup("Some group")]
    [Button]
    public void SomeMethod()
    {
    }

I get the following error : The attribute `NaughtyAttributes.BoxGroupAttribute' is not valid on this declaration type. It is valid on `field' declarations only.

Thanks

Slider is disabled if we add a Label

Hi dbrizow,
I love this plugins and i love you <3 <3 ! thanks a lot for your work !
I found a little bug i think.

When you add a label and a slider, the slider is disabled...
Maybe you can correct it when you have some time ?
And will you marry me ?

image

[ReorderableList] making nested reorderable array work?

Is there a way to make nested classes array work?
It only works on the first Array

For example:

public class LevelBase
{
    public bool IsDisabled;
    public GameObject Level;
 ....
}

AND

public class LevelsChapters
{
    public LevelBase[] LevelChapterBase;

}

And in declaration i do:

  [ReorderableList]
    public LevelsChapters[] LevelChapterBase;

It only 'reorder' the first array while the nested array remains normal.

Label/InfoBox with non-static access

Hi! First I want to thank you for the awesome work, it's really useful as I prefer not to waste time with custom editors. Everything is working fine and as expected.

Would it be imaginable to add a "Label" attribute that could display non-static informations about the object? A quick example :

[Label]
private string MyLabelText 
{
    get { return transform.childCount + " childs."; }
}

I was thinking something with the same design than InfoBox.

Thank you !

[Feature] Allow methods for Dropdown

I'm using this workaround:

    [Dropdown("TheValues")]
    public int foo;
    public static DropdownList<int> TheValues = ValuesFunction();

    DropdownList<int> ValuesFunction()
    {
        for (...) ...
    }

But it would be nicer to write:

    [Dropdown("ValuesFunction")]
    public int foo;
    ...

(or "ValuesFunction()").

Button at the bottom of the inspector

The button attribute gets taken to the bottom of the inspector ignoring the class hierarchy.
It does not make sense when you group attributes together but your button is not with them.

Great repo though :)

Issue with ShowAssetPreview and SerializeField

Hey there,

I've encountered an issue when using ShowAssetPreview together with SerializeField on a Sprite within a scriptable object.

Here is the line:
[SerializeField] [BoxGroup(GENERAL_SETTINGS_HEADER)] [ShowAssetPreview] Sprite itemIcon;

It works when I remove the SerializeField option and use a public modifier instead:
[BoxGroup(GENERAL_SETTINGS_HEADER)] [ShowAssetPreview] public Sprite itemIcon;

here is the Stacktrace:

NullReferenceException: Object reference not set to an instance of an object
NaughtyAttributes.Editor.PropertyUtility.GetAttributes[ShowAssetPreviewAttribute] (UnityEditor.SerializedProperty property) (at Assets/Plugins/NaughtyAttributes/Scripts/Editor/Utility/PropertyUtility.cs:20)
NaughtyAttributes.Editor.ShowAssetPreviewPropertyDrawer.DrawProperty (UnityEditor.SerializedProperty property) (at Assets/Plugins/NaughtyAttributes/Scripts/Editor/PropertyDrawers/ShowAssetPreviewPropertyDrawer.cs:20)
NaughtyAttributes.Editor.InspectorEditor.DrawField (System.Reflection.FieldInfo field) (at Assets/Plugins/NaughtyAttributes/Scripts/Editor/Editors/InspectorEditor.cs:232)
NaughtyAttributes.Editor.InspectorEditor.ValidateAndDrawField (System.Reflection.FieldInfo field) (at Assets/Plugins/NaughtyAttributes/Scripts/Editor/Editors/InspectorEditor.cs:190)
NaughtyAttributes.Editor.InspectorEditor.ValidateAndDrawFields (IEnumerable`1 fields) (at Assets/Plugins/NaughtyAttributes/Scripts/Editor/Editors/InspectorEditor.cs:182)
NaughtyAttributes.Editor.InspectorEditor.OnInspectorGUI () (at Assets/Plugins/NaughtyAttributes/Scripts/Editor/Editors/InspectorEditor.cs:124)
UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor[] editors, Int32 editorIndex, Boolean rebuildOptimizedGUIBlock, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1245)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.