diff --git a/Assets/Editor Toolbox/Editor/Drawers/Helpers/Extraction/ValueExtractionHelper.cs b/Assets/Editor Toolbox/Editor/Drawers/Helpers/Extraction/ValueExtractionHelper.cs index 7538370b..38177a55 100644 --- a/Assets/Editor Toolbox/Editor/Drawers/Helpers/Extraction/ValueExtractionHelper.cs +++ b/Assets/Editor Toolbox/Editor/Drawers/Helpers/Extraction/ValueExtractionHelper.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; - using UnityEditor; namespace Toolbox.Editor.Drawers @@ -68,14 +67,8 @@ public static bool TryGetValue(string source, SerializedProperty causer, out obj public static bool TryGetValue(string source, SerializedProperty causer, out object value, out bool hasMixedValues, Func nextValuesComparer) { - var targetObjects = causer.serializedObject.targetObjects; - var parentObjects = new object[targetObjects.Length]; - for (var i = 0; i < targetObjects.Length; i++) - { - var targetObject = targetObjects[i]; - parentObjects[i] = causer.GetDeclaringObject(targetObject); - } - + //NOTE: consider using NonAlloc implementation + var parentObjects = causer.GetDeclaringObjects(); return TryGetValue(source, parentObjects, out value, out hasMixedValues, nextValuesComparer); } } diff --git a/Assets/Editor Toolbox/Editor/Drawers/ISerializedPropertyContext.cs b/Assets/Editor Toolbox/Editor/Drawers/ISerializedPropertyContext.cs new file mode 100644 index 00000000..2aed7dd3 --- /dev/null +++ b/Assets/Editor Toolbox/Editor/Drawers/ISerializedPropertyContext.cs @@ -0,0 +1,13 @@ +using System; +using System.Reflection; +using UnityEditor; + +namespace Toolbox.Editor.Drawers +{ + public interface ISerializedPropertyContext + { + SerializedProperty Property { get; } + FieldInfo FieldInfo { get; } + Type Type { get; } + } +} \ No newline at end of file diff --git a/Assets/Editor Toolbox/Editor/ToolboxDrawerModule.cs.meta b/Assets/Editor Toolbox/Editor/Drawers/ISerializedPropertyContext.cs.meta similarity index 83% rename from Assets/Editor Toolbox/Editor/ToolboxDrawerModule.cs.meta rename to Assets/Editor Toolbox/Editor/Drawers/ISerializedPropertyContext.cs.meta index 60b3becb..969d1e7a 100644 --- a/Assets/Editor Toolbox/Editor/ToolboxDrawerModule.cs.meta +++ b/Assets/Editor Toolbox/Editor/Drawers/ISerializedPropertyContext.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 3a53f74baaf40314dbec88082130b5d1 +guid: cbdd57b1e7c956e41ba10cd6aa4ad2d5 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Editor Toolbox/Editor/Drawers/Regular/AnimationCurveSettingsAttributeDrawer.cs b/Assets/Editor Toolbox/Editor/Drawers/Regular/AnimationCurveSettingsAttributeDrawer.cs new file mode 100644 index 00000000..9b2c2038 --- /dev/null +++ b/Assets/Editor Toolbox/Editor/Drawers/Regular/AnimationCurveSettingsAttributeDrawer.cs @@ -0,0 +1,32 @@ +using UnityEditor; +using UnityEngine; + +namespace Toolbox.Editor.Drawers +{ + [CustomPropertyDrawer(typeof(AnimationCurveSettingsAttribute))] + public class AnimationCurveSettingsAttributeDrawer : PropertyDrawerBase + { + protected override void OnGUISafe(Rect position, SerializedProperty property, GUIContent label) + { + var attribute = Attribute; + var curveRanges = new Rect( + attribute.Min.x, + attribute.Min.y, + attribute.Max.x - attribute.Min.x, + attribute.Max.y - attribute.Min.y); + + var color = attribute.Color; + + EditorGUI.BeginProperty(position, label, property); + EditorGUI.CurveField(position, property, color, curveRanges, label); + EditorGUI.EndProperty(); + } + + public override bool IsPropertyValid(SerializedProperty property) + { + return base.IsPropertyValid(property) && property.propertyType == SerializedPropertyType.AnimationCurve; + } + + private AnimationCurveSettingsAttribute Attribute => attribute as AnimationCurveSettingsAttribute; + } +} \ No newline at end of file diff --git a/Assets/Editor Toolbox/Editor/Drawers/Regular/AnimationCurveSettingsAttributeDrawer.cs.meta b/Assets/Editor Toolbox/Editor/Drawers/Regular/AnimationCurveSettingsAttributeDrawer.cs.meta new file mode 100644 index 00000000..7403b654 --- /dev/null +++ b/Assets/Editor Toolbox/Editor/Drawers/Regular/AnimationCurveSettingsAttributeDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bff5a6e3c37b7ca4eba282c8910761aa +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor Toolbox/Editor/Drawers/Regular/AssetPreviewAttributeDrawer.cs b/Assets/Editor Toolbox/Editor/Drawers/Regular/AssetPreviewAttributeDrawer.cs index 1424fb9a..dde8d216 100644 --- a/Assets/Editor Toolbox/Editor/Drawers/Regular/AssetPreviewAttributeDrawer.cs +++ b/Assets/Editor Toolbox/Editor/Drawers/Regular/AssetPreviewAttributeDrawer.cs @@ -99,16 +99,13 @@ protected override void OnGUISafe(Rect position, SerializedProperty property, GU } } - public override bool IsPropertyValid(SerializedProperty property) { return property.propertyType == SerializedPropertyType.ObjectReference; } - private AssetPreviewAttribute Attribute => attribute as AssetPreviewAttribute; - private static class Style { internal static readonly float offset = 6.0f; diff --git a/Assets/Editor Toolbox/Editor/Drawers/Regular/PropertyDrawerBase.cs b/Assets/Editor Toolbox/Editor/Drawers/Regular/PropertyDrawerBase.cs index 7213d552..02dad0d9 100644 --- a/Assets/Editor Toolbox/Editor/Drawers/Regular/PropertyDrawerBase.cs +++ b/Assets/Editor Toolbox/Editor/Drawers/Regular/PropertyDrawerBase.cs @@ -26,11 +26,10 @@ protected virtual void OnGUISafe(Rect position, SerializedProperty property, GUI EditorGUI.PropertyField(position, property, label); } - /// /// Native call to return the expected height. /// - public override sealed float GetPropertyHeight(SerializedProperty property, GUIContent label) + public sealed override float GetPropertyHeight(SerializedProperty property, GUIContent label) { return IsPropertyValid(property) ? GetPropertyHeightSafe(property, label) @@ -40,7 +39,7 @@ public override sealed float GetPropertyHeight(SerializedProperty property, GUIC /// /// Native call to draw the provided property. /// - public override sealed void OnGUI(Rect position, SerializedProperty property, GUIContent label) + public sealed override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (IsPropertyValid(property)) { @@ -48,14 +47,12 @@ public override sealed void OnGUI(Rect position, SerializedProperty property, GU return; } - var warningContent = new GUIContent(property.displayName + " has invalid property drawer"); - //create additional warning log to the console window ToolboxEditorLog.WrongAttributeUsageWarning(attribute, property); //create additional warning label based on the property name + var warningContent = new GUIContent(property.displayName + " has invalid property drawer"); ToolboxEditorGui.DrawEmptyProperty(position, property, warningContent); } - /// /// Checks if provided property can be properly handled by this drawer. /// diff --git a/Assets/Editor Toolbox/Editor/Drawers/Toolbox/Decorator/DynamicHelpAttributeDrawer.cs b/Assets/Editor Toolbox/Editor/Drawers/Toolbox/Decorator/DynamicHelpAttributeDrawer.cs index 111cee7a..bb6077a3 100644 --- a/Assets/Editor Toolbox/Editor/Drawers/Toolbox/Decorator/DynamicHelpAttributeDrawer.cs +++ b/Assets/Editor Toolbox/Editor/Drawers/Toolbox/Decorator/DynamicHelpAttributeDrawer.cs @@ -8,7 +8,7 @@ public class DynamicHelpAttributeDrawer : ToolboxDecoratorDrawer { - private MethodInfo GetMethod(EditorButtonAttribute attribute, Object[] targetObjects, string methodName) + private MethodInfo GetMethod(EditorButtonAttribute attribute, object[] targetObjects, string methodName) { var methodInfo = ReflectionUtility.GetObjectMethod(methodName, targetObjects); if (methodInfo == null) @@ -50,7 +49,7 @@ private bool IsClickable(ButtonActivityType activityType) return true; } - private bool IsClickable(EditorButtonAttribute attribute, Object[] targetObjects) + private bool IsClickable(EditorButtonAttribute attribute, object[] targetObjects) { if (!IsClickable(attribute.ActivityType)) { @@ -93,7 +92,7 @@ private bool IsClickable(EditorButtonAttribute attribute, Object[] targetObjects return true; } - private void CallMethods(EditorButtonAttribute attribute, Object[] targetObjects) + private void CallMethods(EditorButtonAttribute attribute, object[] targetObjects) { var methodInfo = GetMethod(attribute, targetObjects, attribute.MethodName); if (methodInfo == null) @@ -120,17 +119,16 @@ private void CallMethods(EditorButtonAttribute attribute, Object[] targetObjects } } - protected override void OnGuiCloseSafe(EditorButtonAttribute attribute) { - var targetObjects = ToolboxEditorHandler.CurrentTargetObjects; - if (targetObjects == null || targetObjects.Length == 0) + var declaringObjects = GetDeclaringObjects(); + if (declaringObjects == null || declaringObjects.Length == 0) { //NOTE: something went really wrong, internal bug or OnGuiBeginSafe was called out of the Toolbox scope return; } - var disable = !IsClickable(attribute, targetObjects); + var disable = !IsClickable(attribute, declaringObjects); using (new EditorGUI.DisabledScope(disable)) { var label = string.IsNullOrEmpty(attribute.ExtraLabel) @@ -141,12 +139,11 @@ protected override void OnGuiCloseSafe(EditorButtonAttribute attribute) if (GUILayout.Button(content, Style.buttonStyle)) { - CallMethods(attribute, targetObjects); + CallMethods(attribute, declaringObjects); } } } - private static class Style { internal static readonly GUIStyle buttonStyle = new GUIStyle(GUI.skin.button) diff --git a/Assets/Editor Toolbox/Editor/Drawers/Toolbox/ToolboxAttributeDrawer.cs b/Assets/Editor Toolbox/Editor/Drawers/Toolbox/ToolboxAttributeDrawer.cs index d577b805..177d6a56 100644 --- a/Assets/Editor Toolbox/Editor/Drawers/Toolbox/ToolboxAttributeDrawer.cs +++ b/Assets/Editor Toolbox/Editor/Drawers/Toolbox/ToolboxAttributeDrawer.cs @@ -5,4 +5,4 @@ /// public abstract class ToolboxAttributeDrawer : ToolboxDrawer { } -} +} \ No newline at end of file diff --git a/Assets/Editor Toolbox/Editor/Drawers/Toolbox/ToolboxConditionDrawer.cs b/Assets/Editor Toolbox/Editor/Drawers/Toolbox/ToolboxConditionDrawer.cs index 62571b0e..e8f7120b 100644 --- a/Assets/Editor Toolbox/Editor/Drawers/Toolbox/ToolboxConditionDrawer.cs +++ b/Assets/Editor Toolbox/Editor/Drawers/Toolbox/ToolboxConditionDrawer.cs @@ -10,7 +10,6 @@ protected virtual PropertyCondition OnGuiValidateSafe(SerializedProperty propert return PropertyCondition.Valid; } - public sealed override PropertyCondition OnGuiValidate(SerializedProperty property) { return OnGuiValidate(property, PropertyUtility.GetAttribute(property)); diff --git a/Assets/Editor Toolbox/Editor/Drawers/Toolbox/ToolboxDecoratorDrawer.cs b/Assets/Editor Toolbox/Editor/Drawers/Toolbox/ToolboxDecoratorDrawer.cs index 1f5bbd7c..c7850357 100644 --- a/Assets/Editor Toolbox/Editor/Drawers/Toolbox/ToolboxDecoratorDrawer.cs +++ b/Assets/Editor Toolbox/Editor/Drawers/Toolbox/ToolboxDecoratorDrawer.cs @@ -1,5 +1,4 @@ using System; - using UnityEngine; namespace Toolbox.Editor.Drawers @@ -16,7 +15,6 @@ protected virtual void OnGuiCloseSafe(T attribute) protected virtual void OnGuiEndSafe(T attribute) { } - public sealed override void OnGuiBegin(ToolboxAttribute attribute) { OnGuiBegin(attribute as T); diff --git a/Assets/Editor Toolbox/Editor/Drawers/Toolbox/ToolboxDecoratorDrawerBase.cs b/Assets/Editor Toolbox/Editor/Drawers/Toolbox/ToolboxDecoratorDrawerBase.cs index 07bf359c..cd42964f 100644 --- a/Assets/Editor Toolbox/Editor/Drawers/Toolbox/ToolboxDecoratorDrawerBase.cs +++ b/Assets/Editor Toolbox/Editor/Drawers/Toolbox/ToolboxDecoratorDrawerBase.cs @@ -1,11 +1,41 @@ -using UnityEngine; +using System; +using UnityEngine; namespace Toolbox.Editor.Drawers { public abstract class ToolboxDecoratorDrawerBase : ToolboxAttributeDrawer { - public abstract void OnGuiBegin(ToolboxAttribute attribute); + protected object[] GetDeclaringObjects() + { + if (PropertyContext == null) + { + return Array.Empty(); + } + + var property = PropertyContext.Property; + return property.GetDeclaringObjects(); + } + + internal virtual void OnGuiBegin(ToolboxAttribute attribute, ISerializedPropertyContext propertyContext) + { + PropertyContext = propertyContext; + OnGuiBegin(attribute); + PropertyContext = null; + } + internal virtual void OnGuiClose(ToolboxAttribute attribute, ISerializedPropertyContext propertyContext) + { + PropertyContext = propertyContext; + OnGuiClose(attribute); + PropertyContext = null; + } + + public abstract void OnGuiBegin(ToolboxAttribute attribute); public abstract void OnGuiClose(ToolboxAttribute attribute); + + /// + /// Context associated with that is currently handled. + /// + protected ISerializedPropertyContext PropertyContext { get; private set; } } } \ No newline at end of file diff --git a/Assets/Editor Toolbox/Editor/Drawers/Toolbox/ToolboxPropertyDrawer.cs b/Assets/Editor Toolbox/Editor/Drawers/Toolbox/ToolboxPropertyDrawer.cs index fe8d693c..7b857b0e 100644 --- a/Assets/Editor Toolbox/Editor/Drawers/Toolbox/ToolboxPropertyDrawer.cs +++ b/Assets/Editor Toolbox/Editor/Drawers/Toolbox/ToolboxPropertyDrawer.cs @@ -10,18 +10,17 @@ protected virtual void OnGuiSafe(SerializedProperty property, GUIContent label, ToolboxEditorGui.DrawDefaultProperty(property, label); } - public override bool IsPropertyValid(SerializedProperty property) { return true; } - public override sealed void OnGui(SerializedProperty property, GUIContent label) + public sealed override void OnGui(SerializedProperty property, GUIContent label) { OnGui(property, label, PropertyUtility.GetAttribute(property)); } - public override sealed void OnGui(SerializedProperty property, GUIContent label, ToolboxAttribute attribute) + public sealed override void OnGui(SerializedProperty property, GUIContent label, ToolboxAttribute attribute) { OnGui(property, label, attribute as T); } @@ -39,10 +38,9 @@ public void OnGui(SerializedProperty property, GUIContent label, T attribute) return; } - var warningContent = new GUIContent(string.Format("{0} has invalid property drawer", property.displayName)); - //create additional warning log to the Console window ToolboxEditorLog.WrongAttributeUsageWarning(attribute, property); //create additional warning label based on the property name + var warningContent = new GUIContent(string.Format("{0} has invalid property drawer", property.displayName)); ToolboxEditorGui.DrawEmptyProperty(property, warningContent); } } diff --git a/Assets/Editor Toolbox/Editor/Drawers/Toolbox/ToolboxTargetTypeDrawer.cs b/Assets/Editor Toolbox/Editor/Drawers/Toolbox/ToolboxTargetTypeDrawer.cs index d2269a57..70036204 100644 --- a/Assets/Editor Toolbox/Editor/Drawers/Toolbox/ToolboxTargetTypeDrawer.cs +++ b/Assets/Editor Toolbox/Editor/Drawers/Toolbox/ToolboxTargetTypeDrawer.cs @@ -1,5 +1,4 @@ using System; - using UnityEditor; using UnityEngine; @@ -8,7 +7,6 @@ namespace Toolbox.Editor.Drawers public abstract class ToolboxTargetTypeDrawer : ToolboxDrawer { public abstract void OnGui(SerializedProperty property, GUIContent label); - public abstract Type GetTargetType(); public abstract bool UseForChildren(); } diff --git a/Assets/Editor Toolbox/Editor/ToolboxDrawerModule.cs b/Assets/Editor Toolbox/Editor/Drawers/ToolboxDrawersManager.cs similarity index 99% rename from Assets/Editor Toolbox/Editor/ToolboxDrawerModule.cs rename to Assets/Editor Toolbox/Editor/Drawers/ToolboxDrawersManager.cs index 429f9859..1d2b3970 100644 --- a/Assets/Editor Toolbox/Editor/ToolboxDrawerModule.cs +++ b/Assets/Editor Toolbox/Editor/Drawers/ToolboxDrawersManager.cs @@ -2,20 +2,18 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; - using UnityEditor; using UnityEngine; -namespace Toolbox.Editor +namespace Toolbox.Editor.Drawers { - using Toolbox.Editor.Drawers; - //TODO: //1. dedicated class to initialize and hold drawer-related data //2. dedicated class used for settings initialization //3. separate logic for resettings active drawers + //4. validations drawers - internal static class ToolboxDrawerModule + internal static class ToolboxDrawersManager { [InitializeOnLoadMethod] internal static void InitializeModule() @@ -199,7 +197,6 @@ private static void PrepareTargetTypeDrawers(IToolboxInspectorSettings settings) } } - /// /// Clears all currently cached s. /// @@ -231,7 +228,7 @@ internal static void UpdateDrawers() /// internal static void UpdateDrawers(IToolboxInspectorSettings settings) { - ToolboxDrawerModule.settings = settings; + ToolboxDrawersManager.settings = settings; if (settings == null) { @@ -254,7 +251,6 @@ internal static void UpdateDrawers(IToolboxInspectorSettings settings) validationEnabled = false; } - /// /// Determines if property has any associated drawer (built-in or custom one). /// This method does not take into account s. diff --git a/Assets/Editor Toolbox/Editor/Drawers/ToolboxDrawersManager.cs.meta b/Assets/Editor Toolbox/Editor/Drawers/ToolboxDrawersManager.cs.meta new file mode 100644 index 00000000..fab074e6 --- /dev/null +++ b/Assets/Editor Toolbox/Editor/Drawers/ToolboxDrawersManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1a6939216e93eb34eb34e53dab7eedb9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor Toolbox/Editor/ToolboxEditorDrawer.cs b/Assets/Editor Toolbox/Editor/Drawers/ToolboxEditorDrawer.cs similarity index 97% rename from Assets/Editor Toolbox/Editor/ToolboxEditorDrawer.cs rename to Assets/Editor Toolbox/Editor/Drawers/ToolboxEditorDrawer.cs index 24bea9df..4637b209 100644 --- a/Assets/Editor Toolbox/Editor/ToolboxEditorDrawer.cs +++ b/Assets/Editor Toolbox/Editor/Drawers/ToolboxEditorDrawer.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using UnityEditor; -namespace Toolbox.Editor +namespace Toolbox.Editor.Drawers { /// /// Default drawer responsible for drawing s. @@ -39,7 +39,7 @@ private void DrawProperty(SerializedProperty property, Action public void DrawEditor(SerializedObject serializedObject) { - if (ToolboxDrawerModule.ToolboxDrawersAllowed) + if (ToolboxDrawersManager.ToolboxDrawersAllowed) { DrawToolboxEditor(serializedObject); } diff --git a/Assets/Editor Toolbox/Editor/ToolboxEditorDrawer.cs.meta b/Assets/Editor Toolbox/Editor/Drawers/ToolboxEditorDrawer.cs.meta similarity index 100% rename from Assets/Editor Toolbox/Editor/ToolboxEditorDrawer.cs.meta rename to Assets/Editor Toolbox/Editor/Drawers/ToolboxEditorDrawer.cs.meta diff --git a/Assets/Editor Toolbox/Editor/ToolboxPropertyHandler.cs b/Assets/Editor Toolbox/Editor/Drawers/ToolboxPropertyHandler.cs similarity index 90% rename from Assets/Editor Toolbox/Editor/ToolboxPropertyHandler.cs rename to Assets/Editor Toolbox/Editor/Drawers/ToolboxPropertyHandler.cs index a2d9b97d..74c53159 100644 --- a/Assets/Editor Toolbox/Editor/ToolboxPropertyHandler.cs +++ b/Assets/Editor Toolbox/Editor/Drawers/ToolboxPropertyHandler.cs @@ -1,35 +1,18 @@ using System; using System.Collections.Generic; using System.Reflection; - using UnityEditor; using UnityEngine; -namespace Toolbox.Editor +namespace Toolbox.Editor.Drawers { using Toolbox.Attributes.Property; - using Toolbox.Editor.Drawers; /// /// Helper class used in display process. /// - internal class ToolboxPropertyHandler + internal class ToolboxPropertyHandler : ISerializedPropertyContext { - /// - /// Target property which contains all useful data about the associated field. - /// - private readonly SerializedProperty property; - - /// - /// Info associated to the . - /// - private readonly FieldInfo fieldInfo; - - /// - /// Type associated to the . - /// - private readonly Type type; - /// /// Determines whenever property is an array/list. /// @@ -95,7 +78,7 @@ internal class ToolboxPropertyHandler /// internal ToolboxPropertyHandler(SerializedProperty property) { - this.property = property; + this.Property = property; //here starts preparation of all needed data for this handler //first of all we have to retrieve the native data like FieldInfo, custom native drawer, etc. @@ -103,14 +86,15 @@ internal ToolboxPropertyHandler(SerializedProperty property) label = new GUIContent(property.displayName); //get FieldInfo associated to this property, it is needed to cache custom attributes - if ((fieldInfo = property.GetFieldInfo(out type)) == null) + if ((FieldInfo = property.GetFieldInfo(out var type)) == null) { return; } + Type = type; //initialize basic information about property isArray = property.isArray && property.propertyType == SerializedPropertyType.Generic; - isChild = property.name != fieldInfo.Name; + isChild = property.name != FieldInfo.Name; //try to fetch additional data about drawers ProcessBuiltInData(); @@ -119,13 +103,13 @@ internal ToolboxPropertyHandler(SerializedProperty property) private void ProcessBuiltInData() { - var attributes = fieldInfo.GetCustomAttributes(); + var attributes = FieldInfo.GetCustomAttributes(); foreach (var attribute in attributes) { HandleNewAttribute(attribute); } - CheckIfPropertyHasPropertyDrawer(type); + CheckIfPropertyHasPropertyDrawer(Type); } /// @@ -134,7 +118,7 @@ private void ProcessBuiltInData() private void ProcessToolboxData() { //get all possible attributes and handle each directly by type - var attributes = fieldInfo.GetCustomAttributes(); + var attributes = FieldInfo.GetCustomAttributes(); foreach (var attribute in attributes) { HandleNewAttribute(attribute); @@ -142,7 +126,7 @@ private void ProcessToolboxData() //check if property has a custom attribute or target type drawer hasToolboxPropertyAssignableDrawer = propertyAttribute != null; - hasToolboxPropertyTargetTypeDrawer = ToolboxDrawerModule.HasTargetTypeDrawer(type); + hasToolboxPropertyTargetTypeDrawer = ToolboxDrawersManager.HasTargetTypeDrawer(Type); //check if property has any of it and cache value hasToolboxPropertyDrawer = hasToolboxPropertyAssignableDrawer || hasToolboxPropertyTargetTypeDrawer; @@ -166,7 +150,7 @@ private void CheckIfPropertyHasPropertyDrawer(Type type) return; } - hasBuiltInPropertyDrawer = ToolboxDrawerModule.HasNativeTypeDrawer(type); + hasBuiltInPropertyDrawer = ToolboxDrawersManager.HasNativeTypeDrawer(type); } private void HandleNewAttribute(PropertyAttribute attribute) @@ -293,14 +277,14 @@ private void DrawProperty(SerializedProperty property, GUIContent label) { //draw target property using the associated attribute var propertyDrawer = isArray - ? ToolboxDrawerModule.GetListPropertyDrawer(propertyAttribute.GetType()) - : ToolboxDrawerModule.GetSelfPropertyDrawer(propertyAttribute.GetType()); + ? ToolboxDrawersManager.GetListPropertyDrawer(propertyAttribute.GetType()) + : ToolboxDrawersManager.GetSelfPropertyDrawer(propertyAttribute.GetType()); propertyDrawer?.OnGui(property, label, propertyAttribute); } else { //draw target property using the associated type drawer - ToolboxDrawerModule.GetTargetTypeDrawer(type)?.OnGui(property, label); + ToolboxDrawersManager.GetTargetTypeDrawer(Type)?.OnGui(property, label); } return; @@ -337,7 +321,7 @@ private void CloseDecoratorDrawers(PropertyCondition conditionState = PropertyCo private void HandleDecorator(ToolboxDecoratorAttribute attribute, bool onBegin, PropertyCondition conditionState = PropertyCondition.Valid) { - var drawer = ToolboxDrawerModule.GetDecoratorDrawer(attribute); + var drawer = ToolboxDrawersManager.GetDecoratorDrawer(attribute); if (drawer == null) { return; @@ -356,11 +340,11 @@ private void HandleDecorator(ToolboxDecoratorAttribute attribute, bool onBegin, { if (onBegin) { - drawer.OnGuiBegin(attribute); + drawer.OnGuiBegin(attribute, this); } else { - drawer.OnGuiClose(attribute); + drawer.OnGuiClose(attribute, this); } } } @@ -373,7 +357,7 @@ private PropertyCondition Validate(SerializedProperty property) return PropertyCondition.Valid; } - return ToolboxDrawerModule.GetConditionDrawer(conditionAttribute)?.OnGuiValidate(property, conditionAttribute) ?? PropertyCondition.Valid; + return ToolboxDrawersManager.GetConditionDrawer(conditionAttribute)?.OnGuiValidate(property, conditionAttribute) ?? PropertyCondition.Valid; } //TODO: replace this method with validation attributes @@ -408,7 +392,7 @@ public void OnGuiLayout() /// public void OnGuiLayout(GUIContent label) { - OnGuiLayout(property, label); + OnGuiLayout(Property, label); } /// @@ -462,7 +446,7 @@ public void OnGuiDefault() /// public void OnGuiDefault(GUIContent label) { - OnGuiDefault(property, label); + OnGuiDefault(Property, label); } /// @@ -496,5 +480,20 @@ public void OnGuiDefault(SerializedProperty property, GUIContent label) ToolboxEditorGui.DrawDefaultProperty(property, label); } } + + /// + /// Target property which contains all useful data about the associated field. + /// + public SerializedProperty Property { get; } + + /// + /// Info associated to the . + /// + public FieldInfo FieldInfo { get; } + + /// + /// Type associated to the . + /// + public Type Type { get; } } } \ No newline at end of file diff --git a/Assets/Editor Toolbox/Editor/ToolboxPropertyHandler.cs.meta b/Assets/Editor Toolbox/Editor/Drawers/ToolboxPropertyHandler.cs.meta similarity index 100% rename from Assets/Editor Toolbox/Editor/ToolboxPropertyHandler.cs.meta rename to Assets/Editor Toolbox/Editor/Drawers/ToolboxPropertyHandler.cs.meta diff --git a/Assets/Editor Toolbox/Editor/Editors/ToolboxScriptedImporterEditor.cs b/Assets/Editor Toolbox/Editor/Editors/ToolboxScriptedImporterEditor.cs index dac9cd7a..533fc90b 100644 --- a/Assets/Editor Toolbox/Editor/Editors/ToolboxScriptedImporterEditor.cs +++ b/Assets/Editor Toolbox/Editor/Editors/ToolboxScriptedImporterEditor.cs @@ -7,6 +7,7 @@ namespace Toolbox.Editor.Editors { + using Toolbox.Editor.Drawers; using Editor = UnityEditor.Editor; public class ToolboxScriptedImporterEditor : ScriptedImporterEditor, IToolboxEditor diff --git a/Assets/Editor Toolbox/Editor/Management.meta b/Assets/Editor Toolbox/Editor/Management.meta new file mode 100644 index 00000000..96ef8a07 --- /dev/null +++ b/Assets/Editor Toolbox/Editor/Management.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0474bb9eb314af742958e546dba2c098 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor Toolbox/Editor/ToolboxAssetProcessor.cs b/Assets/Editor Toolbox/Editor/Management/ToolboxAssetProcessor.cs similarity index 93% rename from Assets/Editor Toolbox/Editor/ToolboxAssetProcessor.cs rename to Assets/Editor Toolbox/Editor/Management/ToolboxAssetProcessor.cs index 283faa1f..25ce466a 100644 --- a/Assets/Editor Toolbox/Editor/ToolboxAssetProcessor.cs +++ b/Assets/Editor Toolbox/Editor/Management/ToolboxAssetProcessor.cs @@ -1,7 +1,7 @@ using UnityEditor; using AssetProcessor = UnityEditor.AssetModificationProcessor; -namespace Toolbox.Editor +namespace Toolbox.Editor.Management { public class ToolboxAssetProcessor : AssetProcessor { diff --git a/Assets/Editor Toolbox/Editor/ToolboxAssetProcessor.cs.meta b/Assets/Editor Toolbox/Editor/Management/ToolboxAssetProcessor.cs.meta similarity index 100% rename from Assets/Editor Toolbox/Editor/ToolboxAssetProcessor.cs.meta rename to Assets/Editor Toolbox/Editor/Management/ToolboxAssetProcessor.cs.meta diff --git a/Assets/Editor Toolbox/Editor/ToolboxManager.cs b/Assets/Editor Toolbox/Editor/Management/ToolboxManager.cs similarity index 98% rename from Assets/Editor Toolbox/Editor/ToolboxManager.cs rename to Assets/Editor Toolbox/Editor/Management/ToolboxManager.cs index 1136af29..e66e1f14 100644 --- a/Assets/Editor Toolbox/Editor/ToolboxManager.cs +++ b/Assets/Editor Toolbox/Editor/Management/ToolboxManager.cs @@ -1,12 +1,12 @@ using System.Collections; using System.IO; - using Unity.EditorCoroutines.Editor; using UnityEditor; using UnityEngine; -namespace Toolbox.Editor +namespace Toolbox.Editor.Management { + using Toolbox.Editor.Drawers; using Editor = UnityEditor.Editor; internal static class ToolboxManager @@ -27,7 +27,7 @@ private static void ForceModulesUpdate() private static void ManageInspectorCore(IToolboxInspectorSettings settings) { //setup all available drawers using the internal module - ToolboxDrawerModule.UpdateDrawers(settings); + ToolboxDrawersManager.UpdateDrawers(settings); } private static void ManageProjectCore(IToolboxProjectSettings settings) diff --git a/Assets/Editor Toolbox/Editor/ToolboxManager.cs.meta b/Assets/Editor Toolbox/Editor/Management/ToolboxManager.cs.meta similarity index 100% rename from Assets/Editor Toolbox/Editor/ToolboxManager.cs.meta rename to Assets/Editor Toolbox/Editor/Management/ToolboxManager.cs.meta diff --git a/Assets/Editor Toolbox/Editor/ToolboxEditor.cs b/Assets/Editor Toolbox/Editor/ToolboxEditor.cs index 3fec514a..26f7b6ca 100644 --- a/Assets/Editor Toolbox/Editor/ToolboxEditor.cs +++ b/Assets/Editor Toolbox/Editor/ToolboxEditor.cs @@ -3,6 +3,7 @@ namespace Toolbox.Editor { + using Toolbox.Editor.Drawers; using Editor = UnityEditor.Editor; using Object = UnityEngine.Object; diff --git a/Assets/Editor Toolbox/Editor/ToolboxEditorGui.cs b/Assets/Editor Toolbox/Editor/ToolboxEditorGui.cs index fb4843d1..a7287573 100644 --- a/Assets/Editor Toolbox/Editor/ToolboxEditorGui.cs +++ b/Assets/Editor Toolbox/Editor/ToolboxEditorGui.cs @@ -1,11 +1,11 @@ using System; - using UnityEditor; using UnityEngine; using Object = UnityEngine.Object; namespace Toolbox.Editor { + using Toolbox.Editor.Drawers; using Toolbox.Editor.Internal; /// @@ -434,7 +434,7 @@ public static void DrawToolboxProperty(Rect position, SerializedProperty propert /// public static void DrawToolboxProperty(SerializedProperty property) { - ToolboxDrawerModule.GetPropertyHandler(property)?.OnGuiLayout(property); + ToolboxDrawersManager.GetPropertyHandler(property)?.OnGuiLayout(property); } /// @@ -443,7 +443,7 @@ public static void DrawToolboxProperty(SerializedProperty property) /// public static void DrawToolboxProperty(SerializedProperty property, GUIContent label) { - ToolboxDrawerModule.GetPropertyHandler(property)?.OnGuiLayout(property, label); + ToolboxDrawersManager.GetPropertyHandler(property)?.OnGuiLayout(property, label); } /// diff --git a/Assets/Editor Toolbox/Editor/ToolboxEditorLog.cs b/Assets/Editor Toolbox/Editor/ToolboxEditorLog.cs index b2bbc09b..22a80a57 100644 --- a/Assets/Editor Toolbox/Editor/ToolboxEditorLog.cs +++ b/Assets/Editor Toolbox/Editor/ToolboxEditorLog.cs @@ -1,9 +1,7 @@ using System; using System.Text; - using UnityEditor; using UnityEngine; -using UnityEngine.Rendering; using Object = UnityEngine.Object; namespace Toolbox.Editor @@ -13,7 +11,6 @@ internal static class ToolboxEditorLog private const string tag = "Editor Toolbox"; private const string format = "[{0}] {1}"; - private static string GetPropertySceneLocation(SerializedProperty property) { return string.Format("{0} property in {1}", property.name, property.serializedObject.targetObject); @@ -28,7 +25,6 @@ private static string GetMemberNotFoundMessage(Type classType, string memberName return stringBuilder.ToString(); } - internal static void AttributeUsageWarning(Attribute attribute, string message) { AttributeUsageWarning(attribute.GetType(), message); diff --git a/Assets/Editor Toolbox/Editor/ToolboxEditorProject.cs b/Assets/Editor Toolbox/Editor/ToolboxEditorProject.cs index d05a1441..bcd4af6d 100644 --- a/Assets/Editor Toolbox/Editor/ToolboxEditorProject.cs +++ b/Assets/Editor Toolbox/Editor/ToolboxEditorProject.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.IO; - using UnityEditor; using UnityEngine; @@ -20,10 +19,8 @@ static ToolboxEditorProject() EditorApplication.projectWindowItemOnGUI += OnItemCallback; } - - private readonly static Dictionary pathBasedFoldersData = new Dictionary(); - private readonly static Dictionary nameBasedFoldersData = new Dictionary(); - + private static readonly Dictionary pathBasedFoldersData = new Dictionary(); + private readonly static Dictionary nameBasedFoldersData = new(); /// /// Draws icons and additional tooltips for matched assets. @@ -50,7 +47,6 @@ private static void OnItemCallback(string guid, Rect rect) } } - /// /// Tries to retrive associated to given path. /// @@ -78,7 +74,6 @@ private static bool TryGetFolderIcon(FolderData data, Rect labelRect, out Textur return true; } - /// /// Creates a custom folder using given data. /// @@ -120,7 +115,6 @@ internal static void ClearCustomFolders() nameBasedFoldersData.Clear(); } - internal static Rect GetLargeIconRect(Rect folderIconRect) { return GetLargeIconRect(folderIconRect, false); @@ -189,7 +183,6 @@ internal static Rect GetSmallIconRect(Rect folderIconRect) internal static void RepaintProjectOverlay() => EditorApplication.RepaintProjectWindow(); - /// /// Determines if can create an additional overlay on the Project Window. /// @@ -213,7 +206,6 @@ internal static Rect GetSmallIconRect(Rect folderIconRect) /// internal static Vector2 SmallIconPaddingRatio { get; set; } = new Vector2(0, 0); - internal static class Defaults { /// diff --git a/Assets/Editor Toolbox/Editor/ToolboxEditorSettings.cs b/Assets/Editor Toolbox/Editor/ToolboxEditorSettings.cs index 8ed7b1ab..b53f9b13 100644 --- a/Assets/Editor Toolbox/Editor/ToolboxEditorSettings.cs +++ b/Assets/Editor Toolbox/Editor/ToolboxEditorSettings.cs @@ -289,7 +289,7 @@ public void ResetSceneSettings() public void SetAllPossibleDecoratorDrawers() { decoratorDrawerHandlers.Clear(); - var types = ToolboxDrawerModule.GetAllPossibleDecoratorDrawers(); + var types = ToolboxDrawersManager.GetAllPossibleDecoratorDrawers(); for (var i = 0; i < types.Count; i++) { decoratorDrawerHandlers.Add(new SerializedType(types[i])); @@ -299,7 +299,7 @@ public void SetAllPossibleDecoratorDrawers() public void SetAllPossibleConditionDrawers() { conditionDrawerHandlers.Clear(); - var types = ToolboxDrawerModule.GetAllPossibleConditionDrawers(); + var types = ToolboxDrawersManager.GetAllPossibleConditionDrawers(); for (var i = 0; i < types.Count; i++) { conditionDrawerHandlers.Add(new SerializedType(types[i])); @@ -309,7 +309,7 @@ public void SetAllPossibleConditionDrawers() public void SetAllPossibleSelfPropertyDrawers() { selfPropertyDrawerHandlers.Clear(); - var types = ToolboxDrawerModule.GetAllPossibleSelfPropertyDrawers(); + var types = ToolboxDrawersManager.GetAllPossibleSelfPropertyDrawers(); for (var i = 0; i < types.Count; i++) { selfPropertyDrawerHandlers.Add(new SerializedType(types[i])); @@ -319,7 +319,7 @@ public void SetAllPossibleSelfPropertyDrawers() public void SetAllPossibleListPropertyDrawers() { listPropertyDrawerHandlers.Clear(); - var types = ToolboxDrawerModule.GetAllPossibleListPropertyDrawers(); + var types = ToolboxDrawersManager.GetAllPossibleListPropertyDrawers(); for (var i = 0; i < types.Count; i++) { listPropertyDrawerHandlers.Add(new SerializedType(types[i])); @@ -329,7 +329,7 @@ public void SetAllPossibleListPropertyDrawers() public void SetAllPossibleTargetTypeDrawers() { targetTypeDrawerHandlers.Clear(); - var types = ToolboxDrawerModule.GetAllPossibleTargetTypeDrawers(); + var types = ToolboxDrawersManager.GetAllPossibleTargetTypeDrawers(); for (var i = 0; i < types.Count; i++) { targetTypeDrawerHandlers.Add(new SerializedType(types[i])); diff --git a/Assets/Editor Toolbox/Editor/ToolboxEditorSettingsEditor.cs b/Assets/Editor Toolbox/Editor/ToolboxEditorSettingsEditor.cs index 280253de..4eb483c7 100644 --- a/Assets/Editor Toolbox/Editor/ToolboxEditorSettingsEditor.cs +++ b/Assets/Editor Toolbox/Editor/ToolboxEditorSettingsEditor.cs @@ -44,7 +44,6 @@ internal class ToolboxEditorSettingsEditor : ToolboxEditor private string[] drawerHandlersShortNames; private string[] drawerHandlersInfoLabels; - private void OnEnable() { currentTarget = target as ToolboxEditorSettings; @@ -418,7 +417,6 @@ private void ValidateDrawers() ToolboxEditorLog.LogInfo("Function not implemented."); } - public override void DrawCustomInspector() { serializedObject.Update(); diff --git a/Assets/Editor Toolbox/Editor/ToolboxLayoutHandler.cs b/Assets/Editor Toolbox/Editor/ToolboxLayoutHandler.cs index 13b8e4b7..42a5d807 100644 --- a/Assets/Editor Toolbox/Editor/ToolboxLayoutHandler.cs +++ b/Assets/Editor Toolbox/Editor/ToolboxLayoutHandler.cs @@ -26,7 +26,6 @@ static ToolboxLayoutHandler() ToolboxEditorHandler.OnEditorReload += ResetCache; } - /// /// Determines whether we are currently within any Editor's layout scope. /// @@ -40,7 +39,6 @@ static ToolboxLayoutHandler() private static int vLayoutClips; private static int hLayoutClips; - private static void OnBeginEditor(Editor editor) { nestingLevel++; @@ -99,7 +97,6 @@ private static bool ValidateScopes() return true; } - internal static Rect BeginVertical() { return BeginVertical(GUIStyle.none); diff --git a/Assets/Editor Toolbox/Editor/ToolboxPrefs.cs b/Assets/Editor Toolbox/Editor/ToolboxPrefs.cs index c74d88d0..a34c773f 100644 --- a/Assets/Editor Toolbox/Editor/ToolboxPrefs.cs +++ b/Assets/Editor Toolbox/Editor/ToolboxPrefs.cs @@ -1,5 +1,4 @@ using System; - using UnityEditor; namespace Toolbox.Editor diff --git a/Assets/Editor Toolbox/Editor/Utilities/PropertyUtility.cs b/Assets/Editor Toolbox/Editor/Utilities/PropertyUtility.cs index f432b958..e3b85044 100644 --- a/Assets/Editor Toolbox/Editor/Utilities/PropertyUtility.cs +++ b/Assets/Editor Toolbox/Editor/Utilities/PropertyUtility.cs @@ -117,6 +117,27 @@ public static object GetDeclaringObject(this SerializedProperty property, Object return validReference; } + public static object[] GetDeclaringObjects(this SerializedProperty property) + { + var targetObjects = property.serializedObject.targetObjects; + var parentObjects = new object[targetObjects.Length]; + GetDeclaringObjectsNonAlloc(property, parentObjects); + return parentObjects; + } + + public static int GetDeclaringObjectsNonAlloc(this SerializedProperty property, object[] result) + { + var targetObjects = property.serializedObject.targetObjects; + var targetObjectsCount = targetObjects.Length; + for (var i = 0; i < targetObjectsCount; i++) + { + var targetObject = targetObjects[i]; + result[i] = property.GetDeclaringObject(targetObject); + } + + return targetObjectsCount; + } + public static object GetTreePathReference(string treeField, object treeParent) { if (IsSerializableArrayElement(treeField, out var index)) diff --git a/Assets/Editor Toolbox/Editor/Utilities/ReflectionUtility.cs b/Assets/Editor Toolbox/Editor/Utilities/ReflectionUtility.cs index c82d4203..bc0ec8fe 100644 --- a/Assets/Editor Toolbox/Editor/Utilities/ReflectionUtility.cs +++ b/Assets/Editor Toolbox/Editor/Utilities/ReflectionUtility.cs @@ -26,12 +26,12 @@ internal static MethodInfo GetObjectMethod(string methodName, SerializedObject s return GetObjectMethod(methodName, serializedObject.targetObjects); } - internal static MethodInfo GetObjectMethod(string methodName, params Object[] targetObjects) + internal static MethodInfo GetObjectMethod(string methodName, params object[] targetObjects) { return GetObjectMethod(methodName, allBindings, targetObjects); } - internal static MethodInfo GetObjectMethod(string methodName, BindingFlags bindingFlags, params Object[] targetObjects) + internal static MethodInfo GetObjectMethod(string methodName, BindingFlags bindingFlags, params object[] targetObjects) { if (targetObjects == null || targetObjects.Length == 0) { diff --git a/Assets/Editor Toolbox/README.md b/Assets/Editor Toolbox/README.md index 5bdd6f33..2dbabff7 100644 --- a/Assets/Editor Toolbox/README.md +++ b/Assets/Editor Toolbox/README.md @@ -278,22 +278,53 @@ public int layer; ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/layer.png) +#### AnimationCurveSettingsAttribute + +Supported types: **AnimationCurve**. + +```csharp +[AnimationCurveSettings(-2, -2, 2, 2, HexColor = "#FFD666")] +public AnimationCurve animationCurve +``` + +![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/animationcurvesettings.png) + #### ChildObjectOnlyAttribute Supported types: **GameObject, Component**. +```csharp +[ChildObjectOnlyAttribute] +public GameObject var1 +``` + #### SceneObjectOnlyAttribute Supported types: **GameObject, Component**. +```csharp +[SceneObjectOnlyAttribute] +public GameObject var1 +``` + #### PrefabObjectOnlyAttribute Supported types: **GameObject, Component**. +```csharp +[PrefabObjectOnlyAttribute] +public GameObject var1 +``` + #### NotPrefabObjectOnlyAttribute Supported types: **GameObject, Component**. +```csharp +[NotPrefabObjectOnlyAttribute] +public GameObject var1 +``` + --- ### Toolbox Drawers diff --git a/Assets/Editor Toolbox/Runtime/Attributes/Property/Regular/AnimationCurveSettingsAttribute.cs b/Assets/Editor Toolbox/Runtime/Attributes/Property/Regular/AnimationCurveSettingsAttribute.cs new file mode 100644 index 00000000..f2af9ffc --- /dev/null +++ b/Assets/Editor Toolbox/Runtime/Attributes/Property/Regular/AnimationCurveSettingsAttribute.cs @@ -0,0 +1,42 @@ +using System; +using System.Diagnostics; + +namespace UnityEngine +{ + /// + /// Allows to draw in a custom way, e.g. you can specify the range. + /// + /// Supported types: any . + /// + [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + [Conditional("UNITY_EDITOR")] + public class AnimationCurveSettingsAttribute : PropertyAttribute + { + public AnimationCurveSettingsAttribute() + : this(Vector2.zero, Vector2.one) + { } + + public AnimationCurveSettingsAttribute(float minX, float minY, float maxX, float maxY) + : this(new Vector2(minX, minY), new Vector2(maxX, maxY)) + { } + + public AnimationCurveSettingsAttribute(Vector2 min, Vector2 max) + { + Min = min; + Max = max; + } + + public Vector2 Min { get; private set; } + + public Vector2 Max { get; private set; } + + public Color Color + { + get => ColorUtility.TryParseHtmlString(HexColor, out var color) + ? color + : Color.green; + } + + public string HexColor { get; set; } + } +} \ No newline at end of file diff --git a/Assets/Editor Toolbox/Runtime/Attributes/Property/Regular/AnimationCurveSettingsAttribute.cs.meta b/Assets/Editor Toolbox/Runtime/Attributes/Property/Regular/AnimationCurveSettingsAttribute.cs.meta new file mode 100644 index 00000000..88c0372f --- /dev/null +++ b/Assets/Editor Toolbox/Runtime/Attributes/Property/Regular/AnimationCurveSettingsAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2e572c536d703b044be1be27fa0b7596 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Examples/Scenes/SampleScene.unity b/Assets/Examples/Scenes/SampleScene.unity index 58f6e488..98718f9c 100644 --- a/Assets/Examples/Scenes/SampleScene.unity +++ b/Assets/Examples/Scenes/SampleScene.unity @@ -2209,6 +2209,8 @@ MonoBehaviour: var56: 0 veryVeryVeryVeryVeryLongName: 0 var57: 0 + nestedObject: + var0: -12 --- !u!4 &1438743619 Transform: m_ObjectHideFlags: 2 diff --git a/Assets/Examples/Scripts/SampleBehaviour1.cs b/Assets/Examples/Scripts/SampleBehaviour1.cs index 830418f4..281e0537 100644 --- a/Assets/Examples/Scripts/SampleBehaviour1.cs +++ b/Assets/Examples/Scripts/SampleBehaviour1.cs @@ -107,6 +107,13 @@ public enum FlagExample "are part of group that will be re-implemented in future as ToolboxValidationAttributes. " + "Unfortunately, for now, you can't use them together with any other PropertyDrawer.", UnityMessageType.Warning, Order = -1)] + [Label("Animation Curve Settings", skinStyle: SkinStyle.Box)] + + [AnimationCurveSettings] + public AnimationCurve animationCurve1; + [AnimationCurveSettings(-1.0f, -1.0f, 2.0f, 2.0f, HexColor = "#360E45")] + public AnimationCurve animationCurve2; + [Label("Validation", skinStyle: SkinStyle.Box)] [Clamp(0.0f, 11.2f)] diff --git a/Assets/Examples/Scripts/SampleBehaviour2.cs b/Assets/Examples/Scripts/SampleBehaviour2.cs index d7cc1ac2..56501984 100644 --- a/Assets/Examples/Scripts/SampleBehaviour2.cs +++ b/Assets/Examples/Scripts/SampleBehaviour2.cs @@ -1,4 +1,5 @@ -using UnityEngine; +using System; +using UnityEngine; [ExecuteAlways] [AddComponentMenu("Editor Toolbox/Cheat Sheet 2 (Toolbox Property)")] @@ -21,7 +22,7 @@ public class SampleBehaviour2 : MonoBehaviour public int GetValue() { - return ints.Length * Random.Range(1, 5); + return ints.Length * UnityEngine.Random.Range(1, 5); } [Label("InLine Editor", skinStyle: SkinStyle.Box)] @@ -63,10 +64,10 @@ public int GetValue() [Label("Nested Objects", skinStyle: SkinStyle.Box)] - [Help("You can use Toolbox Properties inside serializable types without limitations.")] + [Help("You can use Toolbox Attributes inside serializable types without limitations.")] public SampleNestedClass nestedObject; - [System.Serializable] + [Serializable] public class SampleNestedClass { [Tooltip("Set to 1")] diff --git a/Assets/Examples/Scripts/SampleBehaviour4.cs b/Assets/Examples/Scripts/SampleBehaviour4.cs index ce7ecb65..4c6224ca 100644 --- a/Assets/Examples/Scripts/SampleBehaviour4.cs +++ b/Assets/Examples/Scripts/SampleBehaviour4.cs @@ -1,11 +1,29 @@ -using System.Collections; - +using System; +using System.Collections; using UnityEngine; [ExecuteAlways] [AddComponentMenu("Editor Toolbox/Cheat Sheet 4 (Toolbox Decorators)")] public class SampleBehaviour4 : MonoBehaviour { + [Serializable] + private class SampleNestedClass + { + [DynamicHelp(nameof(GetHelpMessage), UnityMessageType.Info)] + [EditorButton(nameof(TestNestedMethod))] + public int var0; + + private void TestNestedMethod() + { + Debug.Log(nameof(TestNestedMethod) + " is called"); + } + + private string GetHelpMessage() + { + return $"Var0 == {var0}"; + } + } + [Label("Help", skinStyle: SkinStyle.Box)] [Disable] @@ -130,4 +148,11 @@ private static void TestStaticMethod() [Title("Standard Title")] public int var57; + + [Label("Nested Objects", skinStyle: SkinStyle.Box)] + + [Help("You can use Toolbox Attributes inside serializable types without limitations.")] + [SerializeField] + private SampleNestedClass nestedObject; + } \ No newline at end of file diff --git a/Assets/Examples/Scripts/SampleBehaviour6.cs b/Assets/Examples/Scripts/SampleBehaviour6.cs index 31d43fc3..259aa6e7 100644 --- a/Assets/Examples/Scripts/SampleBehaviour6.cs +++ b/Assets/Examples/Scripts/SampleBehaviour6.cs @@ -1,5 +1,4 @@ using System; - using UnityEngine; using UnityEngine.Scripting.APIUpdating; diff --git a/README.md b/README.md index d6e747e5..2dbabff7 100644 --- a/README.md +++ b/README.md @@ -278,22 +278,53 @@ public int layer; ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/layer.png) +#### AnimationCurveSettingsAttribute + +Supported types: **AnimationCurve**. + +```csharp +[AnimationCurveSettings(-2, -2, 2, 2, HexColor = "#FFD666")] +public AnimationCurve animationCurve +``` + +![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/animationcurvesettings.png) + #### ChildObjectOnlyAttribute Supported types: **GameObject, Component**. +```csharp +[ChildObjectOnlyAttribute] +public GameObject var1 +``` + #### SceneObjectOnlyAttribute Supported types: **GameObject, Component**. +```csharp +[SceneObjectOnlyAttribute] +public GameObject var1 +``` + #### PrefabObjectOnlyAttribute Supported types: **GameObject, Component**. +```csharp +[PrefabObjectOnlyAttribute] +public GameObject var1 +``` + #### NotPrefabObjectOnlyAttribute Supported types: **GameObject, Component**. +```csharp +[NotPrefabObjectOnlyAttribute] +public GameObject var1 +``` + --- ### Toolbox Drawers @@ -550,16 +581,11 @@ public GameObject[] largeArray = new GameObject[19]; ##### Other ToolboxProperty attributes -**IgnoreParent** allows you to hide the parent's label, foldout arrow and remove the standard indentation for nested fields. - ```csharp -public Quaternion quaternion; [IgnoreParent] public Quaternion q; ``` -![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/ignoreparent.png) - ```csharp [DynamicMinMaxSlider(nameof(minValue), nameof(MaxValue))] public Vector2 vec2;