diff --git a/Editor/CustomEditors/Base/ExtendedEditor.cs b/Editor/CustomEditors/Base/ExtendedEditor.cs
index e710329..1653143 100644
--- a/Editor/CustomEditors/Base/ExtendedEditor.cs
+++ b/Editor/CustomEditors/Base/ExtendedEditor.cs
@@ -1,6 +1,5 @@
using UnityEditor;
using UnityEngine;
-using UnityEngine.UIElements;
namespace Better.Commons.EditorAddons.CustomEditors.Base
{
@@ -23,21 +22,20 @@ protected ExtendedEditor(Object target, SerializedObject serializedObject)
/// This method called just right after instance created
///
public abstract void OnEnable();
-
+
///
/// Use to draw your inspector
///
- public abstract VisualElement CreateInspectorGUI();
-
+ public abstract void OnInspectorGUI();
+
///
/// This method called than editor disables
///
public abstract void OnDisable();
-
+
///
/// Called when object data in editor is changed
///
- ///
- public abstract void OnChanged(SerializedObject serializedObject);
+ public abstract void OnChanged();
}
}
\ No newline at end of file
diff --git a/Editor/CustomEditors/MultiEditor.cs b/Editor/CustomEditors/MultiEditor.cs
index 8630b87..a9d8b15 100644
--- a/Editor/CustomEditors/MultiEditor.cs
+++ b/Editor/CustomEditors/MultiEditor.cs
@@ -7,8 +7,6 @@
using Better.Commons.EditorAddons.Extensions;
using Better.Commons.Runtime.Extensions;
using UnityEditor;
-using UnityEditor.UIElements;
-using UnityEngine.UIElements;
using Object = UnityEngine.Object;
namespace Better.Commons.EditorAddons.CustomEditors
@@ -92,47 +90,35 @@ private void Iterate(IReadOnlyList<(Type type, MultiEditorAttribute)> extensions
}
}
- public override VisualElement CreateInspectorGUI()
+ public override void OnInspectorGUI()
{
- var container = new VisualElement();
-
- for (var i = 0; i < _preEditors.Count; i++)
+ using (var change = new EditorGUI.ChangeCheckScope())
{
- var element = _preEditors[i].CreateInspectorGUI();
- if (element != null)
+ for (var i = 0; i < _preEditors.Count; i++)
{
- container.Add(element);
+ _preEditors[i].OnInspectorGUI();
}
- }
-
- if (!_overrideDefault)
- {
- InspectorElement.FillDefaultInspector(container, serializedObject, this);
- }
- for (var i = 0; i < _postEditors.Count; i++)
- {
- var element = _postEditors[i].CreateInspectorGUI();
- if (element != null)
+ if (!_overrideDefault)
{
- container.Add(element);
+ base.OnInspectorGUI();
}
- }
- container.TrackSerializedObjectValue(serializedObject, OnSerializedObjectTrack);
- return container;
- }
+ for (var i = 0; i < _postEditors.Count; i++)
+ {
+ _postEditors[i].OnInspectorGUI();
+ }
- private void OnSerializedObjectTrack(SerializedObject serializedObject)
- {
- for (var i = 0; i < _preEditors.Count; i++)
- {
- _preEditors[i].OnChanged(serializedObject);
- }
+ if (!change.changed) return;
+ for (var i = 0; i < _preEditors.Count; i++)
+ {
+ _preEditors[i].OnChanged();
+ }
- for (var i = 0; i < _postEditors.Count; i++)
- {
- _postEditors[i].OnChanged(serializedObject);
+ for (var i = 0; i < _postEditors.Count; i++)
+ {
+ _postEditors[i].OnChanged();
+ }
}
}
diff --git a/Editor/Drawers/Base/FieldDrawer.cs b/Editor/Drawers/Base/FieldDrawer.cs
index 87f72a8..a8b68ed 100644
--- a/Editor/Drawers/Base/FieldDrawer.cs
+++ b/Editor/Drawers/Base/FieldDrawer.cs
@@ -10,19 +10,92 @@ public abstract class FieldDrawer
{
protected readonly FieldInfo _fieldInfo;
protected readonly MultiPropertyAttribute _attribute;
+ protected FieldDrawer _nextDrawer;
protected FieldDrawer(FieldInfo fieldInfo, MultiPropertyAttribute attribute)
{
+ Selection.selectionChanged += OnSelectionChanged;
_fieldInfo = fieldInfo;
_attribute = attribute;
}
- public virtual void Initialize()
+ ~FieldDrawer()
{
+ EditorApplication.update += DeconstructOnMainThread;
}
- protected internal abstract void Deconstruct();
+ public virtual void Initialize(FieldDrawer drawer)
+ {
+ _nextDrawer = drawer;
+ }
+
+ private void DeconstructOnMainThread()
+ {
+ EditorApplication.update -= DeconstructOnMainThread;
+ Selection.selectionChanged -= OnSelectionChanged;
+ Deconstruct();
+ }
+
+ private void OnSelectionChanged()
+ {
+ Selection.selectionChanged -= OnSelectionChanged;
+ Deconstruct();
+ }
+
+ protected abstract void Deconstruct();
+
+ protected virtual void DrawField(Rect position, SerializedProperty property, GUIContent label)
+ {
+ var buffer = PreparePropertyRect(position);
+ EditorGUI.PropertyField(buffer, property, label, true);
+ }
+
+ internal void DrawFieldInternal(Rect position, SerializedProperty property, GUIContent label)
+ {
+ if (_nextDrawer != null)
+ {
+ _nextDrawer.DrawFieldInternal(position, property, label);
+ return;
+ }
+
+ DrawField(position, property, label);
+ }
+
+ internal bool PreDrawInternal(ref Rect position, SerializedProperty property, GUIContent label)
+ {
+ if (_nextDrawer != null)
+ {
+ return PreDraw(ref position, property, label) && _nextDrawer.PreDrawInternal(ref position, property, label);
+ }
+
+ return PreDraw(ref position, property, label);
+ }
+
+ internal void PostDrawInternal(Rect position, SerializedProperty property, GUIContent label)
+ {
+ _nextDrawer?.PostDrawInternal(position, property, label);
+ PostDraw(position, property, label);
+ }
- protected internal abstract void PopulateContainer(ElementsContainer container);
+ internal HeightCacheValue GetPropertyHeightInternal(SerializedProperty property, GUIContent label)
+ {
+ var propertyHeight = GetPropertyHeight(property, label);
+ if (_nextDrawer != null)
+ {
+ var heightInternal = _nextDrawer.GetPropertyHeightInternal(property, label);
+ return propertyHeight + heightInternal;
+ }
+
+ 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 HeightCacheValue GetPropertyHeight(SerializedProperty property, GUIContent label)
+ {
+ return HeightCacheValue.GetFull(EditorGUI.GetPropertyHeight(property, label, true));
+ }
}
}
\ No newline at end of file
diff --git a/Editor/Drawers/Base/MultiFieldDrawer.cs b/Editor/Drawers/Base/MultiFieldDrawer.cs
index d160a40..46fa4ed 100644
--- a/Editor/Drawers/Base/MultiFieldDrawer.cs
+++ b/Editor/Drawers/Base/MultiFieldDrawer.cs
@@ -9,13 +9,13 @@
namespace Better.Commons.EditorAddons.Drawers.Base
{
- public abstract class MultiFieldDrawer : FieldDrawer where T : SerializedPropertyHandler
+ public abstract class MultiFieldDrawer : FieldDrawer where T : UtilityWrapper
{
private static readonly CacheValue CacheValueField = new CacheValue();
- protected HandlerCollection _handlers;
+ protected WrapperCollection _wrappers;
- protected class CacheValue : CacheValue>
+ protected class CacheValue : CacheValue>
{
}
@@ -24,20 +24,20 @@ protected MultiFieldDrawer(FieldInfo fieldInfo, MultiPropertyAttribute attribute
}
///
- /// Method generates explicit typed collection inherited from
+ /// Method generates explicit typed collection inherited from
///
///
- protected abstract HandlerCollection GenerateCollection();
+ protected abstract WrapperCollection GenerateCollection();
- public override void Initialize()
+ public override void Initialize(FieldDrawer drawer)
{
- base.Initialize();
- _handlers = GenerateCollection();
+ base.Initialize(drawer);
+ _wrappers = GenerateCollection();
}
- protected internal override void Deconstruct()
+ protected override void Deconstruct()
{
- _handlers?.Deconstruct();
+ _wrappers.Deconstruct();
}
protected virtual Type GetFieldOrElementType()
@@ -50,16 +50,16 @@ protected virtual Type GetFieldOrElementType()
}
///
- /// Validates if contains property by
+ /// Validates if contains property by
///
- /// SerializedProperty what will be stored into
- /// used to validate current stored wrappers and gets instance for recently added property
+ /// SerializedProperty what will be stored into
+ /// used to validate current stored wrappers and gets instance for recently added property
///
- /// Returns true if wrapper for was already stored into
- protected CacheValue ValidateCachedProperties(SerializedProperty property, HandlerMap handler)
- where THandler : HandlerMap, new()
+ /// Returns true if wrapper for was already stored into
+ protected CacheValue ValidateCachedProperties(SerializedProperty property, BaseUtility handler)
+ where THandler : new()
{
- ValidateCachedPropertiesUtility.Validate(_handlers, CacheValueField, property, GetFieldOrElementType(), _attribute.GetType(), handler);
+ ValidateCachedPropertiesUtility.Validate(_wrappers, CacheValueField, property, GetFieldOrElementType(), _attribute.GetType(), handler);
return CacheValueField;
}
}
diff --git a/Editor/Drawers/Base/HandlerCollection.cs b/Editor/Drawers/Base/WrapperCollection.cs
similarity index 72%
rename from Editor/Drawers/Base/HandlerCollection.cs
rename to Editor/Drawers/Base/WrapperCollection.cs
index 452bcbc..bc4a76f 100644
--- a/Editor/Drawers/Base/HandlerCollection.cs
+++ b/Editor/Drawers/Base/WrapperCollection.cs
@@ -5,10 +5,10 @@
namespace Better.Commons.EditorAddons.Drawers.Base
{
- public class HandlerCollection : Dictionary>
- where T : SerializedPropertyHandler
+ public class WrapperCollection : Dictionary>
+ where T : UtilityWrapper
{
- public HandlerCollection() : base(SerializedPropertyComparer.Instance)
+ public WrapperCollection() : base(SerializedPropertyComparer.Instance)
{
}
diff --git a/Editor/Drawers/Base/HandlerCollection.cs.meta b/Editor/Drawers/Base/WrapperCollection.cs.meta
similarity index 100%
rename from Editor/Drawers/Base/HandlerCollection.cs.meta
rename to Editor/Drawers/Base/WrapperCollection.cs.meta
diff --git a/Editor/Drawers/Base/CollectionValue.cs b/Editor/Drawers/Base/WrapperCollectionValue.cs
similarity index 68%
rename from Editor/Drawers/Base/CollectionValue.cs
rename to Editor/Drawers/Base/WrapperCollectionValue.cs
index 8857390..94f35d3 100644
--- a/Editor/Drawers/Base/CollectionValue.cs
+++ b/Editor/Drawers/Base/WrapperCollectionValue.cs
@@ -3,9 +3,9 @@
namespace Better.Commons.EditorAddons.Drawers.Base
{
- public class CollectionValue where T : SerializedPropertyHandler
+ public class WrapperCollectionValue where T : UtilityWrapper
{
- public CollectionValue(T wrapper, Type type)
+ public WrapperCollectionValue(T wrapper, Type type)
{
Wrapper = wrapper;
Type = type;
diff --git a/Editor/Drawers/Base/CollectionValue.cs.meta b/Editor/Drawers/Base/WrapperCollectionValue.cs.meta
similarity index 100%
rename from Editor/Drawers/Base/CollectionValue.cs.meta
rename to Editor/Drawers/Base/WrapperCollectionValue.cs.meta
diff --git a/Editor/Drawers/BasePropertyDrawer.cs b/Editor/Drawers/BasePropertyDrawer.cs
deleted file mode 100644
index 2dcd808..0000000
--- a/Editor/Drawers/BasePropertyDrawer.cs
+++ /dev/null
@@ -1,100 +0,0 @@
-using System;
-using System.Reflection;
-using Better.Commons.EditorAddons.Drawers.Base;
-using Better.Commons.EditorAddons.Drawers.Caching;
-using Better.Commons.EditorAddons.Drawers.Utility;
-using Better.Commons.Runtime.Drawers.Attributes;
-using Better.Commons.Runtime.Extensions;
-using UnityEditor;
-using UnityEditor.UIElements;
-using UnityEngine.UIElements;
-
-namespace Better.Commons.EditorAddons.Drawers
-{
- public abstract class BasePropertyDrawer : PropertyDrawer where T : SerializedPropertyHandler
- {
- protected FieldInfo _fieldInfo => fieldInfo;
- protected MultiPropertyAttribute _attribute => (MultiPropertyAttribute)attribute;
- private static readonly CacheValue CacheValueField = new CacheValue();
-
- protected HandlerCollection _handlers;
-
- protected class CacheValue : CacheValue>
- {
- }
-
- protected BasePropertyDrawer()
- {
- Selection.selectionChanged += OnSelectionChanged;
- }
-
- ~BasePropertyDrawer()
- {
- EditorApplication.update += DeconstructOnMainThread;
- }
-
- public override VisualElement CreatePropertyGUI(SerializedProperty property)
- {
- var container = new ElementsContainer(property);
- var propertyField = new PropertyField(property);
- propertyField.style.FlexGrow(new StyleFloat(1));
- var defaultElement = container.CreateElementFrom(propertyField);
- defaultElement.AddTag(typeof(PropertyDrawer));
- defaultElement.AddTag(property);
-
- _handlers = GenerateCollection();
- PopulateContainer(container);
-
- return container.Generate();
- }
-
- ///
- /// Method generates explicit typed collection inherited from
- ///
- ///
- protected abstract HandlerCollection GenerateCollection();
-
- protected abstract void PopulateContainer(ElementsContainer container);
-
- private void DeconstructOnMainThread()
- {
- EditorApplication.update -= DeconstructOnMainThread;
- Selection.selectionChanged -= OnSelectionChanged;
- Deconstruct();
- }
-
- private void OnSelectionChanged()
- {
- Selection.selectionChanged -= OnSelectionChanged;
- Deconstruct();
- }
-
- protected virtual Type GetFieldOrElementType()
- {
- var fieldType = _fieldInfo.FieldType;
- if (fieldType.IsArrayOrList())
- return fieldType.GetCollectionElementType();
-
- return fieldType;
- }
-
- ///
- /// Validates if contains property by
- ///
- /// SerializedProperty what will be stored into
- /// used to validate current stored wrappers and gets instance for recently added property
- ///
- /// Returns true if wrapper for was already stored into
- protected CacheValue ValidateCachedProperties(SerializedProperty property, HandlerMap handler)
- where THandler : HandlerMap, new()
- {
- ValidateCachedPropertiesUtility.Validate(_handlers, CacheValueField, property, GetFieldOrElementType(), _attribute.GetType(), handler);
- return CacheValueField;
- }
-
- protected virtual void Deconstruct()
- {
- _handlers?.Deconstruct();
- }
- }
-}
\ No newline at end of file
diff --git a/Editor/Drawers/BasePropertyDrawer.cs.meta b/Editor/Drawers/BasePropertyDrawer.cs.meta
deleted file mode 100644
index ecea6f7..0000000
--- a/Editor/Drawers/BasePropertyDrawer.cs.meta
+++ /dev/null
@@ -1,3 +0,0 @@
-fileFormatVersion: 2
-guid: bbb270479ba84bb8bcfca7d8ae9f13d6
-timeCreated: 1716417021
\ No newline at end of file
diff --git a/Editor/Drawers/Caching/ValidateCachedPropertiesUtility.cs b/Editor/Drawers/Caching/ValidateCachedPropertiesUtility.cs
index af3a5e1..9230867 100644
--- a/Editor/Drawers/Caching/ValidateCachedPropertiesUtility.cs
+++ b/Editor/Drawers/Caching/ValidateCachedPropertiesUtility.cs
@@ -8,10 +8,10 @@ namespace Better.Commons.EditorAddons.Drawers.Caching
{
public static class ValidateCachedPropertiesUtility
{
- public static void Validate(HandlerCollection handlers, TCache cache, SerializedProperty property, Type fieldType,
- Type attributeType, HandlerMap handler) where TCache : CacheValue>
- where TWrapper : SerializedPropertyHandler
- where THandler :HandlerMap, new()
+ 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)
{
@@ -19,9 +19,9 @@ public static void Validate(HandlerCollection(nameof(handlers));
+ DebugUtility.LogException(nameof(wrappers));
cache.Set(false, null);
return;
}
@@ -54,22 +54,22 @@ public static void Validate(HandlerCollection(fieldType, attributeType);
+ var wrapper = handler.GetUtilityWrapper(fieldType, attributeType);
if (wrapper == null)
{
cache.Set(false, null);
return;
}
- var collectionValue = new CollectionValue(wrapper, fieldType);
- handlers.Add(property, collectionValue);
+ var collectionValue = new WrapperCollectionValue(wrapper, fieldType);
+ wrappers.Add(property, collectionValue);
cache.Set(false, collectionValue);
}
}
diff --git a/Editor/Drawers/ElementsContainer.cs b/Editor/Drawers/ElementsContainer.cs
deleted file mode 100644
index efdb56b..0000000
--- a/Editor/Drawers/ElementsContainer.cs
+++ /dev/null
@@ -1,98 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Better.Commons.EditorAddons.Utility;
-using Better.Commons.Runtime.Utility;
-using UnityEditor;
-using UnityEditor.UIElements;
-using UnityEngine.UIElements;
-
-namespace Better.Commons.EditorAddons.Drawers
-{
- public class ElementsContainer
- {
- public SerializedProperty Property { get; }
- public SerializedObject Object => Property.serializedObject;
- private List _elements;
- private VisualElement _container;
-
- public IStyle ContainerStyle => _container.style;
- public event Action OnSerializedObjectChanged;
-
- public ElementsContainer(SerializedProperty property)
- {
- Property = property;
- _elements = new List();
- _container = new VisualElement();
- var classStyle = StyleDefinition.AddSubState(StyleDefinition.BetterPropertyClass, nameof(ElementsContainer));
- _container.AddToClassList(classStyle);
- _container.TrackSerializedObjectValue(Object, Callback);
- }
-
- public FieldVisualElement CreateElementFrom(VisualElement element)
- {
- var item = new FieldVisualElement(element);
- _elements.Add(item);
- return item;
- }
-
- public void SetEnabled(bool value)
- {
- _container.SetEnabled(value);
- }
-
- public FieldVisualElement CreateElement()
- {
- var item = new FieldVisualElement();
- _elements.Add(item);
- return item;
- }
-
- public FieldVisualElement GetByTag(object tag)
- {
- if (TryGetByTag(tag, out var fieldVisualElement))
- {
- return fieldVisualElement;
- }
-
- throw new KeyNotFoundException($"Element with tag: {tag} not found");
- }
-
- public IEnumerable GetByTags(IEnumerable