dbrizov / naughtyattributes Goto Github PK
View Code? Open in Web Editor NEWAttribute Extensions for Unity
License: MIT License
Attribute Extensions for Unity
License: MIT License
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.
I can't expand elements anymore. And reordering them is difficult, as Foldout is rendered on top of reordering button.
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.
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()").
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
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.
Just a few suggestions:
Unity 2018.3 supports including packages via packagemanager from git repositorys.
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.
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.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
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.
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".
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 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)
{
}
}`
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)
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
ResizableTextArea not work in strings and array strings.
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();
}
}
}
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.
no effect on monobehaviour Script but ScriptableObject works
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
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
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.
This thread shows a few attributes related to using scriptableobjects nested in monobehaviours
https://forum.unity.com/threads/editor-tool-better-scriptableobject-inspector-editing.484393/
Consider adding something like this to your package
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;
}
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.
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.
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
}
Currently its not working
Instead of referencing GameObject when assigning prefabs, I tend to reference a component on the prefab. It would be great if the [ShowAssetPreview]
attribute could be extended so that if used on a MonoBehaviour reference, it previews the asset that it is attached to.
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!
I want to use "ShowIf" & "OnValueChange" on a single variable that is not currently being usable in Unity 2017.2.17
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...
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.
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 !
When using NaughtyAttributes.ReordableList, that attribute itself is the only one that is applied to the inspector, even though i have added Unity's Header and Tooltip attributes to the same var.
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).
First of all, great plugin, good work and a big thanks for publishing it under MIT!
Now I have a suggestion. There seem to be a way to make radio buttons, like so: https://forum.unity.com/threads/radio-button-inspector.55333/#post-1851822
It would be great to have such possibilities with NaughtyAttributes.
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.
[SerializeField]
[ReorderableList]
private List<AssetLabelReference> _BuildModeAssetLabels = null;
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.
At a point in the future where you target >=2017.3
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.
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;
}
}
When I select multiple gameobjects with the same component that uses a [Button] attribute, pressing the button only executes the function on the first gameobject instead of all of them.
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.
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.