From 6c387faf7f77fba172fce98b800217234a21c841 Mon Sep 17 00:00:00 2001 From: uurhaa Date: Sat, 2 Mar 2024 03:03:36 +0100 Subject: [PATCH] Clean Up --- .../Editor/BetterEditorTools.Editor.asmdef | 3 +- .../Comparers/SerializedPropertyComparer.cs | 1 + .../Editor/EditorTools/ComponentExtension.cs | 20 - .../EditorTools/ComponentExtension.cs.meta | 11 - .../EditorTools/CustomEditors/MultiEditor.cs | 4 +- .../EditorTools/Drawers/Base/FieldDrawer.cs | 73 +-- .../Drawers/Base/HeightCacheValue.cs | 82 ++++ .../Drawers/Base/HeightCacheValue.cs.meta | 3 + .../Drawers/Base/MultiFieldDrawer.cs | 32 +- .../Drawers/Base/WrapperCollection.cs | 4 +- .../Drawers/Base/WrappersTypeCollection.cs | 2 +- .../Drawers/MultiPropertyDrawer.cs | 2 +- .../Caching/{Cache.cs => CacheValue.cs} | 6 +- .../{Cache.cs.meta => CacheValue.cs.meta} | 0 .../ValidateCachedPropertiesUtility.cs | 76 +++ ...> ValidateCachedPropertiesUtility.cs.meta} | 0 .../Helpers/Caching/ValidateExtensions.cs | 35 -- .../EditorTools/Helpers/DrawersHelper.cs | 98 ++-- .../Helpers/DropDown/DropdownBase.cs | 2 +- .../Helpers/DropDown/DropdownCollection.cs | 17 +- .../Helpers/DropDown/DropdownGUI.cs | 29 +- .../Helpers/DropDown/DropdownSubTree.cs | 2 +- .../Helpers/DropDown/DropdownWindow.cs | 2 +- .../EditorTools/Helpers/EditorGUIHelpers.cs | 13 +- .../Editor/EditorTools/Helpers/EditorPopup.cs | 1 - .../Editor/EditorTools/Helpers/IconType.cs | 37 ++ .../EditorTools/Helpers/IconType.cs.meta | 3 + .../Helpers/ReorderableListHelpers.cs | 17 +- .../EditorTools/SerializedPropertyDefines.cs | 16 - .../SerializedPropertyDefines.cs.meta | 3 - .../SerializedPropertyExtensions.cs | 431 ------------------ .../SerializedPropertyExtensions.cs.meta | 3 - .../EditorTools/SerializedPropertyUtil.cs | 206 --------- .../SerializedPropertyUtil.cs.meta | 3 - .../EditorTools/Utilities/BaseUtility.cs | 40 +- .../EditorTools/Utilities/UtilityWrapper.cs | 7 + .../Utilities/UtilityWrapper.cs.meta | 3 + .../Editor/SettingsTools.meta | 3 - .../SettingsTools/ProjectSettingsProvider.cs | 47 -- .../ProjectSettingsProvider.cs.meta | 3 - .../ProjectSettingsRegisterer.cs | 46 -- .../ProjectSettingsRegisterer.cs.meta | 3 - .../SettingsTools/ProjectSettingsTools.cs | 59 --- .../ProjectSettingsTools.cs.meta | 3 - .../ProjectSettingsToolsContainer.cs | 20 - .../ProjectSettingsToolsContainer.cs.meta | 3 - .../BetterEditorTools/Runtime/Settings.meta | 3 - .../Runtime/Settings/ProjectSettings.cs | 9 - .../Runtime/Settings/ProjectSettings.cs.meta | 3 - Assets/BetterEditorTools/package.json | 8 +- Packages/manifest.json | 12 +- Packages/packages-lock.json | 50 +- ProjectSettings/ProjectVersion.txt | 4 +- 53 files changed, 412 insertions(+), 1151 deletions(-) delete mode 100644 Assets/BetterEditorTools/Editor/EditorTools/ComponentExtension.cs delete mode 100644 Assets/BetterEditorTools/Editor/EditorTools/ComponentExtension.cs.meta create mode 100644 Assets/BetterEditorTools/Editor/EditorTools/Drawers/Base/HeightCacheValue.cs create mode 100644 Assets/BetterEditorTools/Editor/EditorTools/Drawers/Base/HeightCacheValue.cs.meta rename Assets/BetterEditorTools/Editor/EditorTools/Helpers/Caching/{Cache.cs => CacheValue.cs} (79%) rename Assets/BetterEditorTools/Editor/EditorTools/Helpers/Caching/{Cache.cs.meta => CacheValue.cs.meta} (100%) create mode 100644 Assets/BetterEditorTools/Editor/EditorTools/Helpers/Caching/ValidateCachedPropertiesUtility.cs rename Assets/BetterEditorTools/Editor/EditorTools/Helpers/Caching/{ValidateExtensions.cs.meta => ValidateCachedPropertiesUtility.cs.meta} (100%) delete mode 100644 Assets/BetterEditorTools/Editor/EditorTools/Helpers/Caching/ValidateExtensions.cs create mode 100644 Assets/BetterEditorTools/Editor/EditorTools/Helpers/IconType.cs create mode 100644 Assets/BetterEditorTools/Editor/EditorTools/Helpers/IconType.cs.meta delete mode 100644 Assets/BetterEditorTools/Editor/EditorTools/SerializedPropertyDefines.cs delete mode 100644 Assets/BetterEditorTools/Editor/EditorTools/SerializedPropertyDefines.cs.meta delete mode 100644 Assets/BetterEditorTools/Editor/EditorTools/SerializedPropertyExtensions.cs delete mode 100644 Assets/BetterEditorTools/Editor/EditorTools/SerializedPropertyExtensions.cs.meta delete mode 100644 Assets/BetterEditorTools/Editor/EditorTools/SerializedPropertyUtil.cs delete mode 100644 Assets/BetterEditorTools/Editor/EditorTools/SerializedPropertyUtil.cs.meta create mode 100644 Assets/BetterEditorTools/Editor/EditorTools/Utilities/UtilityWrapper.cs create mode 100644 Assets/BetterEditorTools/Editor/EditorTools/Utilities/UtilityWrapper.cs.meta delete mode 100644 Assets/BetterEditorTools/Editor/SettingsTools.meta delete mode 100644 Assets/BetterEditorTools/Editor/SettingsTools/ProjectSettingsProvider.cs delete mode 100644 Assets/BetterEditorTools/Editor/SettingsTools/ProjectSettingsProvider.cs.meta delete mode 100644 Assets/BetterEditorTools/Editor/SettingsTools/ProjectSettingsRegisterer.cs delete mode 100644 Assets/BetterEditorTools/Editor/SettingsTools/ProjectSettingsRegisterer.cs.meta delete mode 100644 Assets/BetterEditorTools/Editor/SettingsTools/ProjectSettingsTools.cs delete mode 100644 Assets/BetterEditorTools/Editor/SettingsTools/ProjectSettingsTools.cs.meta delete mode 100644 Assets/BetterEditorTools/Editor/SettingsTools/ProjectSettingsToolsContainer.cs delete mode 100644 Assets/BetterEditorTools/Editor/SettingsTools/ProjectSettingsToolsContainer.cs.meta delete mode 100644 Assets/BetterEditorTools/Runtime/Settings.meta delete mode 100644 Assets/BetterEditorTools/Runtime/Settings/ProjectSettings.cs delete mode 100644 Assets/BetterEditorTools/Runtime/Settings/ProjectSettings.cs.meta diff --git a/Assets/BetterEditorTools/Editor/BetterEditorTools.Editor.asmdef b/Assets/BetterEditorTools/Editor/BetterEditorTools.Editor.asmdef index 2a0dd1a..ff2606e 100644 --- a/Assets/BetterEditorTools/Editor/BetterEditorTools.Editor.asmdef +++ b/Assets/BetterEditorTools/Editor/BetterEditorTools.Editor.asmdef @@ -5,7 +5,8 @@ "GUID:443314a5a4e67c14a88ae223776b6554", "GUID:28da8d3b12e3efa47928e0c9070f853d", "GUID:a59e3daedde9ca94bba45364d4ead25f", - "GUID:01df13aca8d01e24a911bcc3e8277031" + "GUID:01df13aca8d01e24a911bcc3e8277031", + "GUID:1ac867a6259e45a1856740fe8f7623aa" ], "includePlatforms": [ "Editor" diff --git a/Assets/BetterEditorTools/Editor/EditorTools/Comparers/SerializedPropertyComparer.cs b/Assets/BetterEditorTools/Editor/EditorTools/Comparers/SerializedPropertyComparer.cs index 2a01a76..c9771b6 100644 --- a/Assets/BetterEditorTools/Editor/EditorTools/Comparers/SerializedPropertyComparer.cs +++ b/Assets/BetterEditorTools/Editor/EditorTools/Comparers/SerializedPropertyComparer.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Better.Extensions.EditorAddons; using UnityEditor; namespace Better.EditorTools.Comparers diff --git a/Assets/BetterEditorTools/Editor/EditorTools/ComponentExtension.cs b/Assets/BetterEditorTools/Editor/EditorTools/ComponentExtension.cs deleted file mode 100644 index 4dfce6e..0000000 --- a/Assets/BetterEditorTools/Editor/EditorTools/ComponentExtension.cs +++ /dev/null @@ -1,20 +0,0 @@ -using UnityEditor; -using UnityEngine; - -namespace Better.EditorTools -{ - public static class ComponentExtension - { - public static bool IsTargetComponent(this SerializedProperty property, out Component component) - { - component = null; - if (property.serializedObject.targetObject is Component inner) - { - component = inner; - return true; - } - - return false; - } - } -} \ No newline at end of file diff --git a/Assets/BetterEditorTools/Editor/EditorTools/ComponentExtension.cs.meta b/Assets/BetterEditorTools/Editor/EditorTools/ComponentExtension.cs.meta deleted file mode 100644 index 38af2fe..0000000 --- a/Assets/BetterEditorTools/Editor/EditorTools/ComponentExtension.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: b77ccfdf502c2fe48bcced8925666ee8 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/BetterEditorTools/Editor/EditorTools/CustomEditors/MultiEditor.cs b/Assets/BetterEditorTools/Editor/EditorTools/CustomEditors/MultiEditor.cs index 1fb0e77..443760c 100644 --- a/Assets/BetterEditorTools/Editor/EditorTools/CustomEditors/MultiEditor.cs +++ b/Assets/BetterEditorTools/Editor/EditorTools/CustomEditors/MultiEditor.cs @@ -2,9 +2,9 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; +using Better.Extensions.EditorAddons; using Better.Extensions.Runtime; using UnityEditor; -using UnityEngine; using Object = UnityEngine.Object; namespace Better.EditorTools.CustomEditors @@ -56,7 +56,7 @@ bool WherePredicate((Type type, MultiEditorAttribute attribute) x) return att.EditorFor == targetType; } - return typeof(EditorExtension).GetAllInheritedType().Select(type => (type, type.GetCustomAttribute())) + return typeof(EditorExtension).GetAllInheritedTypesWithoutUnityObject().Select(type => (type, type.GetCustomAttribute())) .Where(WherePredicate).OrderBy(x => x.Item2.Order).ToArray(); } diff --git a/Assets/BetterEditorTools/Editor/EditorTools/Drawers/Base/FieldDrawer.cs b/Assets/BetterEditorTools/Editor/EditorTools/Drawers/Base/FieldDrawer.cs index 2701d5c..c3dcb01 100644 --- a/Assets/BetterEditorTools/Editor/EditorTools/Drawers/Base/FieldDrawer.cs +++ b/Assets/BetterEditorTools/Editor/EditorTools/Drawers/Base/FieldDrawer.cs @@ -1,75 +1,10 @@ using System.Reflection; -using Better.EditorTools.Helpers.Caching; using Better.Tools.Runtime.Attributes; using UnityEditor; using UnityEngine; namespace Better.EditorTools.Drawers.Base { - public class HeightCache : Cache - { - public bool Forced { get; private set; } - - public HeightCache(bool additional, float height) - { - IsValid = additional; - Value = height; - } - - public HeightCache() - { - - } - - public HeightCache Force() - { - Forced = true; - return this; - } - - public static HeightCache GetAdditive(float height) - { - var cache = new HeightCache(true, height); - return cache; - } - - public static HeightCache GetFull(float height) - { - var cache = new HeightCache(false, height); - return cache; - } - - public static HeightCache operator +(HeightCache left, HeightCache right) - { - if (left.Forced) - { - return left; - } - - if (right.Forced) - { - return right; - } - - if (!left.IsValid && !right.IsValid) - { - return GetFull(Mathf.Max(left.Value, right.Value)); - } - - if ((!left.IsValid && right.IsValid) || (left.IsValid && !right.IsValid)) - { - return GetFull(left.Value + right.Value); - } - - if (left.IsValid && right.IsValid) - { - return GetAdditive(left.Value + right.Value); - } - - return GetAdditive(0); - } - } - public abstract class FieldDrawer { protected readonly FieldInfo _fieldInfo; @@ -141,7 +76,7 @@ internal void PostDrawInternal(Rect position, SerializedProperty property, GUICo PostDraw(position, property, label); } - internal HeightCache GetPropertyHeightInternal(SerializedProperty property, GUIContent label) + internal HeightCacheValue GetPropertyHeightInternal(SerializedProperty property, GUIContent label) { var propertyHeight = GetPropertyHeight(property, label); if (_nextDrawer != null) @@ -152,14 +87,14 @@ internal HeightCache GetPropertyHeightInternal(SerializedProperty property, GUIC return propertyHeight; } - + protected abstract bool PreDraw(ref Rect position, SerializedProperty property, GUIContent label); protected abstract Rect PreparePropertyRect(Rect original); protected abstract void PostDraw(Rect position, SerializedProperty property, GUIContent label); - protected virtual HeightCache GetPropertyHeight(SerializedProperty property, GUIContent label) + protected virtual HeightCacheValue GetPropertyHeight(SerializedProperty property, GUIContent label) { - return HeightCache.GetFull(EditorGUI.GetPropertyHeight(property, label, true)); + return HeightCacheValue.GetFull(EditorGUI.GetPropertyHeight(property, label, true)); } } } \ No newline at end of file diff --git a/Assets/BetterEditorTools/Editor/EditorTools/Drawers/Base/HeightCacheValue.cs b/Assets/BetterEditorTools/Editor/EditorTools/Drawers/Base/HeightCacheValue.cs new file mode 100644 index 0000000..96deac7 --- /dev/null +++ b/Assets/BetterEditorTools/Editor/EditorTools/Drawers/Base/HeightCacheValue.cs @@ -0,0 +1,82 @@ +using System; +using Better.EditorTools.Helpers.Caching; +using Better.Extensions.Runtime; +using UnityEngine; + +namespace Better.EditorTools.Drawers.Base +{ + public class HeightCacheValue : CacheValue + { + public bool Forced { get; private set; } + + public HeightCacheValue(bool additional, float height) + { + IsValid = additional; + Value = height; + } + + public HeightCacheValue() + { + } + + public HeightCacheValue Force() + { + Forced = true; + return this; + } + + public static HeightCacheValue GetAdditive(float height) + { + var cache = new HeightCacheValue(true, height); + return cache; + } + + public static HeightCacheValue GetFull(float height) + { + var cache = new HeightCacheValue(false, height); + return cache; + } + + public static HeightCacheValue operator +(HeightCacheValue left, HeightCacheValue right) + { + if (left == null) + { + DebugUtility.LogException(nameof(left)); + return new HeightCacheValue(false, 0); + } + + if (right == null) + { + DebugUtility.LogException(nameof(right)); + return new HeightCacheValue(false, 0); + } + + if (left.Forced) + { + return left; + } + + if (right.Forced) + { + return right; + } + + if (!left.IsValid && !right.IsValid) + { + return GetFull(Mathf.Max(left.Value, right.Value)); + } + + if ((!left.IsValid && right.IsValid) || (left.IsValid && !right.IsValid)) + { + return GetFull(left.Value + right.Value); + } + + if (left.IsValid && right.IsValid) + { + return GetAdditive(left.Value + right.Value); + } + + return GetAdditive(0); + } + } +} \ No newline at end of file diff --git a/Assets/BetterEditorTools/Editor/EditorTools/Drawers/Base/HeightCacheValue.cs.meta b/Assets/BetterEditorTools/Editor/EditorTools/Drawers/Base/HeightCacheValue.cs.meta new file mode 100644 index 0000000..b39e051 --- /dev/null +++ b/Assets/BetterEditorTools/Editor/EditorTools/Drawers/Base/HeightCacheValue.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: afd070b2fb8f418eb27480d6621edaeb +timeCreated: 1709343126 \ No newline at end of file diff --git a/Assets/BetterEditorTools/Editor/EditorTools/Drawers/Base/MultiFieldDrawer.cs b/Assets/BetterEditorTools/Editor/EditorTools/Drawers/Base/MultiFieldDrawer.cs index ff6ccc0..c0c856e 100644 --- a/Assets/BetterEditorTools/Editor/EditorTools/Drawers/Base/MultiFieldDrawer.cs +++ b/Assets/BetterEditorTools/Editor/EditorTools/Drawers/Base/MultiFieldDrawer.cs @@ -11,10 +11,18 @@ namespace Better.EditorTools.Drawers.Base { public abstract class MultiFieldDrawer : FieldDrawer where T : UtilityWrapper { - private static readonly Cache CacheField = new Cache(); + private static readonly CacheValue CacheValueField = new CacheValue(); protected WrapperCollection _wrappers; + protected class CacheValue : CacheValue> + { + } + + protected MultiFieldDrawer(FieldInfo fieldInfo, MultiPropertyAttribute attribute) : base(fieldInfo, attribute) + { + } + /// /// Method generates explicit typed collection inherited from /// @@ -34,9 +42,13 @@ protected override void Deconstruct() protected virtual Type GetFieldOrElementType() { - return _fieldInfo.GetFieldOrElementType(); + var fieldType = _fieldInfo.FieldType; + if (fieldType.IsArrayOrList()) + return fieldType.GetCollectionElementType(); + + return fieldType; } - + /// /// Validates if contains property by /// @@ -44,19 +56,11 @@ protected virtual Type GetFieldOrElementType() /// used to validate current stored wrappers and gets instance for recently added property /// /// Returns true if wrapper for was already stored into - protected Cache ValidateCachedProperties(SerializedProperty property, BaseUtility handler) + protected CacheValue ValidateCachedProperties(SerializedProperty property, BaseUtility handler) where THandler : new() { - _wrappers.ValidateCachedProperties(CacheField, property, GetFieldOrElementType(), _attribute.GetType(), handler); - return CacheField; - } - - protected class Cache : Cache> - { - } - - protected MultiFieldDrawer(FieldInfo fieldInfo, MultiPropertyAttribute attribute) : base(fieldInfo, attribute) - { + ValidateCachedPropertiesUtility.Validate(_wrappers, CacheValueField, property, GetFieldOrElementType(), _attribute.GetType(), handler); + return CacheValueField; } } } \ No newline at end of file diff --git a/Assets/BetterEditorTools/Editor/EditorTools/Drawers/Base/WrapperCollection.cs b/Assets/BetterEditorTools/Editor/EditorTools/Drawers/Base/WrapperCollection.cs index d485f6c..3a4d878 100644 --- a/Assets/BetterEditorTools/Editor/EditorTools/Drawers/Base/WrapperCollection.cs +++ b/Assets/BetterEditorTools/Editor/EditorTools/Drawers/Base/WrapperCollection.cs @@ -17,9 +17,9 @@ public WrapperCollection() : base(SerializedPropertyComparer.Instance) /// public void Deconstruct() { - foreach (var gizmo in Values) + foreach (var value in Values) { - gizmo.Wrapper.Deconstruct(); + value.Wrapper.Deconstruct(); } } } diff --git a/Assets/BetterEditorTools/Editor/EditorTools/Drawers/Base/WrappersTypeCollection.cs b/Assets/BetterEditorTools/Editor/EditorTools/Drawers/Base/WrappersTypeCollection.cs index 9232fbd..c8f7863 100644 --- a/Assets/BetterEditorTools/Editor/EditorTools/Drawers/Base/WrappersTypeCollection.cs +++ b/Assets/BetterEditorTools/Editor/EditorTools/Drawers/Base/WrappersTypeCollection.cs @@ -7,7 +7,7 @@ public class WrappersTypeCollection : BaseWrappersTypeCollection { protected Dictionary> _dictionary; - public WrappersTypeCollection() : base() + public WrappersTypeCollection() { _dictionary = new Dictionary>(); } diff --git a/Assets/BetterEditorTools/Editor/EditorTools/Drawers/MultiPropertyDrawer.cs b/Assets/BetterEditorTools/Editor/EditorTools/Drawers/MultiPropertyDrawer.cs index 73b0e8a..26aabb5 100644 --- a/Assets/BetterEditorTools/Editor/EditorTools/Drawers/MultiPropertyDrawer.cs +++ b/Assets/BetterEditorTools/Editor/EditorTools/Drawers/MultiPropertyDrawer.cs @@ -27,7 +27,7 @@ public sealed class MultiPropertyDrawer : PropertyDrawer [DidReloadScripts] private static void OnInitialize() { - var types = typeof(FieldDrawer).GetAllInheritedType(); + var types = typeof(FieldDrawer).GetAllInheritedTypesWithoutUnityObject(); foreach (var type in types) { var atts = type.GetCustomAttributes(); diff --git a/Assets/BetterEditorTools/Editor/EditorTools/Helpers/Caching/Cache.cs b/Assets/BetterEditorTools/Editor/EditorTools/Helpers/Caching/CacheValue.cs similarity index 79% rename from Assets/BetterEditorTools/Editor/EditorTools/Helpers/Caching/Cache.cs rename to Assets/BetterEditorTools/Editor/EditorTools/Helpers/Caching/CacheValue.cs index d961444..51cc6c0 100644 --- a/Assets/BetterEditorTools/Editor/EditorTools/Helpers/Caching/Cache.cs +++ b/Assets/BetterEditorTools/Editor/EditorTools/Helpers/Caching/CacheValue.cs @@ -1,6 +1,6 @@ namespace Better.EditorTools.Helpers.Caching { - public class Cache + public class CacheValue { public bool IsValid { get; protected set; } public T Value { get; protected set; } @@ -11,9 +11,9 @@ public void Set(bool isValid, T value) Value = value; } - public Cache Copy() + public CacheValue Copy() { - return new Cache() + return new CacheValue() { IsValid = IsValid, Value = Value diff --git a/Assets/BetterEditorTools/Editor/EditorTools/Helpers/Caching/Cache.cs.meta b/Assets/BetterEditorTools/Editor/EditorTools/Helpers/Caching/CacheValue.cs.meta similarity index 100% rename from Assets/BetterEditorTools/Editor/EditorTools/Helpers/Caching/Cache.cs.meta rename to Assets/BetterEditorTools/Editor/EditorTools/Helpers/Caching/CacheValue.cs.meta diff --git a/Assets/BetterEditorTools/Editor/EditorTools/Helpers/Caching/ValidateCachedPropertiesUtility.cs b/Assets/BetterEditorTools/Editor/EditorTools/Helpers/Caching/ValidateCachedPropertiesUtility.cs new file mode 100644 index 0000000..aed51aa --- /dev/null +++ b/Assets/BetterEditorTools/Editor/EditorTools/Helpers/Caching/ValidateCachedPropertiesUtility.cs @@ -0,0 +1,76 @@ +using System; +using Better.EditorTools.Drawers.Base; +using Better.EditorTools.Utilities; +using Better.Extensions.Runtime; +using UnityEditor; + +namespace Better.EditorTools.Helpers.Caching +{ + public static class ValidateCachedPropertiesUtility + { + public static void Validate(WrapperCollection wrappers, TCache cache, SerializedProperty property, Type fieldType, + Type attributeType, BaseUtility handler) where TCache : CacheValue> + where TWrapper : UtilityWrapper + where THandler : new() + { + if (cache == null) + { + DebugUtility.LogException(nameof(cache)); + return; + } + + if (wrappers == null) + { + DebugUtility.LogException(nameof(wrappers)); + cache.Set(false, null); + return; + } + + if (property == null) + { + DebugUtility.LogException(nameof(property)); + cache.Set(false, null); + return; + } + + if (fieldType == null) + { + DebugUtility.LogException(nameof(fieldType)); + cache.Set(false, null); + return; + } + + if (attributeType == null) + { + DebugUtility.LogException(nameof(attributeType)); + cache.Set(false, null); + return; + } + + if (handler == null) + { + DebugUtility.LogException(nameof(handler)); + cache.Set(false, null); + return; + } + + if (wrappers.TryGetValue(property, out var wrapperCollectionValue)) + { + handler.ValidateCachedProperties(wrappers); + cache.Set(true, wrapperCollectionValue); + return; + } + + var wrapper = handler.GetUtilityWrapper(fieldType, attributeType); + if (wrapper == null) + { + cache.Set(false, null); + return; + } + + var collectionValue = new WrapperCollectionValue(wrapper, fieldType); + wrappers.Add(property, collectionValue); + cache.Set(false, collectionValue); + } + } +} \ No newline at end of file diff --git a/Assets/BetterEditorTools/Editor/EditorTools/Helpers/Caching/ValidateExtensions.cs.meta b/Assets/BetterEditorTools/Editor/EditorTools/Helpers/Caching/ValidateCachedPropertiesUtility.cs.meta similarity index 100% rename from Assets/BetterEditorTools/Editor/EditorTools/Helpers/Caching/ValidateExtensions.cs.meta rename to Assets/BetterEditorTools/Editor/EditorTools/Helpers/Caching/ValidateCachedPropertiesUtility.cs.meta diff --git a/Assets/BetterEditorTools/Editor/EditorTools/Helpers/Caching/ValidateExtensions.cs b/Assets/BetterEditorTools/Editor/EditorTools/Helpers/Caching/ValidateExtensions.cs deleted file mode 100644 index 99bfb7a..0000000 --- a/Assets/BetterEditorTools/Editor/EditorTools/Helpers/Caching/ValidateExtensions.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using Better.EditorTools.Drawers.Base; -using Better.EditorTools.Utilities; -using UnityEditor; - -namespace Better.EditorTools.Helpers.Caching -{ - public static class ValidateCachedPropertiesExtensions - { - public static void ValidateCachedProperties(this - WrapperCollection wrappers, TCache cache, SerializedProperty property, Type fieldType, - Type attributeType, BaseUtility handler) where TCache : Cache> - where TWrapper : UtilityWrapper - where THandler : new() - { - if (wrappers.TryGetValue(property, out var wrapperCollectionValue)) - { - handler.ValidateCachedProperties(wrappers); - cache.Set(true, wrapperCollectionValue); - return; - } - - var wrapper = handler.GetUtilityWrapper(fieldType, attributeType); - if (wrapper == null) - { - cache.Set(false, null); - return; - } - - var collectionValue = new WrapperCollectionValue(wrapper, fieldType); - wrappers.Add(property, collectionValue); - cache.Set(false, collectionValue); - } - } -} \ No newline at end of file diff --git a/Assets/BetterEditorTools/Editor/EditorTools/Helpers/DrawersHelper.cs b/Assets/BetterEditorTools/Editor/EditorTools/Helpers/DrawersHelper.cs index 2c75b6f..8e4e0c4 100644 --- a/Assets/BetterEditorTools/Editor/EditorTools/Helpers/DrawersHelper.cs +++ b/Assets/BetterEditorTools/Editor/EditorTools/Helpers/DrawersHelper.cs @@ -1,4 +1,5 @@ using System; +using Better.Extensions.Runtime; using UnityEditor; using UnityEngine; @@ -53,11 +54,47 @@ public static string NotSupportedMessage(string fieldName, Type fieldType, Type /// public static void NotSupportedAttribute(Rect position, SerializedProperty property, GUIContent label, Type fieldType, Type attributeType) { + if (property == null) + { + DebugUtility.LogException(nameof(property)); + return; + } + + if (label == null) + { + DebugUtility.LogException(nameof(label)); + return; + } + + if (fieldType == null) + { + DebugUtility.LogException(nameof(fieldType)); + return; + } + + if (attributeType == null) + { + DebugUtility.LogException(nameof(attributeType)); + return; + } + HelpBoxFromRect(position, property, label, NotSupportedMessage(property.name, fieldType, attributeType), IconType.ErrorMessage); } public static void HelpBoxFromRect(Rect position, SerializedProperty property, GUIContent label, string message, IconType messageType) { + if (property == null) + { + DebugUtility.LogException(nameof(property)); + return; + } + + if (label == null) + { + DebugUtility.LogException(nameof(label)); + return; + } + var buffer = new Rect(position); var lab = new GUIContent(label); @@ -100,6 +137,12 @@ public static string BeautifyFormat(string text) /// private static void HelpBox(string message, IconType type, GUIStyle style, bool useSpace) { + if (style == null) + { + DebugUtility.LogException(nameof(style)); + return; + } + var icon = GetIconName(type); if (useSpace) { @@ -135,7 +178,7 @@ private static void HelpBox(Rect position, GUIContent message, GUIStyle style) { EditorGUI.LabelField(position, GUIContent.none, message, style); } - + /// /// Override for default Inspector HelpBox with style /// @@ -143,6 +186,12 @@ private static void HelpBox(Rect position, GUIContent message, GUIStyle style) /// public static void HelpBox(Rect position, GUIContent message) { + if (message == null) + { + DebugUtility.LogException(nameof(message)); + return; + } + HelpBox(position, message, CreateOrReturnHelpBoxStyle()); } @@ -162,6 +211,12 @@ public static float GetHelpBoxHeight(string message, IconType type) public static float GetHelpBoxHeight(GUIContent message) { + if (message == null) + { + DebugUtility.LogException(nameof(message)); + return 0; + } + return CreateOrReturnHelpBoxStyle().CalcHeight(message, EditorGUIUtility.currentViewWidth); } @@ -279,6 +334,12 @@ public static bool IsMouseButton(EventType eventType, int mouseButton) public static Rect GetClickRect(Rect position, GUIContent label) { + if (label == null) + { + DebugUtility.LogException(nameof(label)); + return Rect.zero; + } + var copy = position; copy.size = GUIStyle.none.CalcSize(label); return copy; @@ -318,39 +379,4 @@ public static GUIContent GetIconGUIContent(IconType type) return EditorGUIUtility.IconContent(icon); } } - - public enum IconType - { - /// - /// Neutral message. - /// - None, - - /// - /// Info message. - /// - InfoMessage, - - /// - /// Warning message. - /// - WarningMessage, - - /// - /// Error message. - /// - ErrorMessage, - Info, - View, - Close, - Search, - WhiteLine, - GrayLine, - WhiteDropdown, - GrayDropdown, - Checkmark, - GrayPlayButton, - PlusMore, - Minus - } } \ No newline at end of file diff --git a/Assets/BetterEditorTools/Editor/EditorTools/Helpers/DropDown/DropdownBase.cs b/Assets/BetterEditorTools/Editor/EditorTools/Helpers/DropDown/DropdownBase.cs index e9db87a..fa6bc33 100644 --- a/Assets/BetterEditorTools/Editor/EditorTools/Helpers/DropDown/DropdownBase.cs +++ b/Assets/BetterEditorTools/Editor/EditorTools/Helpers/DropDown/DropdownBase.cs @@ -11,6 +11,7 @@ protected DropdownBase(GUIContent content) } public GUIContent Content { get; } + internal abstract bool Invoke(DropdownWindow downPopup); public bool Equals(string value) @@ -18,7 +19,6 @@ public bool Equals(string value) return Content.text.Equals(value); } - public bool Contains(string searchText, StringComparison comparison = StringComparison.OrdinalIgnoreCase) { diff --git a/Assets/BetterEditorTools/Editor/EditorTools/Helpers/DropDown/DropdownCollection.cs b/Assets/BetterEditorTools/Editor/EditorTools/Helpers/DropDown/DropdownCollection.cs index 3e6cc7a..d0e3ff4 100644 --- a/Assets/BetterEditorTools/Editor/EditorTools/Helpers/DropDown/DropdownCollection.cs +++ b/Assets/BetterEditorTools/Editor/EditorTools/Helpers/DropDown/DropdownCollection.cs @@ -1,7 +1,8 @@ using System; using System.Collections.Generic; using System.Linq; -using Better.DataStructures.Tree; +using Better.DataStructures.Runtime.Tree; +using Better.Extensions.Runtime; using UnityEngine; namespace Better.EditorTools.Helpers.DropDown @@ -10,6 +11,12 @@ public class DropdownCollection : TreeNode { public void AddItem(GUIContent[] keys, bool state, Action onSelect, object value) { + if (keys == null) + { + DebugUtility.LogException(nameof(keys)); + return; + } + var queue = new Queue(keys); var firstKey = queue.Dequeue(); var item = Children.FirstOrDefault(x => ValidateEquals(x, firstKey)); @@ -46,9 +53,11 @@ private void Iterate(TreeNode item, bool state, Action onS var first = bufferItem.Children.FirstOrDefault(x => ValidateEquals(x, bufferKey)); if (first == null) { - var node = queue.Count <= 0 - ? AddLeaf(bufferItem, bufferKey, state, onSelect, value) - : AddBranch(bufferItem, bufferKey); + TreeNode node; + if (queue.Count <= 0) + node = AddLeaf(bufferItem, bufferKey, state, onSelect, value); + else + node = AddBranch(bufferItem, bufferKey); if (queue.Count > 0) { diff --git a/Assets/BetterEditorTools/Editor/EditorTools/Helpers/DropDown/DropdownGUI.cs b/Assets/BetterEditorTools/Editor/EditorTools/Helpers/DropDown/DropdownGUI.cs index d6b4754..21fc6ac 100644 --- a/Assets/BetterEditorTools/Editor/EditorTools/Helpers/DropDown/DropdownGUI.cs +++ b/Assets/BetterEditorTools/Editor/EditorTools/Helpers/DropDown/DropdownGUI.cs @@ -1,6 +1,6 @@ using System; using System.Reflection; -using Better.DataStructures.Tree; +using Better.DataStructures.Runtime.Tree; using UnityEditor; using UnityEngine; @@ -8,8 +8,16 @@ namespace Better.EditorTools.Helpers.DropDown { internal static class DropdownGUI { - private static Vector2 iconSize = new Vector2(13f, 13f); + private const string SearchFieldName = "SearchField"; + private static Vector2 _iconSize = new Vector2(13f, 13f); + private static readonly MethodInfo _setMouseTooltipMethod; + static DropdownGUI() + { + var bindingFlags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy; + _setMouseTooltipMethod = typeof(GUIStyle).GetMethod("SetMouseTooltip",bindingFlags); + } + public static bool DrawItem(TreeNode item, bool hasChildren, bool enabled) { var content = item.Value.Content; @@ -30,8 +38,7 @@ public static bool DrawItem(TreeNode item, bool hasChildren, bool { if (!string.IsNullOrEmpty(content.tooltip)) { - var method = typeof(GUIStyle).GetMethod("SetMouseTooltip",BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy); - method?.Invoke(null, new object[] { content.tooltip, rect }); + _setMouseTooltipMethod?.Invoke(null, new object[] { content.tooltip, rect }); } } @@ -46,18 +53,18 @@ public static bool DrawItem(TreeNode item, bool hasChildren, bool { Styles.CheckMark.Draw(new Rect(rect) { - width = iconSize.x + 1f + width = _iconSize.x + 1f }, GUIContent.none, false, false, isHover, isHover); - rect.x += iconSize.x + 1f; - rect.width -= iconSize.x + 1f; + rect.x += _iconSize.x + 1f; + rect.width -= _iconSize.x + 1f; content.image = null; } else if (content.image == null) { Styles.ItemStyle.Draw(rect, GUIContent.none, false, false, isHover, isHover); - rect.x += iconSize.x + 1f; - rect.width -= iconSize.x + 1f; + rect.x += _iconSize.x + 1f; + rect.width -= _iconSize.x + 1f; } using (new EditorGUI.DisabledScope(!enabled)) @@ -102,10 +109,10 @@ public static void DrawHeader(GUIContent content, bool hasParent, Action onBackC public static string DrawSearchField(string searchString, bool isSearchFieldDisabled) { if (!isSearchFieldDisabled && string.IsNullOrEmpty(GUI.GetNameOfFocusedControl())) - EditorGUI.FocusTextInControl("SearchField"); + EditorGUI.FocusTextInControl(SearchFieldName); using (new EditorGUI.DisabledScope(isSearchFieldDisabled)) { - GUI.SetNextControlName("SearchField"); + GUI.SetNextControlName(SearchFieldName); var str = DrawSearchFieldControl(searchString); return str; } diff --git a/Assets/BetterEditorTools/Editor/EditorTools/Helpers/DropDown/DropdownSubTree.cs b/Assets/BetterEditorTools/Editor/EditorTools/Helpers/DropDown/DropdownSubTree.cs index 50d43e1..81cfbf4 100644 --- a/Assets/BetterEditorTools/Editor/EditorTools/Helpers/DropDown/DropdownSubTree.cs +++ b/Assets/BetterEditorTools/Editor/EditorTools/Helpers/DropDown/DropdownSubTree.cs @@ -1,4 +1,4 @@ -using Better.DataStructures.Tree; +using Better.DataStructures.Runtime.Tree; using UnityEngine; namespace Better.EditorTools.Helpers.DropDown diff --git a/Assets/BetterEditorTools/Editor/EditorTools/Helpers/DropDown/DropdownWindow.cs b/Assets/BetterEditorTools/Editor/EditorTools/Helpers/DropDown/DropdownWindow.cs index 81cd0d9..bdb33f0 100644 --- a/Assets/BetterEditorTools/Editor/EditorTools/Helpers/DropDown/DropdownWindow.cs +++ b/Assets/BetterEditorTools/Editor/EditorTools/Helpers/DropDown/DropdownWindow.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; using System.Linq; -using Better.DataStructures.Tree; +using Better.DataStructures.Runtime.Tree; using UnityEditor; using UnityEditor.Callbacks; using UnityEngine; diff --git a/Assets/BetterEditorTools/Editor/EditorTools/Helpers/EditorGUIHelpers.cs b/Assets/BetterEditorTools/Editor/EditorTools/Helpers/EditorGUIHelpers.cs index f4df5e2..2b3eeba 100644 --- a/Assets/BetterEditorTools/Editor/EditorTools/Helpers/EditorGUIHelpers.cs +++ b/Assets/BetterEditorTools/Editor/EditorTools/Helpers/EditorGUIHelpers.cs @@ -8,14 +8,15 @@ namespace Better.EditorTools.Helpers public static class EditorGUIHelpers { private static MethodInfo _defaultPropertyField; + + static EditorGUIHelpers() + { + var type = typeof(EditorGUI); + _defaultPropertyField = type.GetMethod("DefaultPropertyField", Defines.MethodFlags); + } + public static bool PropertyFieldSafe(Rect position, SerializedProperty property, GUIContent label) { - if (_defaultPropertyField == null) - { - var type = typeof(EditorGUI); - _defaultPropertyField = type.GetMethod("DefaultPropertyField", Defines.MethodFlags); - } - return (bool)_defaultPropertyField.Invoke(null, new object[] { position, property, label }); } } diff --git a/Assets/BetterEditorTools/Editor/EditorTools/Helpers/EditorPopup.cs b/Assets/BetterEditorTools/Editor/EditorTools/Helpers/EditorPopup.cs index 2290973..9c8e0cc 100644 --- a/Assets/BetterEditorTools/Editor/EditorTools/Helpers/EditorPopup.cs +++ b/Assets/BetterEditorTools/Editor/EditorTools/Helpers/EditorPopup.cs @@ -11,7 +11,6 @@ public class EditorPopup : EditorWindow private bool _destroyTexture; public event Action Closed; public event Action FocusLost; - public event Action Destroyed; public static EditorPopup Initialize(Texture texture, Rect position, bool needUpdate, diff --git a/Assets/BetterEditorTools/Editor/EditorTools/Helpers/IconType.cs b/Assets/BetterEditorTools/Editor/EditorTools/Helpers/IconType.cs new file mode 100644 index 0000000..e037c92 --- /dev/null +++ b/Assets/BetterEditorTools/Editor/EditorTools/Helpers/IconType.cs @@ -0,0 +1,37 @@ +namespace Better.EditorTools.Helpers +{ + public enum IconType + { + /// + /// Neutral message. + /// + None, + + /// + /// Info message. + /// + InfoMessage, + + /// + /// Warning message. + /// + WarningMessage, + + /// + /// Error message. + /// + ErrorMessage, + Info, + View, + Close, + Search, + WhiteLine, + GrayLine, + WhiteDropdown, + GrayDropdown, + Checkmark, + GrayPlayButton, + PlusMore, + Minus + } +} \ No newline at end of file diff --git a/Assets/BetterEditorTools/Editor/EditorTools/Helpers/IconType.cs.meta b/Assets/BetterEditorTools/Editor/EditorTools/Helpers/IconType.cs.meta new file mode 100644 index 0000000..b7967fb --- /dev/null +++ b/Assets/BetterEditorTools/Editor/EditorTools/Helpers/IconType.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 06d4b0d5e43549709c217e321caa421b +timeCreated: 1709335565 \ No newline at end of file diff --git a/Assets/BetterEditorTools/Editor/EditorTools/Helpers/ReorderableListHelpers.cs b/Assets/BetterEditorTools/Editor/EditorTools/Helpers/ReorderableListHelpers.cs index 07e5a5c..fa133cf 100644 --- a/Assets/BetterEditorTools/Editor/EditorTools/Helpers/ReorderableListHelpers.cs +++ b/Assets/BetterEditorTools/Editor/EditorTools/Helpers/ReorderableListHelpers.cs @@ -1,4 +1,5 @@ -using Better.Internal.Core.Runtime; +using System.Reflection; +using Better.Internal.Core.Runtime; using UnityEditor; using UnityEditorInternal; @@ -6,17 +7,17 @@ namespace Better.EditorTools.Helpers { public static class ReorderableListHelpers { - private static System.Reflection.MethodInfo _repaintInspectors = null; + private static MethodInfo _repaintInspectors = null; + + static ReorderableListHelpers() + { + var inspWin = typeof(ReorderableList); + _repaintInspectors = inspWin.GetMethod("InvalidateParentCaches", Defines.MethodFlags); + } //TODO: Need to find better way to refresh ReorderableList public static void RepaintAllInspectors(SerializedProperty property) { - if (_repaintInspectors == null) - { - var inspWin = typeof(ReorderableList); - _repaintInspectors = inspWin.GetMethod("InvalidateParentCaches", Defines.MethodFlags); - } - if (_repaintInspectors != null) _repaintInspectors.Invoke(null, new object[] { property.propertyPath }); } } diff --git a/Assets/BetterEditorTools/Editor/EditorTools/SerializedPropertyDefines.cs b/Assets/BetterEditorTools/Editor/EditorTools/SerializedPropertyDefines.cs deleted file mode 100644 index 000f196..0000000 --- a/Assets/BetterEditorTools/Editor/EditorTools/SerializedPropertyDefines.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Text.RegularExpressions; - -namespace Better.EditorTools -{ - public static class SerializedPropertyDefines - { - public static readonly Regex ArrayDataWithIndexRegex = new Regex(@"\.Array\.data\[[0-9]+\]", RegexOptions.Compiled); - - public static readonly Regex ArrayElementRegex = new Regex(@"\GArray\.data\[(\d+)\]", RegexOptions.Compiled); - public static readonly Regex ArrayIndexRegex = new Regex(@"\[([^\[\]]*)\]", RegexOptions.Compiled); - - public static readonly Regex ArrayRegex = new Regex(@"\.Array\.data", RegexOptions.Compiled); - - public const int IteratorNotAtEnd = 2; - } -} \ No newline at end of file diff --git a/Assets/BetterEditorTools/Editor/EditorTools/SerializedPropertyDefines.cs.meta b/Assets/BetterEditorTools/Editor/EditorTools/SerializedPropertyDefines.cs.meta deleted file mode 100644 index a0b23c3..0000000 --- a/Assets/BetterEditorTools/Editor/EditorTools/SerializedPropertyDefines.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 0c7214696e314ed8ad13ee53e65257ac -timeCreated: 1684041557 \ No newline at end of file diff --git a/Assets/BetterEditorTools/Editor/EditorTools/SerializedPropertyExtensions.cs b/Assets/BetterEditorTools/Editor/EditorTools/SerializedPropertyExtensions.cs deleted file mode 100644 index 75cbba1..0000000 --- a/Assets/BetterEditorTools/Editor/EditorTools/SerializedPropertyExtensions.cs +++ /dev/null @@ -1,431 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Runtime.CompilerServices; -using Better.Internal.Core.Runtime; -using Better.Tools.Runtime; -using UnityEditor; -using UnityEngine; - -namespace Better.EditorTools -{ - public static class SerializedPropertyExtensions - { - public static Type GetManagedType(this SerializedProperty property) - { -#if UNITY_2021_2_OR_NEWER - return property.managedReferenceValue?.GetType(); -#else - if (string.IsNullOrEmpty(property.managedReferenceFullTypename)) - { - return null; - } - - var split = property.managedReferenceFullTypename.Split(' '); - var assembly = GetAssembly(split[0]); - var currentValue = assembly.GetType(split[1]); - return currentValue; -#endif - } - - private static Assembly GetAssembly(string name) - { - return AppDomain.CurrentDomain.GetAssemblies() - .SingleOrDefault(assembly => assembly.GetName().Name == name); - } - - public static bool IsArrayElement(this SerializedProperty property) - { - return property.propertyPath.EndsWith("]"); - } - - public static int GetArrayIndex(this SerializedProperty p) - { - var matches = SerializedPropertyDefines.ArrayIndexRegex.Matches(p.propertyPath); - if (matches.Count > 0) - { - if (int.TryParse(matches[matches.Count - 1].Name, out var result)) - { - return result; - } - } - - return -1; - } - - public static string GetPropertyParentList(this SerializedProperty property) - { - string propertyPath = property.propertyPath; - return GetPropertyParentList(propertyPath); - } - - public static string GetPropertyParentList(string propertyPath) - { - int length = propertyPath.LastIndexOf(".Array.data[", StringComparison.Ordinal); - return length < 0 ? (string)null : propertyPath.Substring(0, length); - } - - public static string GetArrayNameFromPath(this SerializedProperty property) - { - return SerializedPropertyDefines.ArrayDataWithIndexRegex.Replace(property.propertyPath, ""); - } - - public static string GetArrayPath(this SerializedProperty property) - { - return SerializedPropertyDefines.ArrayRegex.Replace(property.propertyPath, ""); - } - - public static bool IsDisposed(this SerializedObject serializedObject) - { - if (serializedObject == null) - { - return true; - } - - var objectPrtInfo = typeof(SerializedObject).GetField("m_NativeObjectPtr", Defines.FieldsFlags); - try - { - if (objectPrtInfo != null) - { - var objectPrt = (IntPtr)objectPrtInfo.GetValue(serializedObject); - return objectPrt == IntPtr.Zero; - } - } - catch - { - return true; - } - - return true; - } - - public static bool IsDisposed(this SerializedProperty property) - { - if (property == null || property.serializedObject == null) - { - return true; - } - - var propertyPrtInfo = typeof(SerializedProperty).GetField("m_NativePropertyPtr", Defines.FieldsFlags); - var objectPrtInfo = typeof(SerializedObject).GetField("m_NativeObjectPtr", Defines.FieldsFlags); - try - { - if (propertyPrtInfo != null && objectPrtInfo != null) - { - var propertyPrt = (IntPtr)propertyPrtInfo.GetValue(property); - var objectPrt = (IntPtr)objectPrtInfo.GetValue(property.serializedObject); - return propertyPrt == IntPtr.Zero || objectPrt == IntPtr.Zero; - } - } - catch - { - return true; - } - - return true; - } - - public static bool Verify(this SerializedProperty property) - { - if (property == null || property.serializedObject == null) - { - return false; - } - - var verifyMethod = typeof(SerializedProperty).GetMethod("Verify", Defines.FieldsFlags); - - try - { - if (verifyMethod != null) - { - verifyMethod.Invoke(property, new object[] { SerializedPropertyDefines.IteratorNotAtEnd }); - return true; - } - } - catch - { - return false; - } - - return false; - } - - //https://gist.github.com/aholkner/214628a05b15f0bb169660945ac7923b - - /// - /// Get the value of the serialized property. - /// - /// - /// - public static object GetValue(this SerializedProperty property) - { - string propertyPath = property.propertyPath; - object value = property.serializedObject.targetObject; - int i = 0; - while (NextPathComponent(propertyPath, ref i, out var token)) - value = GetPathComponentValue(value, token); - return value; - } - - /// - /// Set the value of the serialized property. - /// - /// - /// - public static void SetValue(this SerializedProperty property, object value) - { - Undo.RecordObject(property.serializedObject.targetObject, $"Set {property.name}"); - - SetValueNoRecord(property, value); - - EditorUtility.SetDirty(property.serializedObject.targetObject); - property.serializedObject.ApplyModifiedProperties(); - } - - /// - /// Set the value of the serialized property, but do not record the change. - /// The change will not be persisted unless you call SetDirty and ApplyModifiedProperties. - /// - /// - /// - public static void SetValueNoRecord(this SerializedProperty property, object value) - { - var container = GetPropertyContainer(property, out var deferredToken); - - SetPathComponentValue(container, deferredToken, value); - } - - public static object GetPropertyContainer(this SerializedProperty property) - { - return GetPropertyContainer(property, out _); - } - - private static readonly HashSet CollectionTypes = new HashSet - { - typeof(List<>), - typeof(Dictionary<,>), - typeof(HashSet<>), - typeof(Stack<>), - typeof(Queue<>), - // Add more collection types here if needed - }; - - public static object GetLastNonCollectionContainer(this SerializedProperty property) - { - var containers = property.GetPropertyContainers(); - for (var index = containers.Count - 1; index >= 0; index--) - { - var container = containers[index]; - if (IsCollectionType(container.GetType())) continue; - return container; - } - - return containers.FirstOrDefault(); - } - - private static bool IsCollectionType(this Type targetType) - { - if (targetType.IsArray || targetType.IsGenericType) - { - var genericType = targetType.IsArray ? targetType.GetElementType() : targetType.GetGenericArguments()[0]; - foreach (var collectionType in CollectionTypes) - { - var constructedType = collectionType.MakeGenericType(genericType); - if (targetType == constructedType) - { - return true; - } - } - } - - return false; - } - - public static List GetPropertyContainers(this SerializedProperty property) - { - string propertyPath = property.propertyPath; - object container = property.serializedObject.targetObject; - - int i = 0; - PropertyPathComponent deferredToken; - var list = new List(); - list.Add(container); - NextPathComponent(propertyPath, ref i, out deferredToken); - while (NextPathComponent(propertyPath, ref i, out var token)) - { - container = GetPathComponentValue(container, deferredToken); - deferredToken = token; - list.Add(container); - } - - Debug.Assert(!container.GetType().IsValueType, - $"Cannot use SerializedObject.SetValue on a struct object, as the result will be set on a temporary. Either change {container.GetType().Name} to a class, or use SetValue with a parent member."); - - return list; - } - - private static object GetPropertyContainer(SerializedProperty property, out PropertyPathComponent deferredToken) - { - string propertyPath = property.propertyPath; - object container = property.serializedObject.targetObject; - - int i = 0; - NextPathComponent(propertyPath, ref i, out deferredToken); - while (NextPathComponent(propertyPath, ref i, out var token)) - { - container = GetPathComponentValue(container, deferredToken); - deferredToken = token; - } - - return container; - } - - /// - /// Union type representing either a property name or array element index. The element - /// index is valid only if propertyName is null. - /// - private struct PropertyPathComponent - { - public string PropertyName { get; set; } - public int ElementIndex { get; set; } - } - - - /// - /// Parse the next path component from a SerializedProperty.propertyPath. For simple field/property access, - /// this is just tokenizing on '.' and returning each field/property name. Array/list access is via - /// the pseudo-property "Array.data[N]", so this method parses that and returns just the array/list index N. - /// Call this method repeatedly to access all path components. For example: - /// string propertyPath = "quests.Array.data[0].goal"; - /// int i = 0; - /// NextPropertyPathToken(propertyPath, ref i, out var component); - /// => component = { propertyName = "quests" }; - /// NextPropertyPathToken(propertyPath, ref i, out var component) - /// => component = { elementIndex = 0 }; - /// NextPropertyPathToken(propertyPath, ref i, out var component) - /// => component = { propertyName = "goal" }; - /// NextPropertyPathToken(propertyPath, ref i, out var component) - /// => returns false - /// - /// - /// - /// - /// - private static bool NextPathComponent(string propertyPath, ref int index, out PropertyPathComponent component) - { - component = new PropertyPathComponent(); - - if (index >= propertyPath.Length) - return false; - - var arrayElementMatch = SerializedPropertyDefines.ArrayElementRegex.Match(propertyPath, index); - if (arrayElementMatch.Success) - { - index += arrayElementMatch.Length + 1; // Skip past next '.' - component.ElementIndex = int.Parse(arrayElementMatch.Groups[1].Value); - return true; - } - - int dot = propertyPath.IndexOf('.', index); - if (dot == -1) - { - component.PropertyName = propertyPath.Substring(index); - index = propertyPath.Length; - } - else - { - component.PropertyName = propertyPath.Substring(index, dot - index); - index = dot + 1; // Skip past next '.' - } - - return true; - } - - private static object GetPathComponentValue(object container, PropertyPathComponent component) - { - if (component.PropertyName == null) - return ((IList)container)[component.ElementIndex]; - else - return GetMemberValue(container, component.PropertyName); - } - - private static void SetPathComponentValue(object container, PropertyPathComponent component, object value) - { - if (component.PropertyName == null) - ((IList)container)[component.ElementIndex] = value; - else - SetMemberValue(container, component.PropertyName, value); - } - - private static object GetMemberValue(object container, string name) - { - if (container == null) - return null; - var type = container.GetType(); - var members = TraverseBaseClasses(type, name); - for (int i = 0; i < members.Count; ++i) - { - if (members[i] is FieldInfo field) - return field.GetValue(container); - - if (members[i] is PropertyInfo property) - return property.GetValue(container); - } - - return null; - } - - private static List TraverseBaseClasses(Type currentType, string name) - { - var memberInfos = new List(); - - var currentTypeFields = currentType.GetMember(name, Defines.FieldsFlags); - memberInfos.AddRange(currentTypeFields); - - var baseType = currentType.BaseType; - - if (baseType == null) return memberInfos; - var baseTypeFields = baseType.GetMember(name, Defines.FieldsFlags); - memberInfos.AddRange(baseTypeFields); - - memberInfos.AddRange(TraverseBaseClasses(baseType, name)); // Recursively traverse the base classes - - return memberInfos; - } - - private static void SetMemberValue(object container, string name, object value) - { - var type = container.GetType(); - var members = type.GetMember(name, Defines.FieldsFlags); - for (int i = 0; i < members.Length; ++i) - { - if (members[i] is FieldInfo field) - { - if (!type.IsValueType && !type.IsEnum) - { - field.SetValue(container, value); - } - else - { - field.SetValueDirect(__makeref(container), value); - } - - return; - } - else if (members[i] is PropertyInfo property) - { - if (!type.IsValueType && !type.IsEnum) - { - property.SetValue(container, value); - } - - return; - } - } - - Debug.Assert(false, $"Failed to set member {container}.{name} via reflection"); - } - } -} \ No newline at end of file diff --git a/Assets/BetterEditorTools/Editor/EditorTools/SerializedPropertyExtensions.cs.meta b/Assets/BetterEditorTools/Editor/EditorTools/SerializedPropertyExtensions.cs.meta deleted file mode 100644 index 02dcd0e..0000000 --- a/Assets/BetterEditorTools/Editor/EditorTools/SerializedPropertyExtensions.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: b119f4216b1947ebbd366a2b2d32f438 -timeCreated: 1680990335 \ No newline at end of file diff --git a/Assets/BetterEditorTools/Editor/EditorTools/SerializedPropertyUtil.cs b/Assets/BetterEditorTools/Editor/EditorTools/SerializedPropertyUtil.cs deleted file mode 100644 index d4d9ed2..0000000 --- a/Assets/BetterEditorTools/Editor/EditorTools/SerializedPropertyUtil.cs +++ /dev/null @@ -1,206 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Text.RegularExpressions; -using Better.Extensions.Runtime; -using UnityEditor; -using UnityEditor.Callbacks; - -namespace Better.EditorTools -{ - public class FieldInfoCache - { - public FieldInfoCache(FieldInfo fieldInfo, Type type) - { - FieldInfo = fieldInfo; - Type = type; - } - - public FieldInfo FieldInfo { get; } - public Type Type { get; } - } - - public static class SerializedPropertyUtil - { - [DidReloadScripts] - private static void Reload() - { - FieldInfoFromPropertyPathCache.Clear(); - } - - private struct Cache : IEquatable - { - private readonly Type _host; - private readonly string _path; - - public Cache(Type host, string path) - { - _host = host; - _path = path; - } - - public bool Equals(Cache other) - { - return _host == other._host && string.Equals(_path, other._path); - } - - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is Cache && Equals((Cache)obj); - } - - public override int GetHashCode() - { - unchecked - { - return ((_host != null ? _host.GetHashCode() : 0) * 397) ^ (_path != null ? _path.GetHashCode() : 0); - } - } - } - - private static readonly Dictionary FieldInfoFromPropertyPathCache = new Dictionary(); - - public static Type GetScriptTypeFromProperty(this SerializedProperty property) - { - if (property.serializedObject.targetObject != null) - return property.serializedObject.targetObject.GetType(); - - // Fallback in case the targetObject has been destroyed but the property is still valid. - var scriptProp = property.serializedObject.FindProperty("m_Script"); - - if (scriptProp == null) - return null; - - var script = scriptProp.objectReferenceValue as MonoScript; - - return script == null ? null : script.GetClass(); - } - - public static List GetAttributes(this SerializedProperty property, bool inherit = false) where TAttributes : Attribute - { - var fieldInfo = property.GetFieldInfoAndStaticTypeFromProperty(); - if (fieldInfo == null) return null; - var attributes = fieldInfo.FieldInfo.GetCustomAttributes(inherit); - return attributes.ToList(); - } - - /// - /// Returns the field info and field type for the property. The types are based on the - /// static field definition. - /// - /// - /// - public static FieldInfoCache GetFieldInfoAndStaticTypeFromProperty(this SerializedProperty property) - { - var classType = GetScriptTypeFromProperty(property); - if (classType == null) - { - return null; - } - - var fieldPath = property.propertyPath; - if (property.propertyType == SerializedPropertyType.ManagedReference) - { - // When the field we are trying to access is a dynamic instance, things are a bit more tricky - // since we cannot "statically" (looking only at the parent class field types) know the actual - // "classType" of the parent class. - - // The issue also is that at this point our only view on the object is the very limited SerializedProperty. - - // So we have to: - // 1. try to get the FQN from for the current managed type from the serialized data, - // 2. get the path *in the current managed instance* of the field we are pointing to, - // 3. foward that to 'GetFieldInfoFromPropertyPath' as if it was a regular field, - - var objectTypename = property.managedReferenceFullTypename; - GetTypeFromManagedReferenceFullTypeName(objectTypename, out classType); - - fieldPath = property.propertyPath; - } - - if (classType == null) - { - return null; - } - - return GetFieldInfoFromPropertyPath(classType, fieldPath); - } - - /// - /// Create a Type instance from the managed reference full type name description. - /// The expected format for the typename string is the one returned by SerializedProperty.managedReferenceFullTypename. - /// - /// - /// - /// - public static bool GetTypeFromManagedReferenceFullTypeName(string managedReferenceFullTypename, out Type managedReferenceInstanceType) - { - managedReferenceInstanceType = null; - - var parts = managedReferenceFullTypename.Split(' '); - if (parts.Length == 2) - { - var assemblyPart = parts[0]; - var nsClassnamePart = parts[1]; - managedReferenceInstanceType = Type.GetType($"{nsClassnamePart}, {assemblyPart}"); - } - - return managedReferenceInstanceType != null; - } - - public static FieldInfoCache GetFieldInfoFromPropertyPath(Type host, string path) - { - var cache = new Cache(host, path); - - if (FieldInfoFromPropertyPathCache.TryGetValue(cache, out var fieldInfoCache)) - { - return fieldInfoCache; - } - - // we are looking for array element only when the path ends with Array.data[x] - var lookingForArrayElement = Regex.IsMatch(path, SerializedPropertyDefines.ArrayDataWithIndexRegex.ToString() + "$"); - // remove any Array.data[x] from the path because it is prevents cache searching. - path = SerializedPropertyDefines.ArrayDataWithIndexRegex.Replace(path, ".___ArrayElement___"); - - FieldInfo fieldInfo = null; - var type = host; - var parts = path.Split('.'); - for (var i = 0; i < parts.Length; i++) - { - var member = parts[i]; - // GetField on class A will not find private fields in base classes to A, - // so we have to iterate through the base classes and look there too. - // Private fields are relevant because they can still be shown in the Inspector, - // and that applies to private fields in base classes too. - FieldInfo foundField = null; - for (var currentType = type; foundField == null && currentType != null; currentType = currentType.BaseType) - foundField = currentType.GetField(member, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); - - if (foundField == null) - { - FieldInfoFromPropertyPathCache.Add(cache, null); - return null; - } - - fieldInfo = foundField; - type = fieldInfo.FieldType; - // we want to get the element type if we are looking for Array.data[x] - if (i < parts.Length - 1 && parts[i + 1] == "___ArrayElement___" && type.IsArrayOrList()) - { - i++; // skip the "___ArrayElement___" part - type = type.GetArrayOrListElementType(); - } - } - - // we want to get the element type if we are looking for Array.data[x] - if (lookingForArrayElement && type != null && type.IsArrayOrList()) - type = type.GetArrayOrListElementType(); - - fieldInfoCache = new FieldInfoCache(fieldInfo, type); - FieldInfoFromPropertyPathCache.Add(cache, fieldInfoCache); - return fieldInfoCache; - } - } -} \ No newline at end of file diff --git a/Assets/BetterEditorTools/Editor/EditorTools/SerializedPropertyUtil.cs.meta b/Assets/BetterEditorTools/Editor/EditorTools/SerializedPropertyUtil.cs.meta deleted file mode 100644 index 68f0f51..0000000 --- a/Assets/BetterEditorTools/Editor/EditorTools/SerializedPropertyUtil.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 1217f97a487c45068467557843cb4b29 -timeCreated: 1680997777 \ No newline at end of file diff --git a/Assets/BetterEditorTools/Editor/EditorTools/Utilities/BaseUtility.cs b/Assets/BetterEditorTools/Editor/EditorTools/Utilities/BaseUtility.cs index 34a0026..9710b1b 100644 --- a/Assets/BetterEditorTools/Editor/EditorTools/Utilities/BaseUtility.cs +++ b/Assets/BetterEditorTools/Editor/EditorTools/Utilities/BaseUtility.cs @@ -1,15 +1,11 @@ using System; using System.Collections.Generic; using Better.EditorTools.Drawers.Base; +using Better.Extensions.Runtime; using UnityEditor; namespace Better.EditorTools.Utilities { - public abstract class UtilityWrapper - { - public abstract void Deconstruct(); - } - public abstract class BaseUtility where THandler : new() { private static THandler _instance; @@ -40,7 +36,7 @@ private void Construct() _wrappersCollection = GenerateCollection(); _availableTypes = GenerateAvailable(); } - + /// /// Type collection for . @@ -80,7 +76,7 @@ private void Construct() protected abstract HashSet GenerateAvailable(); /// - /// Generate ready to use wrapper's instance by dictionary from + /// Generate ready to use wrapper's instance by dictionary from /// /// /// @@ -88,6 +84,18 @@ private void Construct() /// public T GetUtilityWrapper(Type fieldType, Type attributeType) where T : UtilityWrapper { + if (fieldType == null) + { + DebugUtility.LogException(nameof(fieldType)); + return null; + } + + if (attributeType == null) + { + DebugUtility.LogException(nameof(attributeType)); + return null; + } + if (!IsSupported(fieldType)) { return null; @@ -97,7 +105,9 @@ public T GetUtilityWrapper(Type fieldType, Type attributeType) where T : Util { return (T)Activator.CreateInstance(wrapperType); } - throw new KeyNotFoundException($"Supported types not found for {fieldType}"); + + DebugUtility.LogException($"Supported types not found for {fieldType}"); + return null; } /// @@ -108,12 +118,14 @@ public T GetUtilityWrapper(Type fieldType, Type attributeType) where T : Util /// public virtual bool IsSupported(Type type) { + if (type == null) + { + DebugUtility.LogException(nameof(type)); + } + return _availableTypes.Contains(type); } - } - - public static class BaseUtilityExtension - { + /// /// Validates stored properties if their supported /// @@ -121,12 +133,12 @@ public static class BaseUtilityExtension /// /// /// - public static void ValidateCachedProperties(this BaseUtility handler, WrapperCollection gizmoWrappers) where T : UtilityWrapper where THandler : new() + public void ValidateCachedProperties(WrapperCollection gizmoWrappers) where T : UtilityWrapper { List keysToRemove = null; foreach (var value in gizmoWrappers) { - if (handler.IsSupported(value.Value.Type)) continue; + if (IsSupported(value.Value.Type)) continue; if (keysToRemove == null) { keysToRemove = new List(); diff --git a/Assets/BetterEditorTools/Editor/EditorTools/Utilities/UtilityWrapper.cs b/Assets/BetterEditorTools/Editor/EditorTools/Utilities/UtilityWrapper.cs new file mode 100644 index 0000000..7f53aa1 --- /dev/null +++ b/Assets/BetterEditorTools/Editor/EditorTools/Utilities/UtilityWrapper.cs @@ -0,0 +1,7 @@ +namespace Better.EditorTools.Utilities +{ + public abstract class UtilityWrapper + { + public abstract void Deconstruct(); + } +} \ No newline at end of file diff --git a/Assets/BetterEditorTools/Editor/EditorTools/Utilities/UtilityWrapper.cs.meta b/Assets/BetterEditorTools/Editor/EditorTools/Utilities/UtilityWrapper.cs.meta new file mode 100644 index 0000000..0fcae3c --- /dev/null +++ b/Assets/BetterEditorTools/Editor/EditorTools/Utilities/UtilityWrapper.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: cfe49fae8a25475e865dac13d8cc9fc3 +timeCreated: 1709335739 \ No newline at end of file diff --git a/Assets/BetterEditorTools/Editor/SettingsTools.meta b/Assets/BetterEditorTools/Editor/SettingsTools.meta deleted file mode 100644 index 8bca50a..0000000 --- a/Assets/BetterEditorTools/Editor/SettingsTools.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 8c0054b53acf46858451f98aa5f4813d -timeCreated: 1686787046 \ No newline at end of file diff --git a/Assets/BetterEditorTools/Editor/SettingsTools/ProjectSettingsProvider.cs b/Assets/BetterEditorTools/Editor/SettingsTools/ProjectSettingsProvider.cs deleted file mode 100644 index c0e613c..0000000 --- a/Assets/BetterEditorTools/Editor/SettingsTools/ProjectSettingsProvider.cs +++ /dev/null @@ -1,47 +0,0 @@ -using Better.Tools.Runtime.Settings; -using UnityEditor; -using UnityEngine; - -namespace Better.EditorTools.SettingsTools -{ - public abstract class ProjectSettingsProvider : SettingsProvider where T : ProjectSettings - { - protected readonly T _settings; - protected readonly SerializedObject _settingsObject; - private GUIStyle _style; - private const int Space = 8; - - protected ProjectSettingsProvider(ProjectSettingsTools tools, SettingsScope scope = SettingsScope.User) - : base(tools.ProjectSettingKey, scope) - { - _settings = tools.LoadOrCreateScriptableObject(); - _settingsObject = new SerializedObject(_settings); - label = tools.NamespacePrefix; - } - - public override void OnGUI(string searchContext) - { - var style = CreateOrGetStyle(); - using (new EditorGUILayout.VerticalScope(style)) - { - DrawGUI(); - } - - _settingsObject.ApplyModifiedPropertiesWithoutUndo(); - } - - private GUIStyle CreateOrGetStyle() - { - if (_style != null) - { - return _style; - } - - _style = new GUIStyle(); - _style.margin = new RectOffset(Space, Space, Space, Space); - return _style; - } - - protected abstract void DrawGUI(); - } -} \ No newline at end of file diff --git a/Assets/BetterEditorTools/Editor/SettingsTools/ProjectSettingsProvider.cs.meta b/Assets/BetterEditorTools/Editor/SettingsTools/ProjectSettingsProvider.cs.meta deleted file mode 100644 index ae15e26..0000000 --- a/Assets/BetterEditorTools/Editor/SettingsTools/ProjectSettingsProvider.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: b155d23665d44e588e7a82fd5d21f9d5 -timeCreated: 1686787056 \ No newline at end of file diff --git a/Assets/BetterEditorTools/Editor/SettingsTools/ProjectSettingsRegisterer.cs b/Assets/BetterEditorTools/Editor/SettingsTools/ProjectSettingsRegisterer.cs deleted file mode 100644 index 2b68670..0000000 --- a/Assets/BetterEditorTools/Editor/SettingsTools/ProjectSettingsRegisterer.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using Better.Extensions.Runtime; -using Better.Tools.Runtime.Settings; -using UnityEditor; -using UnityEngine; - -namespace Better.EditorTools.SettingsTools -{ - public static class ProjectSettingsRegisterer - { - - [SettingsProviderGroup] - internal static SettingsProvider[] CreateSettingsProvider() - { - var allInheritedType = typeof(ProjectSettings).GetAllInheritedTypeWithUnityObjects(); - var types = allInheritedType - .SelectMany(CollectionSelector).Where(ValidateInternal); - var instances = types.Select(Activator.CreateInstance).Cast(); - // First parameter is the path in the Settings window. - // Second parameter is the scope of this setting: it only appears in the Settings window for the Project scope. - return instances.ToArray(); - } - - private static IEnumerable CollectionSelector(Type x) - { - return typeof(ProjectSettingsProvider<>).MakeGenericType(x).GetAllInheritedType(); - } - - private static bool ValidateInternal(Type type) - { - if (type.IsValueType) - { - return true; - } - - var constructor = type.GetConstructor( - BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, - null, Type.EmptyTypes, null); - - return constructor != null; - } - } -} \ No newline at end of file diff --git a/Assets/BetterEditorTools/Editor/SettingsTools/ProjectSettingsRegisterer.cs.meta b/Assets/BetterEditorTools/Editor/SettingsTools/ProjectSettingsRegisterer.cs.meta deleted file mode 100644 index baeafe1..0000000 --- a/Assets/BetterEditorTools/Editor/SettingsTools/ProjectSettingsRegisterer.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: e63b27e159aa46699527d76ce9a788f8 -timeCreated: 1686787056 \ No newline at end of file diff --git a/Assets/BetterEditorTools/Editor/SettingsTools/ProjectSettingsTools.cs b/Assets/BetterEditorTools/Editor/SettingsTools/ProjectSettingsTools.cs deleted file mode 100644 index 916d9dd..0000000 --- a/Assets/BetterEditorTools/Editor/SettingsTools/ProjectSettingsTools.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System.IO; -using Better.Internal.Core.Runtime; -using Better.Tools.Runtime; -using Better.Tools.Runtime.Settings; -using UnityEditor; -using UnityEngine; - -namespace Better.EditorTools.SettingsTools -{ - public class ProjectSettingsTools where T : ProjectSettings - { - private readonly string[] _folderPaths; - public string ProjectSettingKey { get; } - public string NamespacePrefix { get; } - - public ProjectSettingsTools(string namespacePrefix, string settingMenuItem) - { - NamespacePrefix = namespacePrefix; - _folderPaths = new string[] - { PrefixConstants.BetterPrefix, NamespacePrefix, PrefixConstants.ResourcesPrefix }; - var menuItemPrefix = $"{PrefixConstants.BetterPrefix}/{settingMenuItem}"; - ProjectSettingKey = $"{PrefixConstants.ProjectPrefix}/{menuItemPrefix}"; - } - - public ProjectSettingsTools(string namespacePrefix, string settingMenuItem, string[] settingsFolderNames) - { - NamespacePrefix = namespacePrefix; - _folderPaths = settingsFolderNames; - var menuItemPrefix = $"{PrefixConstants.BetterPrefix}/{settingMenuItem}"; - ProjectSettingKey = $"{PrefixConstants.ProjectPrefix}/{menuItemPrefix}"; - } - - private string GenerateResourcesRelativePath() - { - return Path.Combine(_folderPaths); - } - - public T LoadOrCreateScriptableObject() - { - var name = typeof(T).Name; - var settings = Resources.Load(name); - if (settings != null) return settings; - - settings = ScriptableObject.CreateInstance(); - - var relativePath = GenerateResourcesRelativePath(); - var absolutePath = Path.Combine(Application.dataPath, relativePath); - - if (!Directory.Exists(absolutePath)) - { - Directory.CreateDirectory(absolutePath); - AssetDatabase.Refresh(ImportAssetOptions.Default); - } - relativePath = Path.Combine("Assets", relativePath, $"{name}.asset"); - AssetDatabase.CreateAsset(settings, relativePath); - return settings; - } - } -} \ No newline at end of file diff --git a/Assets/BetterEditorTools/Editor/SettingsTools/ProjectSettingsTools.cs.meta b/Assets/BetterEditorTools/Editor/SettingsTools/ProjectSettingsTools.cs.meta deleted file mode 100644 index 1ec134e..0000000 --- a/Assets/BetterEditorTools/Editor/SettingsTools/ProjectSettingsTools.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: cf575afd022c48ed8ee78ca1108e8527 -timeCreated: 1681156280 \ No newline at end of file diff --git a/Assets/BetterEditorTools/Editor/SettingsTools/ProjectSettingsToolsContainer.cs b/Assets/BetterEditorTools/Editor/SettingsTools/ProjectSettingsToolsContainer.cs deleted file mode 100644 index 19eb6ff..0000000 --- a/Assets/BetterEditorTools/Editor/SettingsTools/ProjectSettingsToolsContainer.cs +++ /dev/null @@ -1,20 +0,0 @@ -namespace Better.EditorTools.SettingsTools -{ - public class ProjectSettingsToolsContainer where THandler : new() - { - private static THandler _instance; - - public static THandler Instance - { - get - { - if (_instance == null) - { - _instance = new THandler(); - } - - return _instance; - } - } - } -} \ No newline at end of file diff --git a/Assets/BetterEditorTools/Editor/SettingsTools/ProjectSettingsToolsContainer.cs.meta b/Assets/BetterEditorTools/Editor/SettingsTools/ProjectSettingsToolsContainer.cs.meta deleted file mode 100644 index 1d300a9..0000000 --- a/Assets/BetterEditorTools/Editor/SettingsTools/ProjectSettingsToolsContainer.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: dd9b271c836b465a89890d82f9e55add -timeCreated: 1686830188 \ No newline at end of file diff --git a/Assets/BetterEditorTools/Runtime/Settings.meta b/Assets/BetterEditorTools/Runtime/Settings.meta deleted file mode 100644 index 66a822c..0000000 --- a/Assets/BetterEditorTools/Runtime/Settings.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: d75e452ce31241b4b6f2f6829db20f52 -timeCreated: 1686835492 \ No newline at end of file diff --git a/Assets/BetterEditorTools/Runtime/Settings/ProjectSettings.cs b/Assets/BetterEditorTools/Runtime/Settings/ProjectSettings.cs deleted file mode 100644 index a11d90d..0000000 --- a/Assets/BetterEditorTools/Runtime/Settings/ProjectSettings.cs +++ /dev/null @@ -1,9 +0,0 @@ -using UnityEngine; - -namespace Better.Tools.Runtime.Settings -{ - public abstract class ProjectSettings : ScriptableObject - { - - } -} \ No newline at end of file diff --git a/Assets/BetterEditorTools/Runtime/Settings/ProjectSettings.cs.meta b/Assets/BetterEditorTools/Runtime/Settings/ProjectSettings.cs.meta deleted file mode 100644 index 7da082f..0000000 --- a/Assets/BetterEditorTools/Runtime/Settings/ProjectSettings.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: cc8ec59f6d794b889b5a2ac151d8b961 -timeCreated: 1686782557 \ No newline at end of file diff --git a/Assets/BetterEditorTools/package.json b/Assets/BetterEditorTools/package.json index 703012b..58e75b9 100644 --- a/Assets/BetterEditorTools/package.json +++ b/Assets/BetterEditorTools/package.json @@ -2,11 +2,11 @@ "name": "com.uurha.bettereditortools", "displayName": "Better Editor Tools", "description": "Collection of useful tools for Unity Editor", - "version": "1.0.71", - "unity": "2020.1", + "version": "1.5.0", + "unity": "2021.3", "dependencies": { - "com.uurha.betterdatastructures": "0.1.2", - "com.uurha.betterextensions": "1.2.3", + "com.uurha.betterdatastructures": "0.1.7", + "com.uurha.betterextensions": "1.5.7", "com.tdw.better.internal.core": "0.0.2" }, "author": { diff --git a/Packages/manifest.json b/Packages/manifest.json index d6dfc4d..9588092 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -1,18 +1,18 @@ { "dependencies": { "com.tdw.better.internal.core": "0.0.2", - "com.unity.collab-proxy": "1.17.7", + "com.unity.collab-proxy": "2.0.1", "com.unity.feature.development": "1.0.1", - "com.unity.ide.rider": "3.0.16", - "com.unity.ide.visualstudio": "2.0.16", + "com.unity.ide.rider": "3.0.18", + "com.unity.ide.visualstudio": "2.0.17", "com.unity.ide.vscode": "1.2.5", "com.unity.test-framework": "1.1.31", "com.unity.textmeshpro": "3.0.6", "com.unity.timeline": "1.6.4", "com.unity.ugui": "1.0.0", - "com.unity.visualscripting": "1.7.8", - "com.uurha.betterdatastructures": "0.1.2", - "com.uurha.betterextensions": "1.2.3", + "com.unity.visualscripting": "1.8.0", + "com.uurha.betterdatastructures": "0.1.7", + "com.uurha.betterextensions": "1.5.7", "com.unity.modules.ai": "1.0.0", "com.unity.modules.androidjni": "1.0.0", "com.unity.modules.animation": "1.0.0", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index 1021b25..7918b77 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -8,12 +8,10 @@ "url": "https://package.openupm.com" }, "com.unity.collab-proxy": { - "version": "1.17.7", + "version": "2.0.1", "depth": 0, "source": "registry", - "dependencies": { - "com.unity.services.core": "1.0.1" - }, + "dependencies": {}, "url": "https://packages.unity.com" }, "com.unity.editorcoroutines": { @@ -35,17 +33,17 @@ "depth": 0, "source": "builtin", "dependencies": { - "com.unity.ide.visualstudio": "2.0.16", - "com.unity.ide.rider": "3.0.16", + "com.unity.ide.visualstudio": "2.0.17", + "com.unity.ide.rider": "3.0.18", "com.unity.ide.vscode": "1.2.5", "com.unity.editorcoroutines": "1.0.0", - "com.unity.performance.profile-analyzer": "1.1.1", + "com.unity.performance.profile-analyzer": "1.2.2", "com.unity.test-framework": "1.1.31", "com.unity.testtools.codecoverage": "1.2.2" } }, "com.unity.ide.rider": { - "version": "3.0.16", + "version": "3.0.18", "depth": 0, "source": "registry", "dependencies": { @@ -54,7 +52,7 @@ "url": "https://packages.unity.com" }, "com.unity.ide.visualstudio": { - "version": "2.0.16", + "version": "2.0.17", "depth": 0, "source": "registry", "dependencies": { @@ -69,31 +67,13 @@ "dependencies": {}, "url": "https://packages.unity.com" }, - "com.unity.nuget.newtonsoft-json": { - "version": "3.0.2", - "depth": 2, - "source": "registry", - "dependencies": {}, - "url": "https://packages.unity.com" - }, "com.unity.performance.profile-analyzer": { - "version": "1.1.1", + "version": "1.2.2", "depth": 1, "source": "registry", "dependencies": {}, "url": "https://packages.unity.com" }, - "com.unity.services.core": { - "version": "1.6.0", - "depth": 1, - "source": "registry", - "dependencies": { - "com.unity.modules.unitywebrequest": "1.0.0", - "com.unity.nuget.newtonsoft-json": "3.0.2", - "com.unity.modules.androidjni": "1.0.0" - }, - "url": "https://packages.unity.com" - }, "com.unity.settings-manager": { "version": "1.0.3", "depth": 2, @@ -153,7 +133,7 @@ } }, "com.unity.visualscripting": { - "version": "1.7.8", + "version": "1.8.0", "depth": 0, "source": "registry", "dependencies": { @@ -163,17 +143,21 @@ "url": "https://packages.unity.com" }, "com.uurha.betterdatastructures": { - "version": "0.1.2", + "version": "0.1.7", "depth": 0, "source": "registry", - "dependencies": {}, + "dependencies": { + "com.tdw.better.internal.core": "0.0.2" + }, "url": "https://package.openupm.com" }, "com.uurha.betterextensions": { - "version": "1.2.3", + "version": "1.5.7", "depth": 0, "source": "registry", - "dependencies": {}, + "dependencies": { + "com.tdw.better.internal.core": "0.0.2" + }, "url": "https://package.openupm.com" }, "com.unity.modules.ai": { diff --git a/ProjectSettings/ProjectVersion.txt b/ProjectSettings/ProjectVersion.txt index 3643b02..bca3d02 100644 --- a/ProjectSettings/ProjectVersion.txt +++ b/ProjectSettings/ProjectVersion.txt @@ -1,2 +1,2 @@ -m_EditorVersion: 2021.3.16f1 -m_EditorVersionWithRevision: 2021.3.16f1 (4016570cf34f) +m_EditorVersion: 2021.3.21f1 +m_EditorVersionWithRevision: 2021.3.21f1 (1b156197d683)