From 063e83ea78fc253c93de130f4676a8b110325551 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Matkowski?= Date: Fri, 30 Aug 2024 21:44:00 +0200 Subject: [PATCH 01/21] Force standalone tests in the test.yml workflow --- .github/workflows/test.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4833111e..07a70e25 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -43,7 +43,10 @@ jobs: - uses: game-ci/unity-test-runner@v2 id: testRunner with: - testMode: all + testMode: + - playmode + - editmode + - standalone - uses: actions/upload-artifact@v2 with: From fe9e2c4268d2ea0f6dfeeb44a9ecba147f77ef68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Matkowski?= Date: Fri, 30 Aug 2024 21:51:01 +0200 Subject: [PATCH 02/21] Change actions to latest versions --- .github/workflows/test.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 07a70e25..a2f7536b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,13 +13,13 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Create LFS file list run: git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id - name: Restore LFS cache - uses: actions/cache@v2 + uses: actions/cache@v3 id: lfs-cache with: path: .git/lfs @@ -40,7 +40,7 @@ jobs: Library-test-project- Library- - - uses: game-ci/unity-test-runner@v2 + - uses: game-ci/unity-test-runner@v4 id: testRunner with: testMode: @@ -48,7 +48,7 @@ jobs: - editmode - standalone - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 with: name: Test results (all modes) path: ${{ steps.testRunner.outputs.artifactsPath }} \ No newline at end of file From c71df7761ed1ef06f32740a4d21e927883653edc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Matkowski?= Date: Fri, 30 Aug 2024 21:55:49 +0200 Subject: [PATCH 03/21] Use matrixes to setup initial test data --- .github/workflows/test.yml | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a2f7536b..b0f992ef 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,8 +9,17 @@ env: jobs: testRunner: - name: Test all modes 📝 + name: Test ${{ matrix.testMode }} 📝 runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + projectPath: + - test-project + testMode: + - playmode + - editmode + - standalone steps: - name: Checkout code uses: actions/checkout@v4 @@ -43,12 +52,12 @@ jobs: - uses: game-ci/unity-test-runner@v4 id: testRunner with: - testMode: - - playmode - - editmode - - standalone + testMode: ${{ matrix.testMode }} + artifactsPath: ${{ matrix.testMode }}-artifacts + checkName: ${{ matrix.testMode }} Test Results - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v3 + if: always() with: - name: Test results (all modes) - path: ${{ steps.testRunner.outputs.artifactsPath }} \ No newline at end of file + name: Test results for ${{ matrix.testMode }} + path: ${{ steps.tests.outputs.artifactsPath }} \ No newline at end of file From 2920190b3697259dfa9638e49cf6e691af8d1b0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Matkowski?= Date: Fri, 30 Aug 2024 21:57:38 +0200 Subject: [PATCH 04/21] Attempt to fix syntax --- .github/workflows/test.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b0f992ef..2b28e223 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,13 +9,11 @@ env: jobs: testRunner: - name: Test ${{ matrix.testMode }} 📝 + name: Test 📝 runs-on: ubuntu-latest strategy: fail-fast: false matrix: - projectPath: - - test-project testMode: - playmode - editmode From f8cdebaad25428606f822b834066c08f78ac41a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Matkowski?= Date: Fri, 30 Aug 2024 22:04:25 +0200 Subject: [PATCH 05/21] Attempt to fix syntax --- .github/workflows/test.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2b28e223..e9da76d5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,15 +9,15 @@ env: jobs: testRunner: - name: Test 📝 + name: Test runs-on: ubuntu-latest strategy: - fail-fast: false - matrix: - testMode: - - playmode - - editmode - - standalone + fail-fast: false + matrix: + testMode: + - playmode + - editmode + - standalone steps: - name: Checkout code uses: actions/checkout@v4 From a2608c79ebbe196d006620eb170724b2456800bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Matkowski?= Date: Fri, 30 Aug 2024 22:06:23 +0200 Subject: [PATCH 06/21] Attempt to fix syntax --- .github/workflows/test.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e9da76d5..f08eb157 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,16 +8,16 @@ env: UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }} jobs: - testRunner: - name: Test + testAllModes: + name: Test in ${{ matrix.testMode }} runs-on: ubuntu-latest strategy: - fail-fast: false - matrix: - testMode: - - playmode - - editmode - - standalone + fail-fast: false + matrix: + testMode: + - playmode + - editmode + - standalone steps: - name: Checkout code uses: actions/checkout@v4 From eaa761528633d79291d9424d009801fa4647f8a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Matkowski?= Date: Fri, 30 Aug 2024 22:40:44 +0200 Subject: [PATCH 07/21] Attempt to fix syntax --- .github/workflows/test.yml | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f08eb157..ea60c1ad 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,7 +9,7 @@ env: jobs: testAllModes: - name: Test in ${{ matrix.testMode }} + name: Test in '${{ matrix.testMode }}' 📝 runs-on: ubuntu-latest strategy: fail-fast: false @@ -19,42 +19,23 @@ jobs: - editmode - standalone steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Create LFS file list - run: git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id - - - name: Restore LFS cache - uses: actions/cache@v3 - id: lfs-cache + - uses: actions/checkout@v4 with: - path: .git/lfs - key: ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }} - - - name: Git LFS Pull - run: | - git lfs pull - git add . - git reset --hard - - - name: Restore Library cache - uses: actions/cache@v2 + lfs: true + - uses: actions/cache@v3 with: path: Library key: Library-test-project restore-keys: | Library-test-project- Library- - - uses: game-ci/unity-test-runner@v4 - id: testRunner + id: tests with: testMode: ${{ matrix.testMode }} artifactsPath: ${{ matrix.testMode }}-artifacts checkName: ${{ matrix.testMode }} Test Results - - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v3 if: always() with: name: Test results for ${{ matrix.testMode }} From 1c10ddd6b32b617c2a9beaa41e7e436b58db9123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Matkowski?= Date: Fri, 30 Aug 2024 23:02:55 +0200 Subject: [PATCH 08/21] Add secrets --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ea60c1ad..66cda1f3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,6 +6,8 @@ on: env: UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }} + UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }} + UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }} jobs: testAllModes: From b7e5fa9af2e2b8f18cc99a8e56261a6d6d1af07c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Matkowski?= Date: Fri, 30 Aug 2024 23:11:28 +0200 Subject: [PATCH 09/21] Break code compilation (temp) --- .../Runtime/Serialization/SerializedDirectory.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Assets/Editor Toolbox/Runtime/Serialization/SerializedDirectory.cs b/Assets/Editor Toolbox/Runtime/Serialization/SerializedDirectory.cs index ecd11ece..2b7df920 100644 --- a/Assets/Editor Toolbox/Runtime/Serialization/SerializedDirectory.cs +++ b/Assets/Editor Toolbox/Runtime/Serialization/SerializedDirectory.cs @@ -16,7 +16,7 @@ public class SerializedDirectory : ISerializationCallbackReceiver [SerializeField, Disable] private string path; -#if UNITY_EDITOR +//#if UNITY_EDITOR internal static bool IsAssetValid(DefaultAsset asset, out string path) { path = asset != null ? AssetDatabase.GetAssetPath(asset) : null; @@ -34,7 +34,7 @@ internal static bool IsAssetValid(DefaultAsset asset, out string path) return false; } -#endif +//#endif void ISerializationCallbackReceiver.OnAfterDeserialize() { } From ef753793d956f050d4e6500dac0c49aa9bbebca7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Matkowski?= Date: Fri, 30 Aug 2024 23:24:04 +0200 Subject: [PATCH 10/21] Restore appropriate code --- .../Runtime/Serialization/SerializedDirectory.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Assets/Editor Toolbox/Runtime/Serialization/SerializedDirectory.cs b/Assets/Editor Toolbox/Runtime/Serialization/SerializedDirectory.cs index 2b7df920..ecd11ece 100644 --- a/Assets/Editor Toolbox/Runtime/Serialization/SerializedDirectory.cs +++ b/Assets/Editor Toolbox/Runtime/Serialization/SerializedDirectory.cs @@ -16,7 +16,7 @@ public class SerializedDirectory : ISerializationCallbackReceiver [SerializeField, Disable] private string path; -//#if UNITY_EDITOR +#if UNITY_EDITOR internal static bool IsAssetValid(DefaultAsset asset, out string path) { path = asset != null ? AssetDatabase.GetAssetPath(asset) : null; @@ -34,7 +34,7 @@ internal static bool IsAssetValid(DefaultAsset asset, out string path) return false; } -//#endif +#endif void ISerializationCallbackReceiver.OnAfterDeserialize() { } From 89c51b90da419c472e955d2182715d416759e4ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Matkowski?= Date: Mon, 9 Sep 2024 01:04:17 +0200 Subject: [PATCH 11/21] Conditional CustomEditor override --- Assets/Editor Toolbox/Editor/ToolboxDefines.cs | 1 + .../Editor/ToolboxDrawerModule.cs | 17 ++++++++++++++++- Assets/Editor Toolbox/Editor/ToolboxEditor.cs | 2 ++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Assets/Editor Toolbox/Editor/ToolboxDefines.cs b/Assets/Editor Toolbox/Editor/ToolboxDefines.cs index 974700a0..1a3cfde4 100644 --- a/Assets/Editor Toolbox/Editor/ToolboxDefines.cs +++ b/Assets/Editor Toolbox/Editor/ToolboxDefines.cs @@ -3,5 +3,6 @@ internal static class ToolboxDefines { internal const string defaultListsDefine = "TOOLBOX_FORCE_DEFAULT_LISTS"; + internal const string ignoreEditorDefine = "TOOLBOX_IGNORE_CUSTOM_EDITOR"; } } \ No newline at end of file diff --git a/Assets/Editor Toolbox/Editor/ToolboxDrawerModule.cs b/Assets/Editor Toolbox/Editor/ToolboxDrawerModule.cs index bcc63674..429f9859 100644 --- a/Assets/Editor Toolbox/Editor/ToolboxDrawerModule.cs +++ b/Assets/Editor Toolbox/Editor/ToolboxDrawerModule.cs @@ -246,7 +246,10 @@ internal static void UpdateDrawers(IToolboxInspectorSettings settings) //create all type-only-related drawers PrepareTargetTypeDrawers(settings); - HandleDefaultLists(settings.ForceDefaultLists); + var useDefaultLists = settings.ForceDefaultLists; + HandleDefaultLists(useDefaultLists); + var ignoreCustomEditor = !settings.UseToolboxDrawers; + HandleIgnoreEditor(ignoreCustomEditor); //log errors into console only once validationEnabled = false; } @@ -301,6 +304,18 @@ internal static void HandleDefaultLists(bool value) } } + internal static void HandleIgnoreEditor(bool value) + { + if (value) + { + ScriptingUtility.AppendDefine(ToolboxDefines.ignoreEditorDefine); + } + else + { + ScriptingUtility.RemoveDefine(ToolboxDefines.ignoreEditorDefine); + } + } + internal static ToolboxDecoratorDrawerBase GetDecoratorDrawer(T attribute) where T : ToolboxDecoratorAttribute { return GetDecoratorDrawer(attribute.GetType()); diff --git a/Assets/Editor Toolbox/Editor/ToolboxEditor.cs b/Assets/Editor Toolbox/Editor/ToolboxEditor.cs index 96a6b6f9..3fec514a 100644 --- a/Assets/Editor Toolbox/Editor/ToolboxEditor.cs +++ b/Assets/Editor Toolbox/Editor/ToolboxEditor.cs @@ -9,7 +9,9 @@ namespace Toolbox.Editor /// /// Base Editor class for all Toolbox-related features. /// +#if !TOOLBOX_IGNORE_CUSTOM_EDITOR [CustomEditor(typeof(Object), true, isFallback = true)] +#endif [CanEditMultipleObjects] public class ToolboxEditor : Editor, IToolboxEditor { From 4148d814bd468f5bd8b0c29be95be75cb71da31b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Matkowski?= Date: Mon, 9 Sep 2024 01:10:31 +0200 Subject: [PATCH 12/21] Minor refactor changes --- .../Editor/ToolboxPropertyHandler.cs | 1 - .../Editor/Utilities/PropertyUtility.cs | 15 ++++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/Assets/Editor Toolbox/Editor/ToolboxPropertyHandler.cs b/Assets/Editor Toolbox/Editor/ToolboxPropertyHandler.cs index fd1b763e..a2d9b97d 100644 --- a/Assets/Editor Toolbox/Editor/ToolboxPropertyHandler.cs +++ b/Assets/Editor Toolbox/Editor/ToolboxPropertyHandler.cs @@ -117,7 +117,6 @@ internal ToolboxPropertyHandler(SerializedProperty property) ProcessToolboxData(); } - private void ProcessBuiltInData() { var attributes = fieldInfo.GetCustomAttributes(); diff --git a/Assets/Editor Toolbox/Editor/Utilities/PropertyUtility.cs b/Assets/Editor Toolbox/Editor/Utilities/PropertyUtility.cs index 63aed9ae..f432b958 100644 --- a/Assets/Editor Toolbox/Editor/Utilities/PropertyUtility.cs +++ b/Assets/Editor Toolbox/Editor/Utilities/PropertyUtility.cs @@ -9,8 +9,13 @@ namespace Toolbox.Editor { - public static partial class PropertyUtility + public static class PropertyUtility { + internal static class Defaults + { + internal static readonly string scriptPropertyName = "m_Script"; + } + //NOTE: last non-reflection implementation was ok but support for [SerializeReference] makes it a bit slow // unfortunately UnityEditor.ScriptAttributeUtility.GetFieldInfoFromProperty is internal so we have to retrive it using reflection private static readonly MethodInfo getGetFieldInfoFromPropertyMethod = @@ -440,14 +445,6 @@ public static void OverrideLabelByValue(GUIContent label, SerializedProperty pro } } - internal static class Defaults - { - internal static readonly string scriptPropertyName = "m_Script"; - } - } - - public static partial class PropertyUtility - { public static SerializedProperty GetSibling(this SerializedProperty property, string propertyPath) { var propertyParent = property.GetParent(); From 03993d83cb215b452fd6c3267ba36350b1972059 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Matkowski?= Date: Thu, 7 Nov 2024 12:33:52 +0100 Subject: [PATCH 13/21] Force properties to be folded if there are no children to draw --- .../Toolbox/PropertyList/ScrollableItemsAttributeDrawer.cs | 3 --- Assets/Editor Toolbox/Editor/Internal/PropertyScope.cs | 5 ++++- Assets/Examples/Scripts/SampleBehaviour6.cs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Assets/Editor Toolbox/Editor/Drawers/Toolbox/PropertyList/ScrollableItemsAttributeDrawer.cs b/Assets/Editor Toolbox/Editor/Drawers/Toolbox/PropertyList/ScrollableItemsAttributeDrawer.cs index bfc01460..921d63d8 100644 --- a/Assets/Editor Toolbox/Editor/Drawers/Toolbox/PropertyList/ScrollableItemsAttributeDrawer.cs +++ b/Assets/Editor Toolbox/Editor/Drawers/Toolbox/PropertyList/ScrollableItemsAttributeDrawer.cs @@ -17,7 +17,6 @@ static ScrollableItemsAttributeDrawer() private static readonly PropertyDataStorage storage; - private void DrawSettingsBody(SerializedProperty property, ScrollableItemsAttribute attribute, out int size, out Vector2 indexRange) { EditorGUILayout.PropertyField(property.GetSize()); @@ -53,7 +52,6 @@ private void DrawElementsBody(SerializedProperty property, ScrollableItemsAttrib } } - protected override void OnGuiSafe(SerializedProperty property, GUIContent label, ScrollableItemsAttribute attribute) { using (var propertyScope = new PropertyScope(property, label)) @@ -70,7 +68,6 @@ protected override void OnGuiSafe(SerializedProperty property, GUIContent label, } } - private static class Style { //TODO: apply custom styling for the drawer diff --git a/Assets/Editor Toolbox/Editor/Internal/PropertyScope.cs b/Assets/Editor Toolbox/Editor/Internal/PropertyScope.cs index 681d4384..fc9f9136 100644 --- a/Assets/Editor Toolbox/Editor/Internal/PropertyScope.cs +++ b/Assets/Editor Toolbox/Editor/Internal/PropertyScope.cs @@ -71,7 +71,10 @@ public void Dispose() Close(); } - public bool IsVisible => property.isExpanded; + /// + /// Indicates whether property is expanded and has any children to draw. + /// + public bool IsVisible => property.isExpanded && property.hasVisibleChildren; public Rect LabelRect { get; private set; } public Rect InputRect { get; private set; } } diff --git a/Assets/Examples/Scripts/SampleBehaviour6.cs b/Assets/Examples/Scripts/SampleBehaviour6.cs index 02cb0077..31d43fc3 100644 --- a/Assets/Examples/Scripts/SampleBehaviour6.cs +++ b/Assets/Examples/Scripts/SampleBehaviour6.cs @@ -88,7 +88,7 @@ public class ClassWithInterface4 : ClassWithInterface2 public int var33; } -#endregion + #endregion #region Generic Types From 67aa03794e90e5aeaeae3116e83d29049a6e3259 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Matkowski?= Date: Thu, 7 Nov 2024 15:54:41 +0100 Subject: [PATCH 14/21] Possibily to force Toolbar repaint externally --- .../Editor/ToolboxEditorToolbar.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Assets/Editor Toolbox/Editor/ToolboxEditorToolbar.cs b/Assets/Editor Toolbox/Editor/ToolboxEditorToolbar.cs index 2b5e471e..bf5285f7 100644 --- a/Assets/Editor Toolbox/Editor/ToolboxEditorToolbar.cs +++ b/Assets/Editor Toolbox/Editor/ToolboxEditorToolbar.cs @@ -46,6 +46,9 @@ static ToolboxEditorToolbar() private static readonly FieldInfo onGuiHandler = containterType.GetField("m_OnGUIHandler", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); + private static readonly MethodInfo repaintMethod = toolbarType.GetMethod("RepaintToolbar", + BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); + private static Object toolbar; private static IEnumerator Initialize() @@ -106,7 +109,7 @@ private static IEnumerator Initialize() private static void OnGui() { - if (!IsToolbarAllowed || OnToolbarGui == null) + if (!IsToolbarAllowed || !IsToolbarValid) { return; } @@ -142,9 +145,18 @@ private static void OnGui() #endif } + public static void Repaint() + { + if (toolbar == null) + { + return; + } + + repaintMethod?.Invoke(toolbar, null); + } public static bool IsToolbarAllowed { get; set; } = true; - + public static bool IsToolbarValid => toolbar != null && OnToolbarGui != null; public static float FromToolsOffset { get; set; } = 400.0f; public static float FromStripOffset { get; set; } = 150.0f; From 99baede3f1244e2e833cb2142b30c7430485b6bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Matkowski?= Date: Thu, 28 Nov 2024 01:31:45 +0100 Subject: [PATCH 15/21] Fix building name for some generic types; fix drawing SerializedDictionary for non-serializable value/key types --- .../TargetType/SerializedDictionaryDrawer.cs | 20 ++++++++++++------- .../Internal/Types/TypesEditorCollection.cs | 16 ++++++++------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/Assets/Editor Toolbox/Editor/Drawers/Toolbox/TargetType/SerializedDictionaryDrawer.cs b/Assets/Editor Toolbox/Editor/Drawers/Toolbox/TargetType/SerializedDictionaryDrawer.cs index 59bc4b40..2abc384a 100644 --- a/Assets/Editor Toolbox/Editor/Drawers/Toolbox/TargetType/SerializedDictionaryDrawer.cs +++ b/Assets/Editor Toolbox/Editor/Drawers/Toolbox/TargetType/SerializedDictionaryDrawer.cs @@ -52,13 +52,19 @@ static SerializedDictionaryDrawer() var content = list.GetElementContent(element, index); using (new EditorGUILayout.HorizontalScope()) { - var kOption = GUILayout.Width(Style.kGroupWidth); - DrawDictionaryProperty(kProperty, Style.kLabel, Style.kLabelWidth, kOption); - - var vLabel = vProperty.hasVisibleChildren - ? Style.vLabel - : GUIContent.none; - DrawDictionaryProperty(vProperty, vLabel, Style.vLabelWidth); + if (kProperty != null) + { + var kOption = GUILayout.Width(Style.kGroupWidth); + DrawDictionaryProperty(kProperty, Style.kLabel, Style.kLabelWidth, kOption); + } + + if (vProperty != null) + { + var vLabel = vProperty.hasVisibleChildren + ? Style.vLabel + : GUIContent.none; + DrawDictionaryProperty(vProperty, vLabel, Style.vLabelWidth); + } } }; return list; diff --git a/Assets/Editor Toolbox/Editor/Internal/Types/TypesEditorCollection.cs b/Assets/Editor Toolbox/Editor/Internal/Types/TypesEditorCollection.cs index ce9e0154..b16d014e 100644 --- a/Assets/Editor Toolbox/Editor/Internal/Types/TypesEditorCollection.cs +++ b/Assets/Editor Toolbox/Editor/Internal/Types/TypesEditorCollection.cs @@ -76,19 +76,21 @@ private static string GetTypeName(Type type, bool createFull) stringBuilder.Append(':'); } - if (type.IsGenericType) + var typeName = type.Name; + //NOTE: there are rare cases where "generic" types have no arguments, let's ignore them + if (type.IsGenericType && typeName.Contains("`")) { - var name = type.Name; - name = name.Substring(0, name.IndexOf("`")); + var genericCharIndex = typeName.IndexOf("`"); + typeName = typeName.Substring(0, genericCharIndex); - stringBuilder.Append(name); + stringBuilder.Append(typeName); stringBuilder.Append('<'); var arguments = type.GetGenericArguments(); for (var i = 0; i < arguments.Length; i++) { - var argumentType = arguments[i]; + var argumentType = arguments[i]; var argumentName = string.IsNullOrEmpty(argumentType.FullName) - ? argumentType.Name + ? argumentType.Name : GetTypeName(argumentType, false); stringBuilder.Append(argumentName); @@ -102,7 +104,7 @@ private static string GetTypeName(Type type, bool createFull) } else { - stringBuilder.Append(type.Name); + stringBuilder.Append(typeName); } return stringBuilder.ToString(); From 9dabb4089a8e52245a320a5d48efb66e47bf23fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Matkowski?= Date: Thu, 28 Nov 2024 22:27:58 +0100 Subject: [PATCH 16/21] Minor refactor changes; possibility to use EditorButtonAttribute and DynamicHelpAttribute in nested types; implement AnimationCurveSettingsAttribute & Drawer --- .../Extraction/ValueExtractionHelper.cs | 11 +-- .../Drawers/ISerializedPropertyContext.cs | 13 ++++ .../ISerializedPropertyContext.cs.meta} | 2 +- .../AnimationCurveSettingsAttributeDrawer.cs | 32 +++++++++ ...mationCurveSettingsAttributeDrawer.cs.meta | 11 +++ .../Regular/AssetPreviewAttributeDrawer.cs | 3 - .../Drawers/Regular/PropertyDrawerBase.cs | 9 +-- .../Decorator/DynamicHelpAttributeDrawer.cs | 2 +- .../Decorator/EditorButtonAttributeDrawer.cs | 17 ++--- .../Drawers/Toolbox/ToolboxAttributeDrawer.cs | 2 +- .../Drawers/Toolbox/ToolboxConditionDrawer.cs | 1 - .../Drawers/Toolbox/ToolboxDecoratorDrawer.cs | 2 - .../Toolbox/ToolboxDecoratorDrawerBase.cs | 34 ++++++++- .../Drawers/Toolbox/ToolboxPropertyDrawer.cs | 8 +-- .../Toolbox/ToolboxTargetTypeDrawer.cs | 2 - .../ToolboxDrawersManager.cs} | 12 ++-- .../Drawers/ToolboxDrawersManager.cs.meta | 11 +++ .../{ => Drawers}/ToolboxEditorDrawer.cs | 4 +- .../{ => Drawers}/ToolboxEditorDrawer.cs.meta | 0 .../{ => Drawers}/ToolboxPropertyHandler.cs | 71 +++++++++---------- .../ToolboxPropertyHandler.cs.meta | 0 .../Editors/ToolboxScriptedImporterEditor.cs | 1 + Assets/Editor Toolbox/Editor/Management.meta | 8 +++ .../{ => Management}/ToolboxAssetProcessor.cs | 2 +- .../ToolboxAssetProcessor.cs.meta | 0 .../Editor/{ => Management}/ToolboxManager.cs | 6 +- .../{ => Management}/ToolboxManager.cs.meta | 0 Assets/Editor Toolbox/Editor/ToolboxEditor.cs | 1 + .../Editor Toolbox/Editor/ToolboxEditorGui.cs | 6 +- .../Editor Toolbox/Editor/ToolboxEditorLog.cs | 4 -- .../Editor/ToolboxEditorProject.cs | 12 +--- .../Editor/ToolboxEditorSettings.cs | 10 +-- .../Editor/ToolboxEditorSettingsEditor.cs | 2 - .../Editor/ToolboxLayoutHandler.cs | 3 - Assets/Editor Toolbox/Editor/ToolboxPrefs.cs | 1 - .../Editor/Utilities/PropertyUtility.cs | 21 ++++++ .../Editor/Utilities/ReflectionUtility.cs | 4 +- Assets/Editor Toolbox/README.md | 31 ++++++++ .../AnimationCurveSettingsAttribute.cs | 42 +++++++++++ .../AnimationCurveSettingsAttribute.cs.meta | 11 +++ Assets/Examples/Scenes/SampleScene.unity | 2 + Assets/Examples/Scripts/SampleBehaviour1.cs | 7 ++ Assets/Examples/Scripts/SampleBehaviour2.cs | 9 +-- Assets/Examples/Scripts/SampleBehaviour4.cs | 29 +++++++- Assets/Examples/Scripts/SampleBehaviour6.cs | 1 - README.md | 36 ++++++++-- 46 files changed, 361 insertions(+), 135 deletions(-) create mode 100644 Assets/Editor Toolbox/Editor/Drawers/ISerializedPropertyContext.cs rename Assets/Editor Toolbox/Editor/{ToolboxDrawerModule.cs.meta => Drawers/ISerializedPropertyContext.cs.meta} (83%) create mode 100644 Assets/Editor Toolbox/Editor/Drawers/Regular/AnimationCurveSettingsAttributeDrawer.cs create mode 100644 Assets/Editor Toolbox/Editor/Drawers/Regular/AnimationCurveSettingsAttributeDrawer.cs.meta rename Assets/Editor Toolbox/Editor/{ToolboxDrawerModule.cs => Drawers/ToolboxDrawersManager.cs} (99%) create mode 100644 Assets/Editor Toolbox/Editor/Drawers/ToolboxDrawersManager.cs.meta rename Assets/Editor Toolbox/Editor/{ => Drawers}/ToolboxEditorDrawer.cs (97%) rename Assets/Editor Toolbox/Editor/{ => Drawers}/ToolboxEditorDrawer.cs.meta (100%) rename Assets/Editor Toolbox/Editor/{ => Drawers}/ToolboxPropertyHandler.cs (90%) rename Assets/Editor Toolbox/Editor/{ => Drawers}/ToolboxPropertyHandler.cs.meta (100%) create mode 100644 Assets/Editor Toolbox/Editor/Management.meta rename Assets/Editor Toolbox/Editor/{ => Management}/ToolboxAssetProcessor.cs (93%) rename Assets/Editor Toolbox/Editor/{ => Management}/ToolboxAssetProcessor.cs.meta (100%) rename Assets/Editor Toolbox/Editor/{ => Management}/ToolboxManager.cs (98%) rename Assets/Editor Toolbox/Editor/{ => Management}/ToolboxManager.cs.meta (100%) create mode 100644 Assets/Editor Toolbox/Runtime/Attributes/Property/Regular/AnimationCurveSettingsAttribute.cs create mode 100644 Assets/Editor Toolbox/Runtime/Attributes/Property/Regular/AnimationCurveSettingsAttribute.cs.meta 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; From 375cde61ee447da6796d608e4fcd1a792a79215d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Matkowski?= Date: Thu, 28 Nov 2024 22:34:12 +0100 Subject: [PATCH 17/21] Update README.md --- Assets/Editor Toolbox/README.md | 25 +++++++++++++++++++++++++ Docs/animationcurvesettings.png | Bin 0 -> 9699 bytes README.md | 25 +++++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 Docs/animationcurvesettings.png diff --git a/Assets/Editor Toolbox/README.md b/Assets/Editor Toolbox/README.md index 2dbabff7..cb48b208 100644 --- a/Assets/Editor Toolbox/README.md +++ b/Assets/Editor Toolbox/README.md @@ -145,6 +145,11 @@ public Component var2; Supported types: **all**. +```csharp +[Suffix("cm")] +public string var1; +``` + ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/suffix.png) @@ -179,6 +184,11 @@ public FlagExample enumFlag = FlagExample.Flag1 | FlagExample.Flag2 | FlagExampl Supported types: UnityEngine.**Object**. +```csharp +[NotNull] +public GameObject var1; +``` + ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/notnull1.png)\ ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/notnull2.png) @@ -187,6 +197,11 @@ Supported types: UnityEngine.**Object**. Supported types: **string**. +```csharp +[Directory] +public string var1; +``` + ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/directory1.png)\ ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/directory2.png) @@ -194,6 +209,11 @@ Supported types: **string**. Supported types: **string**. +```csharp +[SceneName] +public string var1; +``` + ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/scenename1.png)\ ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/scenename2.png) @@ -254,6 +274,11 @@ public string password; Supported types: **bool**. +```csharp +[LeftToggle] +public bool var1; +``` + ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/lefttoggle.png) #### FormattedNumberAttribute diff --git a/Docs/animationcurvesettings.png b/Docs/animationcurvesettings.png new file mode 100644 index 0000000000000000000000000000000000000000..6c5bf2f5c5fc537ca4fc4ba9e7c179049b90bc5c GI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9Rsrf literal 0 HcmV?d00001 diff --git a/README.md b/README.md index 2dbabff7..cb48b208 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,11 @@ public Component var2; Supported types: **all**. +```csharp +[Suffix("cm")] +public string var1; +``` + ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/suffix.png) @@ -179,6 +184,11 @@ public FlagExample enumFlag = FlagExample.Flag1 | FlagExample.Flag2 | FlagExampl Supported types: UnityEngine.**Object**. +```csharp +[NotNull] +public GameObject var1; +``` + ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/notnull1.png)\ ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/notnull2.png) @@ -187,6 +197,11 @@ Supported types: UnityEngine.**Object**. Supported types: **string**. +```csharp +[Directory] +public string var1; +``` + ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/directory1.png)\ ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/directory2.png) @@ -194,6 +209,11 @@ Supported types: **string**. Supported types: **string**. +```csharp +[SceneName] +public string var1; +``` + ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/scenename1.png)\ ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/scenename2.png) @@ -254,6 +274,11 @@ public string password; Supported types: **bool**. +```csharp +[LeftToggle] +public bool var1; +``` + ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/lefttoggle.png) #### FormattedNumberAttribute From d473b9818ae639e5ce9d97bd0c90dcc5a3054f53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Matkowski?= Date: Thu, 28 Nov 2024 22:43:48 +0100 Subject: [PATCH 18/21] Update README.md --- Assets/Editor Toolbox/README.md | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Assets/Editor Toolbox/README.md b/Assets/Editor Toolbox/README.md index cb48b208..ea3d5d43 100644 --- a/Assets/Editor Toolbox/README.md +++ b/Assets/Editor Toolbox/README.md @@ -211,7 +211,7 @@ Supported types: **string**. ```csharp [SceneName] -public string var1; +public string sceneName; ``` ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/scenename1.png)\ diff --git a/README.md b/README.md index cb48b208..ea3d5d43 100644 --- a/README.md +++ b/README.md @@ -211,7 +211,7 @@ Supported types: **string**. ```csharp [SceneName] -public string var1; +public string sceneName; ``` ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/scenename1.png)\ From e81100ed6258acc3cdabfc085801deab3640929f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Matkowski?= Date: Fri, 29 Nov 2024 14:01:05 +0100 Subject: [PATCH 19/21] Update samples; update README.md --- .../Editor/ToolboxEditorSettings.cs | 11 ++--- Assets/Editor Toolbox/README.md | 20 +++++++- Assets/Examples/Scenes/SampleScene.unity | 48 +++++++++++++++++++ Assets/Examples/Scripts/SampleBehaviour1.cs | 12 ++--- README.md | 20 +++++++- 5 files changed, 95 insertions(+), 16 deletions(-) diff --git a/Assets/Editor Toolbox/Editor/ToolboxEditorSettings.cs b/Assets/Editor Toolbox/Editor/ToolboxEditorSettings.cs index b53f9b13..7f623c03 100644 --- a/Assets/Editor Toolbox/Editor/ToolboxEditorSettings.cs +++ b/Assets/Editor Toolbox/Editor/ToolboxEditorSettings.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; - using UnityEngine; using UnityEngine.Serialization; @@ -62,9 +61,9 @@ internal interface IToolboxSceneViewSettings [CreateAssetMenu(fileName = "Editor Toolbox Settings", menuName = "Editor Toolbox/Settings")] internal class ToolboxEditorSettings : ScriptableObject, IToolboxGeneralSettings, IToolboxHierarchySettings, IToolboxProjectSettings, IToolboxInspectorSettings, IToolboxSceneViewSettings { - [SerializeField] + [SerializeField, Tooltip("Set to false if you don't want to use Toolbox Hierarchy and related features.")] private bool useToolboxHierarchy = true; - [SerializeField] + [SerializeField, Tooltip("Set to true if you want to display horizontal lines in the Hierarchy Window.")] private bool drawHorizontalLines = true; [SerializeField] private bool showSelectionsCount; @@ -73,7 +72,7 @@ internal class ToolboxEditorSettings : ScriptableObject, IToolboxGeneralSettings [FormerlySerializedAs("rowDataItems")] private List rowDataTypes = Defaults.rowDataTypes; - [SerializeField] + [SerializeField, Tooltip("Set to false if you don't want to use Toolbox Folders and related features.")] private bool useToolboxFolders = true; [SerializeField, Clamp(0.0f, float.MaxValue)] @@ -95,7 +94,7 @@ internal class ToolboxEditorSettings : ScriptableObject, IToolboxGeneralSettings [SerializeField] private KeyCode selectorKey = KeyCode.Tab; - [SerializeField, Tooltip("Set to false if you don't want to use Toolbox attributes and related features.")] + [SerializeField, Tooltip("Set to false if you don't want to use Toolbox Attributes and related features.")] private bool useToolboxDrawers = true; [SerializeField, Tooltip("By default, Inspectors will use the built-in version of the list instead of the Toolbox-based one. " + "Keep in mind that built-in properties don't support Toolbox attributes. \n\n Changing this property will recompile the code.")] @@ -471,7 +470,7 @@ private static class Defaults internal const float smallFolderIconXPaddingDefault = 0.15f; internal const float smallFolderIconYPaddingDefault = 0.15f; - internal readonly static List rowDataTypes = new List() + internal static readonly List rowDataTypes = new List() { HierarchyItemDataType.Icon, HierarchyItemDataType.Toggle, diff --git a/Assets/Editor Toolbox/README.md b/Assets/Editor Toolbox/README.md index ea3d5d43..c5d629df 100644 --- a/Assets/Editor Toolbox/README.md +++ b/Assets/Editor Toolbox/README.md @@ -604,13 +604,29 @@ public GameObject[] largeArray = new GameObject[19]; ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/scrollableitems.png) -##### Other ToolboxProperty attributes +##### IgnoreParentAttribute + +**IgnoreParent** allows you to hide the parent's label, foldout arrow and remove the standard indentation for nested fields. ```csharp [IgnoreParent] public Quaternion q; ``` +![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/ignoreparent.png) + +##### DynamicRangeAttribute + +```csharp +[DynamicRange(nameof(minValue), nameof(MaxValue))] +public float var1; + +public float minValue; +public float MaxValue => 15.0f; +``` + +##### DynamicMinMaxSliderAttribute + ```csharp [DynamicMinMaxSlider(nameof(minValue), nameof(MaxValue))] public Vector2 vec2; @@ -952,7 +968,7 @@ public void Usage() #### SerializedDirectory -Allows to serialize folders in form of assets and retrieve direct paths in runtime. +Allows to serialize folders in form of assets and retrieve direct paths in Runtime. ```csharp public SerializedDirectory serializeDirectory; diff --git a/Assets/Examples/Scenes/SampleScene.unity b/Assets/Examples/Scenes/SampleScene.unity index 98718f9c..afd0d538 100644 --- a/Assets/Examples/Scenes/SampleScene.unity +++ b/Assets/Examples/Scenes/SampleScene.unity @@ -1301,6 +1301,54 @@ MonoBehaviour: bigNumber: 12345678 currency: 20.41 layer: 5 + animationCurve1: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 34 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + - serializedVersion: 3 + time: 1 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 34 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + animationCurve2: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: -1 + value: -1 + inSlope: 2 + outSlope: 2 + tangentMode: 0 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + - serializedVersion: 3 + time: 2 + value: 2 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 clampedValue: 6 notNullReference: {fileID: 0} childReference: {fileID: 0} diff --git a/Assets/Examples/Scripts/SampleBehaviour1.cs b/Assets/Examples/Scripts/SampleBehaviour1.cs index 281e0537..2f657de1 100644 --- a/Assets/Examples/Scripts/SampleBehaviour1.cs +++ b/Assets/Examples/Scripts/SampleBehaviour1.cs @@ -101,12 +101,6 @@ public enum FlagExample [Layer] public int layer; - [BeginGroup(Order = -2)] - - [Help("NotNullAttribute, ClampAttribute, SceneObjectOnlyAttribute, ChildObjectOnlyAttribute, PrefabObjectOnlyAttribute " + - "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] @@ -114,6 +108,12 @@ public enum FlagExample [AnimationCurveSettings(-1.0f, -1.0f, 2.0f, 2.0f, HexColor = "#360E45")] public AnimationCurve animationCurve2; + [BeginGroup(Order = -2)] + + [Help("NotNullAttribute, ClampAttribute, SceneObjectOnlyAttribute, ChildObjectOnlyAttribute, PrefabObjectOnlyAttribute " + + "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("Validation", skinStyle: SkinStyle.Box)] [Clamp(0.0f, 11.2f)] diff --git a/README.md b/README.md index ea3d5d43..c5d629df 100644 --- a/README.md +++ b/README.md @@ -604,13 +604,29 @@ public GameObject[] largeArray = new GameObject[19]; ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/scrollableitems.png) -##### Other ToolboxProperty attributes +##### IgnoreParentAttribute + +**IgnoreParent** allows you to hide the parent's label, foldout arrow and remove the standard indentation for nested fields. ```csharp [IgnoreParent] public Quaternion q; ``` +![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/ignoreparent.png) + +##### DynamicRangeAttribute + +```csharp +[DynamicRange(nameof(minValue), nameof(MaxValue))] +public float var1; + +public float minValue; +public float MaxValue => 15.0f; +``` + +##### DynamicMinMaxSliderAttribute + ```csharp [DynamicMinMaxSlider(nameof(minValue), nameof(MaxValue))] public Vector2 vec2; @@ -952,7 +968,7 @@ public void Usage() #### SerializedDirectory -Allows to serialize folders in form of assets and retrieve direct paths in runtime. +Allows to serialize folders in form of assets and retrieve direct paths in Runtime. ```csharp public SerializedDirectory serializeDirectory; From 31f75823fe6820d53ef0fcc6d7711c9c54fb90a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Matkowski?= Date: Fri, 29 Nov 2024 14:14:18 +0100 Subject: [PATCH 20/21] Update: package.json, CHANGELOG.md --- Assets/Editor Toolbox/CHANGELOG.md | 11 +++++++++++ Assets/Editor Toolbox/package.json | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Assets/Editor Toolbox/CHANGELOG.md b/Assets/Editor Toolbox/CHANGELOG.md index 8b1b728b..035bcd06 100644 --- a/Assets/Editor Toolbox/CHANGELOG.md +++ b/Assets/Editor Toolbox/CHANGELOG.md @@ -1,3 +1,14 @@ +## 0.13.2 [29.11.2024] + +### Added: +- AnimationCurveSettingsAttribute + +### Changed: +- Possibility to use [EditorButton] and [DynamicHelp] in nested types +- For now SerializeReference properties without children will always be folded +- Fix exception while building labels for generic types without arguments +- Fix drawing SerializedDictionary if value or key types cannot be serialized + ## 0.13.1 [30.08.2024] ### Changed: diff --git a/Assets/Editor Toolbox/package.json b/Assets/Editor Toolbox/package.json index a098956a..4c6cdc76 100644 --- a/Assets/Editor Toolbox/package.json +++ b/Assets/Editor Toolbox/package.json @@ -1,7 +1,7 @@ { "name": "com.browar.editor-toolbox", "displayName": "Editor Toolbox", - "version": "0.13.1", + "version": "0.13.2", "unity": "2018.1", "description": "Tools, custom attributes, drawers, hierarchy overlay, and other extensions for the Unity Editor.", "keywords": [ From b45cb0f4698e9e43bbf142098adff7b1445d0235 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Matkowski?= Date: Fri, 29 Nov 2024 16:46:04 +0100 Subject: [PATCH 21/21] Minor refactor changes --- Assets/Editor Toolbox/Editor/ToolboxEditorProject.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/Editor Toolbox/Editor/ToolboxEditorProject.cs b/Assets/Editor Toolbox/Editor/ToolboxEditorProject.cs index bcd4af6d..a4a9d5b8 100644 --- a/Assets/Editor Toolbox/Editor/ToolboxEditorProject.cs +++ b/Assets/Editor Toolbox/Editor/ToolboxEditorProject.cs @@ -20,7 +20,7 @@ static ToolboxEditorProject() } private static readonly Dictionary pathBasedFoldersData = new Dictionary(); - private readonly static Dictionary nameBasedFoldersData = new(); + private readonly static Dictionary nameBasedFoldersData = new Dictionary(); /// /// Draws icons and additional tooltips for matched assets.