Code Monkey home page Code Monkey logo

naughtyattributes's People

Contributors

aka3eka avatar atatrkgl avatar blumbye 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

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.

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.

[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()").

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

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.

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.

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

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

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.

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

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?

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

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)

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

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

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

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

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.

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.

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.

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

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!

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

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.

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 !

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

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

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.

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

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

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.

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?

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.