diff --git a/Editor/EditorAddons/Comparers.meta b/Editor/Comparers.meta similarity index 100% rename from Editor/EditorAddons/Comparers.meta rename to Editor/Comparers.meta diff --git a/Editor/EditorAddons/Comparers/AnyTypeComparer.cs b/Editor/Comparers/AnyTypeComparer.cs similarity index 100% rename from Editor/EditorAddons/Comparers/AnyTypeComparer.cs rename to Editor/Comparers/AnyTypeComparer.cs diff --git a/Editor/EditorAddons/Comparers/AnyTypeComparer.cs.meta b/Editor/Comparers/AnyTypeComparer.cs.meta similarity index 100% rename from Editor/EditorAddons/Comparers/AnyTypeComparer.cs.meta rename to Editor/Comparers/AnyTypeComparer.cs.meta diff --git a/Editor/EditorAddons/CustomEditors.meta b/Editor/CustomEditors.meta similarity index 100% rename from Editor/EditorAddons/CustomEditors.meta rename to Editor/CustomEditors.meta diff --git a/Editor/CustomEditors/ButtonsEditor.cs b/Editor/CustomEditors/ButtonsEditor.cs new file mode 100644 index 0000000..c227eba --- /dev/null +++ b/Editor/CustomEditors/ButtonsEditor.cs @@ -0,0 +1,36 @@ +using Better.Attributes.EditorAddons.Drawers.EditorButton; +using Better.Commons.EditorAddons.CustomEditors.Attributes; +using Better.Commons.EditorAddons.CustomEditors.Base; +using UnityEditor; +using UnityEngine.UIElements; +using Object = UnityEngine.Object; + +namespace Better.Attributes.EditorAddons.CustomEditors +{ + [MultiEditor(typeof(Object), true, Order = 999)] + public class ButtonsEditor : ExtendedEditor + { + public ButtonsEditor(Object target, SerializedObject serializedObject) : base(target, serializedObject) + { + } + + public override void OnDisable() + { + } + + public override void OnEnable() + { + } + + public override VisualElement CreateInspectorGUI() + { + var container = new EditorButtonDrawer(_serializedObject); + container.CreateFromTarget(_target); + return container; + } + + public override void OnChanged(SerializedObject serializedObject) + { + } + } +} \ No newline at end of file diff --git a/Editor/EditorAddons/CustomEditors/ButtonsEditor.cs.meta b/Editor/CustomEditors/ButtonsEditor.cs.meta similarity index 100% rename from Editor/EditorAddons/CustomEditors/ButtonsEditor.cs.meta rename to Editor/CustomEditors/ButtonsEditor.cs.meta diff --git a/Editor/EditorAddons/CustomEditors/GizmosEditor.cs b/Editor/CustomEditors/GizmosEditor.cs similarity index 100% rename from Editor/EditorAddons/CustomEditors/GizmosEditor.cs rename to Editor/CustomEditors/GizmosEditor.cs diff --git a/Editor/EditorAddons/CustomEditors/GizmosEditor.cs.meta b/Editor/CustomEditors/GizmosEditor.cs.meta similarity index 100% rename from Editor/EditorAddons/CustomEditors/GizmosEditor.cs.meta rename to Editor/CustomEditors/GizmosEditor.cs.meta diff --git a/Editor/EditorAddons/Drawers.meta b/Editor/Drawers.meta similarity index 100% rename from Editor/EditorAddons/Drawers.meta rename to Editor/Drawers.meta diff --git a/Editor/EditorAddons/Drawers/Decorators.meta b/Editor/Drawers/Decorators.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Decorators.meta rename to Editor/Drawers/Decorators.meta diff --git a/Editor/EditorAddons/Drawers/Decorators/IconHeaderDrawer.cs b/Editor/Drawers/Decorators/IconHeaderDrawer.cs similarity index 100% rename from Editor/EditorAddons/Drawers/Decorators/IconHeaderDrawer.cs rename to Editor/Drawers/Decorators/IconHeaderDrawer.cs diff --git a/Editor/EditorAddons/Drawers/Decorators/IconHeaderDrawer.cs.meta b/Editor/Drawers/Decorators/IconHeaderDrawer.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Decorators/IconHeaderDrawer.cs.meta rename to Editor/Drawers/Decorators/IconHeaderDrawer.cs.meta diff --git a/Editor/EditorAddons/Drawers/Decorators/PrefabHeaderDrawer.cs b/Editor/Drawers/Decorators/PrefabHeaderDrawer.cs similarity index 100% rename from Editor/EditorAddons/Drawers/Decorators/PrefabHeaderDrawer.cs rename to Editor/Drawers/Decorators/PrefabHeaderDrawer.cs diff --git a/Editor/EditorAddons/Drawers/Decorators/PrefabHeaderDrawer.cs.meta b/Editor/Drawers/Decorators/PrefabHeaderDrawer.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Decorators/PrefabHeaderDrawer.cs.meta rename to Editor/Drawers/Decorators/PrefabHeaderDrawer.cs.meta diff --git a/Editor/EditorAddons/Drawers/Decorators/ReferencesHeaderDrawer.cs b/Editor/Drawers/Decorators/ReferencesHeaderDrawer.cs similarity index 100% rename from Editor/EditorAddons/Drawers/Decorators/ReferencesHeaderDrawer.cs rename to Editor/Drawers/Decorators/ReferencesHeaderDrawer.cs diff --git a/Editor/EditorAddons/Drawers/Decorators/ReferencesHeaderDrawer.cs.meta b/Editor/Drawers/Decorators/ReferencesHeaderDrawer.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Decorators/ReferencesHeaderDrawer.cs.meta rename to Editor/Drawers/Decorators/ReferencesHeaderDrawer.cs.meta diff --git a/Editor/EditorAddons/Drawers/Decorators/SettingsHeaderDrawer.cs b/Editor/Drawers/Decorators/SettingsHeaderDrawer.cs similarity index 100% rename from Editor/EditorAddons/Drawers/Decorators/SettingsHeaderDrawer.cs rename to Editor/Drawers/Decorators/SettingsHeaderDrawer.cs diff --git a/Editor/EditorAddons/Drawers/Decorators/SettingsHeaderDrawer.cs.meta b/Editor/Drawers/Decorators/SettingsHeaderDrawer.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Decorators/SettingsHeaderDrawer.cs.meta rename to Editor/Drawers/Decorators/SettingsHeaderDrawer.cs.meta diff --git a/Editor/EditorAddons/Drawers/Decorators/StateHeaderDrawer.cs b/Editor/Drawers/Decorators/StateHeaderDrawer.cs similarity index 100% rename from Editor/EditorAddons/Drawers/Decorators/StateHeaderDrawer.cs rename to Editor/Drawers/Decorators/StateHeaderDrawer.cs diff --git a/Editor/EditorAddons/Drawers/Decorators/StateHeaderDrawer.cs.meta b/Editor/Drawers/Decorators/StateHeaderDrawer.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Decorators/StateHeaderDrawer.cs.meta rename to Editor/Drawers/Decorators/StateHeaderDrawer.cs.meta diff --git a/Editor/EditorAddons/Drawers/DrawInspector.meta b/Editor/Drawers/DrawInspector.meta similarity index 100% rename from Editor/EditorAddons/Drawers/DrawInspector.meta rename to Editor/Drawers/DrawInspector.meta diff --git a/Editor/EditorAddons/Drawers/DrawInspector/DrawInspectorDrawer.cs b/Editor/Drawers/DrawInspector/DrawInspectorDrawer.cs similarity index 100% rename from Editor/EditorAddons/Drawers/DrawInspector/DrawInspectorDrawer.cs rename to Editor/Drawers/DrawInspector/DrawInspectorDrawer.cs diff --git a/Editor/EditorAddons/Drawers/DrawInspector/DrawInspectorDrawer.cs.meta b/Editor/Drawers/DrawInspector/DrawInspectorDrawer.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/DrawInspector/DrawInspectorDrawer.cs.meta rename to Editor/Drawers/DrawInspector/DrawInspectorDrawer.cs.meta diff --git a/Editor/EditorAddons/Drawers/DrawInspector/DrawInspectorHandler.cs b/Editor/Drawers/DrawInspector/DrawInspectorHandler.cs similarity index 100% rename from Editor/EditorAddons/Drawers/DrawInspector/DrawInspectorHandler.cs rename to Editor/Drawers/DrawInspector/DrawInspectorHandler.cs diff --git a/Editor/EditorAddons/Drawers/DrawInspector/DrawInspectorHandler.cs.meta b/Editor/Drawers/DrawInspector/DrawInspectorHandler.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/DrawInspector/DrawInspectorHandler.cs.meta rename to Editor/Drawers/DrawInspector/DrawInspectorHandler.cs.meta diff --git a/Editor/Drawers/EditorButton.meta b/Editor/Drawers/EditorButton.meta new file mode 100644 index 0000000..da034b8 --- /dev/null +++ b/Editor/Drawers/EditorButton.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 0d9eaab591d5423dbfb40e8059a86f61 +timeCreated: 1728247401 \ No newline at end of file diff --git a/Editor/Drawers/EditorButton/EditorButtonDrawer.cs b/Editor/Drawers/EditorButton/EditorButtonDrawer.cs new file mode 100644 index 0000000..4297424 --- /dev/null +++ b/Editor/Drawers/EditorButton/EditorButtonDrawer.cs @@ -0,0 +1,172 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using Better.Attributes.EditorAddons.Drawers.Parameters; +using Better.Attributes.EditorAddons.Utilities; +using Better.Attributes.Runtime; +using Better.Commons.EditorAddons.Enums; +using Better.Commons.EditorAddons.Extensions; +using Better.Commons.EditorAddons.Utility; +using Better.Commons.Runtime.Extensions; +using Better.Commons.Runtime.UIElements; +using Better.Commons.Runtime.Utility; +using UnityEditor; +using UnityEngine.UIElements; + +namespace Better.Attributes.EditorAddons.Drawers.EditorButton +{ + public class EditorButtonDrawer : VisualElement + { + private readonly SerializedObject _serializedObject; + private Dictionary>> _buttons; + private object _target; + + public EditorButtonDrawer(SerializedObject serializedObject) + { + _serializedObject = serializedObject; + } + + public void CreateFromTarget(object target) + { + if (target == null) + { + DebugUtility.LogException(nameof(target)); + return; + } + + _target = target; + Clear(); + var type = _target.GetType(); + Add(type); + } + + private void Add(Type targetType) + { + var methodAttributes = EditorButtonUtility.GetSortedMethodAttributes(targetType); + foreach (var (captureGroup, keyValuePairs) in methodAttributes) + { + if (captureGroup == -1) + { + var grouped = keyValuePairs.GroupBy(key => key.Key, pair => pair.Value, (methodInfo, attributes) => (methodInfo, attributes)); + var verticalElement = VisualElementUtility.CreateVerticalGroup(); + Add(verticalElement); + + foreach (var group in grouped) + { + var horizontalElement = VisualElementUtility.CreateHorizontalGroup(); + verticalElement.Add(horizontalElement); + + foreach (var attribute in group.attributes) + { + var visualElement = CreateFromMethodInfo(group.methodInfo, attribute); + horizontalElement.Add(visualElement); + } + } + } + else + { + var horizontalElement = VisualElementUtility.CreateHorizontalGroup(); + Add(horizontalElement); + foreach (var (key, value) in keyValuePairs) + { + var visualElement = CreateFromMethodInfo(key, value); + horizontalElement.Add(visualElement); + } + } + } + } + + private VisualElement CreateFromMethodInfo(MethodInfo methodInfo, EditorButtonAttribute attribute) + { + var parameters = methodInfo.GetParameters(); + foreach (var parameterInfo in parameters) + { + if (!ParameterFieldProvider.IsSupported(parameterInfo.ParameterType) || parameterInfo.IsOut) + { + return CreateNotSupportedHelpBox(methodInfo, parameterInfo); + } + } + + return CreateButton(methodInfo, attribute); + } + + private static HelpBox CreateNotSupportedHelpBox(MethodInfo methodInfo, ParameterInfo parameterInfo) + { + string message; + if (parameterInfo.IsOut) + { + message = $"Parameter({parameterInfo.Name}) with \"out\" modificator in {methodInfo.Name} not supported"; + } + else + { + message = $"Parameter({parameterInfo.Name}) with type {parameterInfo.ParameterType} in {methodInfo.Name} not supported"; + } + + var helpBox = VisualElementUtility.HelpBox(message, HelpBoxMessageType.Error); + helpBox.style.FlexGrow(StyleDefinition.OneStyleFloat); + return helpBox; + } + + private VisualElement CreateButton(MethodInfo methodInfo, EditorButtonAttribute attribute) + { + var prettyMemberName = methodInfo.PrettyMemberName(); + + var verticalGroup = VisualElementUtility.CreateVerticalGroup(); + verticalGroup.name = $"{prettyMemberName}__{nameof(verticalGroup)}"; + verticalGroup.style + .FlexGrow(StyleDefinition.OneStyleFloat) + .FlexBasis(0.5f); + + var horizontalGroup = VisualElementUtility.CreateHorizontalGroup(); + horizontalGroup.name = $"{prettyMemberName}__{nameof(horizontalGroup)}"; + horizontalGroup.style + .FlexGrow(StyleDefinition.OneStyleFloat) + .MaxHeight(StyleDefinition.ButtonHeight); + + verticalGroup.Add(horizontalGroup); + + var button = new Button + { + text = attribute.GetDisplayName(prettyMemberName), + name = prettyMemberName + }; + + var parameters = methodInfo.GetParameters(); + var datas = parameters.Select(info => new Parameter(info)).ToArray(); + + var parametersElement = new ParametersElementDrawer(datas); + verticalGroup.Add(parametersElement); + + if (!datas.IsNullOrEmpty()) + { + var toggle = new ToggleButton(value => parametersElement.style.SetVisible(value)); + toggle.AddIcon(IconType.GrayDropdown); + toggle.style.Padding(1f); + + toggle.text = string.Empty; + horizontalGroup.Add(toggle); + } + else + { + parametersElement.style.SetVisible(false); + } + + horizontalGroup.Add(button); + button.style.FlexGrow(StyleDefinition.OneStyleFloat); + button.RegisterCallback(OnClick, methodInfo, parametersElement); + return verticalGroup; + } + + private void OnClick(ClickEvent clickEvent, (MethodInfo methodInfo, ParametersElementDrawer parameters) data) + { + _serializedObject.Update(); + var parameters = data.parameters; + + //TODO: Validate parameters count and types + data.methodInfo.Invoke(_target, parameters.GetData()); + EditorUtility.SetDirty(_serializedObject.targetObject); + _serializedObject.ApplyModifiedProperties(); + } + } +} \ No newline at end of file diff --git a/Editor/Drawers/EditorButton/EditorButtonDrawer.cs.meta b/Editor/Drawers/EditorButton/EditorButtonDrawer.cs.meta new file mode 100644 index 0000000..1bc5b37 --- /dev/null +++ b/Editor/Drawers/EditorButton/EditorButtonDrawer.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 176e86a484d24f3e9ecdd19cec2d7b62 +timeCreated: 1725671015 \ No newline at end of file diff --git a/Editor/EditorAddons/Drawers/Gizmo.meta b/Editor/Drawers/Gizmo.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Gizmo.meta rename to Editor/Drawers/Gizmo.meta diff --git a/Editor/EditorAddons/Drawers/Gizmo/BaseHandlers.meta b/Editor/Drawers/Gizmo/BaseHandlers.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Gizmo/BaseHandlers.meta rename to Editor/Drawers/Gizmo/BaseHandlers.meta diff --git a/Editor/EditorAddons/Drawers/Gizmo/BaseHandlers/BoundsBaseHandler.cs b/Editor/Drawers/Gizmo/BaseHandlers/BoundsBaseHandler.cs similarity index 100% rename from Editor/EditorAddons/Drawers/Gizmo/BaseHandlers/BoundsBaseHandler.cs rename to Editor/Drawers/Gizmo/BaseHandlers/BoundsBaseHandler.cs diff --git a/Editor/EditorAddons/Drawers/Gizmo/BaseHandlers/BoundsBaseHandler.cs.meta b/Editor/Drawers/Gizmo/BaseHandlers/BoundsBaseHandler.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Gizmo/BaseHandlers/BoundsBaseHandler.cs.meta rename to Editor/Drawers/Gizmo/BaseHandlers/BoundsBaseHandler.cs.meta diff --git a/Editor/EditorAddons/Drawers/Gizmo/BaseHandlers/GizmoHandler.cs b/Editor/Drawers/Gizmo/BaseHandlers/GizmoHandler.cs similarity index 74% rename from Editor/EditorAddons/Drawers/Gizmo/BaseHandlers/GizmoHandler.cs rename to Editor/Drawers/Gizmo/BaseHandlers/GizmoHandler.cs index d758855..0546e26 100644 --- a/Editor/EditorAddons/Drawers/Gizmo/BaseHandlers/GizmoHandler.cs +++ b/Editor/Drawers/Gizmo/BaseHandlers/GizmoHandler.cs @@ -29,17 +29,12 @@ public virtual void SetProperty(SerializedProperty property, Type fieldType) private string GetCompiledName() { - if (Validate()) + if (_serializedProperty.IsArrayElement()) { - if (_serializedProperty.IsArrayElement()) - { - return $"{ObjectNames.NicifyVariableName(_serializedProperty.GetArrayPath())}"; - } - - return _serializedProperty.displayName; + return $"{ObjectNames.NicifyVariableName(_serializedProperty.GetArrayPath())}"; } - return string.Empty; + return _serializedProperty.displayName; } public void SetMode(bool value) @@ -59,40 +54,8 @@ public override void Deconstruct() _serializedProperty = null; } - public virtual bool Validate() - { - try - { - if (_serializedProperty == null) - { - return false; - } - - if (!_serializedProperty.Verify()) - { - return false; - } - - if (_serializedProperty.IsDisposed()) - { - return false; - } - - return _serializedProperty.serializedObject.targetObject != null; - } - catch - { - return false; - } - } - private protected void SetValueAndApply(object value) { - if (!Validate()) - { - return; - } - if (_fieldType.IsEquivalentTo(typeof(Vector2))) _serializedProperty.vector2Value = (Vector2)value; else if (_fieldType.IsEquivalentTo(typeof(Vector3))) diff --git a/Editor/EditorAddons/Drawers/Gizmo/BaseHandlers/GizmoHandler.cs.meta b/Editor/Drawers/Gizmo/BaseHandlers/GizmoHandler.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Gizmo/BaseHandlers/GizmoHandler.cs.meta rename to Editor/Drawers/Gizmo/BaseHandlers/GizmoHandler.cs.meta diff --git a/Editor/EditorAddons/Drawers/Gizmo/GizmoDrawer.cs b/Editor/Drawers/Gizmo/GizmoDrawer.cs similarity index 81% rename from Editor/EditorAddons/Drawers/Gizmo/GizmoDrawer.cs rename to Editor/Drawers/Gizmo/GizmoDrawer.cs index cf13697..6d6afb1 100644 --- a/Editor/EditorAddons/Drawers/Gizmo/GizmoDrawer.cs +++ b/Editor/Drawers/Gizmo/GizmoDrawer.cs @@ -36,44 +36,25 @@ private void OnSceneGUIDelegate(SceneView sceneView) { if (sceneView.drawGizmos) { - ValidationUtility.ValidateCachedProperties(Handlers); + Handlers?.Revalidate(); Apply(sceneView); } } private void Apply(SceneView sceneView) { - List keysToRemove = null; + Handlers.Revalidate(); + foreach (var gizmo in Handlers) { var valueWrapper = gizmo.Value.Handler; - if (valueWrapper.Validate()) - { - valueWrapper.Apply(sceneView); - } - else - { - if (keysToRemove == null) - { - keysToRemove = new List(); - } - - keysToRemove.Add(gizmo.Key); - } - } - - if (keysToRemove != null) - { - foreach (var property in keysToRemove) - { - Handlers.Remove(property); - } + valueWrapper.Apply(sceneView); } } - protected override void Deconstruct() + protected override void ContainerReleased(ElementsContainer container) { - base.Deconstruct(); + base.ContainerReleased(container); SceneView.duringSceneGui -= OnSceneGUIDelegate; } diff --git a/Editor/EditorAddons/Drawers/Gizmo/GizmoDrawer.cs.meta b/Editor/Drawers/Gizmo/GizmoDrawer.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Gizmo/GizmoDrawer.cs.meta rename to Editor/Drawers/Gizmo/GizmoDrawer.cs.meta diff --git a/Editor/EditorAddons/Drawers/Gizmo/GizmoElementBehaviour.cs b/Editor/Drawers/Gizmo/GizmoElementBehaviour.cs similarity index 100% rename from Editor/EditorAddons/Drawers/Gizmo/GizmoElementBehaviour.cs rename to Editor/Drawers/Gizmo/GizmoElementBehaviour.cs diff --git a/Editor/EditorAddons/Drawers/Gizmo/GizmoElementBehaviour.cs.meta b/Editor/Drawers/Gizmo/GizmoElementBehaviour.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Gizmo/GizmoElementBehaviour.cs.meta rename to Editor/Drawers/Gizmo/GizmoElementBehaviour.cs.meta diff --git a/Editor/EditorAddons/Drawers/Gizmo/HideTransformDrawer.cs b/Editor/Drawers/Gizmo/HideTransformDrawer.cs similarity index 100% rename from Editor/EditorAddons/Drawers/Gizmo/HideTransformDrawer.cs rename to Editor/Drawers/Gizmo/HideTransformDrawer.cs diff --git a/Editor/EditorAddons/Drawers/Gizmo/HideTransformDrawer.cs.meta b/Editor/Drawers/Gizmo/HideTransformDrawer.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Gizmo/HideTransformDrawer.cs.meta rename to Editor/Drawers/Gizmo/HideTransformDrawer.cs.meta diff --git a/Editor/EditorAddons/Drawers/Gizmo/LocalHandlers.meta b/Editor/Drawers/Gizmo/LocalHandlers.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Gizmo/LocalHandlers.meta rename to Editor/Drawers/Gizmo/LocalHandlers.meta diff --git a/Editor/EditorAddons/Drawers/Gizmo/LocalHandlers/BoundsLocalHandler.cs b/Editor/Drawers/Gizmo/LocalHandlers/BoundsLocalHandler.cs similarity index 100% rename from Editor/EditorAddons/Drawers/Gizmo/LocalHandlers/BoundsLocalHandler.cs rename to Editor/Drawers/Gizmo/LocalHandlers/BoundsLocalHandler.cs diff --git a/Editor/EditorAddons/Drawers/Gizmo/LocalHandlers/BoundsLocalHandler.cs.meta b/Editor/Drawers/Gizmo/LocalHandlers/BoundsLocalHandler.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Gizmo/LocalHandlers/BoundsLocalHandler.cs.meta rename to Editor/Drawers/Gizmo/LocalHandlers/BoundsLocalHandler.cs.meta diff --git a/Editor/EditorAddons/Drawers/Gizmo/LocalHandlers/QuaternionLocalHandler.cs b/Editor/Drawers/Gizmo/LocalHandlers/QuaternionLocalHandler.cs similarity index 100% rename from Editor/EditorAddons/Drawers/Gizmo/LocalHandlers/QuaternionLocalHandler.cs rename to Editor/Drawers/Gizmo/LocalHandlers/QuaternionLocalHandler.cs diff --git a/Editor/EditorAddons/Drawers/Gizmo/LocalHandlers/QuaternionLocalHandler.cs.meta b/Editor/Drawers/Gizmo/LocalHandlers/QuaternionLocalHandler.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Gizmo/LocalHandlers/QuaternionLocalHandler.cs.meta rename to Editor/Drawers/Gizmo/LocalHandlers/QuaternionLocalHandler.cs.meta diff --git a/Editor/EditorAddons/Drawers/Gizmo/LocalHandlers/Vector2LocalHandler.cs b/Editor/Drawers/Gizmo/LocalHandlers/Vector2LocalHandler.cs similarity index 100% rename from Editor/EditorAddons/Drawers/Gizmo/LocalHandlers/Vector2LocalHandler.cs rename to Editor/Drawers/Gizmo/LocalHandlers/Vector2LocalHandler.cs diff --git a/Editor/EditorAddons/Drawers/Gizmo/LocalHandlers/Vector2LocalHandler.cs.meta b/Editor/Drawers/Gizmo/LocalHandlers/Vector2LocalHandler.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Gizmo/LocalHandlers/Vector2LocalHandler.cs.meta rename to Editor/Drawers/Gizmo/LocalHandlers/Vector2LocalHandler.cs.meta diff --git a/Editor/EditorAddons/Drawers/Gizmo/LocalHandlers/Vector3LocalHandler.cs b/Editor/Drawers/Gizmo/LocalHandlers/Vector3LocalHandler.cs similarity index 100% rename from Editor/EditorAddons/Drawers/Gizmo/LocalHandlers/Vector3LocalHandler.cs rename to Editor/Drawers/Gizmo/LocalHandlers/Vector3LocalHandler.cs diff --git a/Editor/EditorAddons/Drawers/Gizmo/LocalHandlers/Vector3LocalHandler.cs.meta b/Editor/Drawers/Gizmo/LocalHandlers/Vector3LocalHandler.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Gizmo/LocalHandlers/Vector3LocalHandler.cs.meta rename to Editor/Drawers/Gizmo/LocalHandlers/Vector3LocalHandler.cs.meta diff --git a/Editor/EditorAddons/Drawers/Gizmo/WorldHandlers.meta b/Editor/Drawers/Gizmo/WorldHandlers.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Gizmo/WorldHandlers.meta rename to Editor/Drawers/Gizmo/WorldHandlers.meta diff --git a/Editor/EditorAddons/Drawers/Gizmo/WorldHandlers/BoundsHandler.cs b/Editor/Drawers/Gizmo/WorldHandlers/BoundsHandler.cs similarity index 100% rename from Editor/EditorAddons/Drawers/Gizmo/WorldHandlers/BoundsHandler.cs rename to Editor/Drawers/Gizmo/WorldHandlers/BoundsHandler.cs diff --git a/Editor/EditorAddons/Drawers/Gizmo/WorldHandlers/BoundsHandler.cs.meta b/Editor/Drawers/Gizmo/WorldHandlers/BoundsHandler.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Gizmo/WorldHandlers/BoundsHandler.cs.meta rename to Editor/Drawers/Gizmo/WorldHandlers/BoundsHandler.cs.meta diff --git a/Editor/EditorAddons/Drawers/Gizmo/WorldHandlers/QuaternionHandler.cs b/Editor/Drawers/Gizmo/WorldHandlers/QuaternionHandler.cs similarity index 100% rename from Editor/EditorAddons/Drawers/Gizmo/WorldHandlers/QuaternionHandler.cs rename to Editor/Drawers/Gizmo/WorldHandlers/QuaternionHandler.cs diff --git a/Editor/EditorAddons/Drawers/Gizmo/WorldHandlers/QuaternionHandler.cs.meta b/Editor/Drawers/Gizmo/WorldHandlers/QuaternionHandler.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Gizmo/WorldHandlers/QuaternionHandler.cs.meta rename to Editor/Drawers/Gizmo/WorldHandlers/QuaternionHandler.cs.meta diff --git a/Editor/EditorAddons/Drawers/Gizmo/WorldHandlers/Vector2Handler.cs b/Editor/Drawers/Gizmo/WorldHandlers/Vector2Handler.cs similarity index 100% rename from Editor/EditorAddons/Drawers/Gizmo/WorldHandlers/Vector2Handler.cs rename to Editor/Drawers/Gizmo/WorldHandlers/Vector2Handler.cs diff --git a/Editor/EditorAddons/Drawers/Gizmo/WorldHandlers/Vector2Handler.cs.meta b/Editor/Drawers/Gizmo/WorldHandlers/Vector2Handler.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Gizmo/WorldHandlers/Vector2Handler.cs.meta rename to Editor/Drawers/Gizmo/WorldHandlers/Vector2Handler.cs.meta diff --git a/Editor/EditorAddons/Drawers/Gizmo/WorldHandlers/Vector3Handler.cs b/Editor/Drawers/Gizmo/WorldHandlers/Vector3Handler.cs similarity index 100% rename from Editor/EditorAddons/Drawers/Gizmo/WorldHandlers/Vector3Handler.cs rename to Editor/Drawers/Gizmo/WorldHandlers/Vector3Handler.cs diff --git a/Editor/EditorAddons/Drawers/Gizmo/WorldHandlers/Vector3Handler.cs.meta b/Editor/Drawers/Gizmo/WorldHandlers/Vector3Handler.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Gizmo/WorldHandlers/Vector3Handler.cs.meta rename to Editor/Drawers/Gizmo/WorldHandlers/Vector3Handler.cs.meta diff --git a/Editor/EditorAddons/Drawers/HandlerMaps.meta b/Editor/Drawers/HandlerMaps.meta similarity index 100% rename from Editor/EditorAddons/Drawers/HandlerMaps.meta rename to Editor/Drawers/HandlerMaps.meta diff --git a/Editor/EditorAddons/Drawers/HandlerMaps/DrawInspectorTypeHandlerBinder.cs b/Editor/Drawers/HandlerMaps/DrawInspectorTypeHandlerBinder.cs similarity index 100% rename from Editor/EditorAddons/Drawers/HandlerMaps/DrawInspectorTypeHandlerBinder.cs rename to Editor/Drawers/HandlerMaps/DrawInspectorTypeHandlerBinder.cs diff --git a/Editor/EditorAddons/Drawers/HandlerMaps/DrawInspectorTypeHandlerBinder.cs.meta b/Editor/Drawers/HandlerMaps/DrawInspectorTypeHandlerBinder.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/HandlerMaps/DrawInspectorTypeHandlerBinder.cs.meta rename to Editor/Drawers/HandlerMaps/DrawInspectorTypeHandlerBinder.cs.meta diff --git a/Editor/EditorAddons/Drawers/HandlerMaps/GizmoTypeHandlerBinder.cs b/Editor/Drawers/HandlerMaps/GizmoTypeHandlerBinder.cs similarity index 100% rename from Editor/EditorAddons/Drawers/HandlerMaps/GizmoTypeHandlerBinder.cs rename to Editor/Drawers/HandlerMaps/GizmoTypeHandlerBinder.cs diff --git a/Editor/EditorAddons/Drawers/HandlerMaps/GizmoTypeHandlerBinder.cs.meta b/Editor/Drawers/HandlerMaps/GizmoTypeHandlerBinder.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/HandlerMaps/GizmoTypeHandlerBinder.cs.meta rename to Editor/Drawers/HandlerMaps/GizmoTypeHandlerBinder.cs.meta diff --git a/Editor/EditorAddons/Drawers/HandlerMaps/ManipulateTypeHandlerBinder.cs b/Editor/Drawers/HandlerMaps/ManipulateTypeHandlerBinder.cs similarity index 100% rename from Editor/EditorAddons/Drawers/HandlerMaps/ManipulateTypeHandlerBinder.cs rename to Editor/Drawers/HandlerMaps/ManipulateTypeHandlerBinder.cs diff --git a/Editor/EditorAddons/Drawers/HandlerMaps/ManipulateTypeHandlerBinder.cs.meta b/Editor/Drawers/HandlerMaps/ManipulateTypeHandlerBinder.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/HandlerMaps/ManipulateTypeHandlerBinder.cs.meta rename to Editor/Drawers/HandlerMaps/ManipulateTypeHandlerBinder.cs.meta diff --git a/Editor/EditorAddons/Drawers/HandlerMaps/MiscBinder.cs b/Editor/Drawers/HandlerMaps/MiscBinder.cs similarity index 89% rename from Editor/EditorAddons/Drawers/HandlerMaps/MiscBinder.cs rename to Editor/Drawers/HandlerMaps/MiscBinder.cs index 4e53c94..997b31a 100644 --- a/Editor/EditorAddons/Drawers/HandlerMaps/MiscBinder.cs +++ b/Editor/Drawers/HandlerMaps/MiscBinder.cs @@ -46,6 +46,12 @@ protected override BaseHandlersTypeCollection GenerateCollection() { typeof(Type), typeof(RenameFieldHandler) } } }, + { + typeof(DetailedAttribute), new Dictionary(AnyTypeComparer.Instance) + { + { typeof(Type), typeof(DetailedHandler) } + } + }, }; } diff --git a/Editor/EditorAddons/Drawers/HandlerMaps/MiscBinder.cs.meta b/Editor/Drawers/HandlerMaps/MiscBinder.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/HandlerMaps/MiscBinder.cs.meta rename to Editor/Drawers/HandlerMaps/MiscBinder.cs.meta diff --git a/Editor/EditorAddons/Drawers/HandlerMaps/PreviewTypeHandlerBinder.cs b/Editor/Drawers/HandlerMaps/PreviewTypeHandlerBinder.cs similarity index 100% rename from Editor/EditorAddons/Drawers/HandlerMaps/PreviewTypeHandlerBinder.cs rename to Editor/Drawers/HandlerMaps/PreviewTypeHandlerBinder.cs diff --git a/Editor/EditorAddons/Drawers/HandlerMaps/PreviewTypeHandlerBinder.cs.meta b/Editor/Drawers/HandlerMaps/PreviewTypeHandlerBinder.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/HandlerMaps/PreviewTypeHandlerBinder.cs.meta rename to Editor/Drawers/HandlerMaps/PreviewTypeHandlerBinder.cs.meta diff --git a/Editor/EditorAddons/Drawers/HandlerMaps/SelectTypeHandlerBinder.cs b/Editor/Drawers/HandlerMaps/SelectTypeHandlerBinder.cs similarity index 100% rename from Editor/EditorAddons/Drawers/HandlerMaps/SelectTypeHandlerBinder.cs rename to Editor/Drawers/HandlerMaps/SelectTypeHandlerBinder.cs diff --git a/Editor/EditorAddons/Drawers/HandlerMaps/SelectTypeHandlerBinder.cs.meta b/Editor/Drawers/HandlerMaps/SelectTypeHandlerBinder.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/HandlerMaps/SelectTypeHandlerBinder.cs.meta rename to Editor/Drawers/HandlerMaps/SelectTypeHandlerBinder.cs.meta diff --git a/Editor/EditorAddons/Drawers/Manipulation.meta b/Editor/Drawers/Manipulation.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Manipulation.meta rename to Editor/Drawers/Manipulation.meta diff --git a/Editor/EditorAddons/Drawers/Manipulation/Handlers.meta b/Editor/Drawers/Manipulation/Handlers.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Manipulation/Handlers.meta rename to Editor/Drawers/Manipulation/Handlers.meta diff --git a/Editor/EditorAddons/Drawers/Manipulation/Handlers/InEditorModeHandler.cs b/Editor/Drawers/Manipulation/Handlers/InEditorModeHandler.cs similarity index 100% rename from Editor/EditorAddons/Drawers/Manipulation/Handlers/InEditorModeHandler.cs rename to Editor/Drawers/Manipulation/Handlers/InEditorModeHandler.cs diff --git a/Editor/EditorAddons/Drawers/Manipulation/Handlers/InEditorModeHandler.cs.meta b/Editor/Drawers/Manipulation/Handlers/InEditorModeHandler.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Manipulation/Handlers/InEditorModeHandler.cs.meta rename to Editor/Drawers/Manipulation/Handlers/InEditorModeHandler.cs.meta diff --git a/Editor/EditorAddons/Drawers/Manipulation/Handlers/InPlayModeHandler.cs b/Editor/Drawers/Manipulation/Handlers/InPlayModeHandler.cs similarity index 100% rename from Editor/EditorAddons/Drawers/Manipulation/Handlers/InPlayModeHandler.cs rename to Editor/Drawers/Manipulation/Handlers/InPlayModeHandler.cs diff --git a/Editor/EditorAddons/Drawers/Manipulation/Handlers/InPlayModeHandler.cs.meta b/Editor/Drawers/Manipulation/Handlers/InPlayModeHandler.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Manipulation/Handlers/InPlayModeHandler.cs.meta rename to Editor/Drawers/Manipulation/Handlers/InPlayModeHandler.cs.meta diff --git a/Editor/EditorAddons/Drawers/Manipulation/Handlers/ManipulateHandler.cs b/Editor/Drawers/Manipulation/Handlers/ManipulateHandler.cs similarity index 100% rename from Editor/EditorAddons/Drawers/Manipulation/Handlers/ManipulateHandler.cs rename to Editor/Drawers/Manipulation/Handlers/ManipulateHandler.cs diff --git a/Editor/EditorAddons/Drawers/Manipulation/Handlers/ManipulateHandler.cs.meta b/Editor/Drawers/Manipulation/Handlers/ManipulateHandler.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Manipulation/Handlers/ManipulateHandler.cs.meta rename to Editor/Drawers/Manipulation/Handlers/ManipulateHandler.cs.meta diff --git a/Editor/EditorAddons/Drawers/Manipulation/Handlers/ManipulateUserConditionHandler.cs b/Editor/Drawers/Manipulation/Handlers/ManipulateUserConditionHandler.cs similarity index 59% rename from Editor/EditorAddons/Drawers/Manipulation/Handlers/ManipulateUserConditionHandler.cs rename to Editor/Drawers/Manipulation/Handlers/ManipulateUserConditionHandler.cs index c26c442..23c022f 100644 --- a/Editor/EditorAddons/Drawers/Manipulation/Handlers/ManipulateUserConditionHandler.cs +++ b/Editor/Drawers/Manipulation/Handlers/ManipulateUserConditionHandler.cs @@ -1,6 +1,8 @@ using System; +using System.Reflection; using Better.Attributes.Runtime.Manipulation; using Better.Commons.EditorAddons.Extensions; +using Better.Commons.Runtime.Extensions; using Better.Internal.Core.Runtime; using UnityEditor; @@ -20,26 +22,23 @@ protected override bool IsConditionSatisfied() { if (_container == null) return false; var type = _container.GetType(); - var field = type.GetField(_userAttribute.MemberName, Defines.FieldsFlags); + var memberInfo = type.GetMemberByNameRecursive(_userAttribute.MemberName); var memberValue = _userAttribute.MemberValue; - if (field != null) + if (memberInfo is FieldInfo fieldInfo) { - var value = field.GetValue(_container); + var value = fieldInfo.GetValue(_container); return Equals(memberValue, value); } - var method = type.GetMethod(_userAttribute.MemberName, Defines.MethodFlags); - if (method != null) + if (memberInfo is MethodInfo methodInfo) { - return Equals(memberValue, method.Invoke(_container, Array.Empty())); + return Equals(memberValue, methodInfo.Invoke(_container, Array.Empty())); } - var property = type.GetProperty(_userAttribute.MemberName, Defines.FieldsFlags); - var propertyValue = _userAttribute.MemberValue; - if (property != null) + if (memberInfo is PropertyInfo propertyInfo) { - var value = property.GetValue(_container); - return Equals(memberValue, propertyValue); + var value = propertyInfo.GetValue(_container); + return Equals(memberValue, value); } return false; @@ -49,7 +48,7 @@ public override void SetProperty(SerializedProperty property, ManipulateAttribut { base.SetProperty(property, attribute); _userAttribute = (ManipulateUserConditionAttribute)attribute; - _container = _property.GetLastNonCollectionContainer(); + _container = _property.GetLastNonCollectionParent(); } } } \ No newline at end of file diff --git a/Editor/EditorAddons/Drawers/Manipulation/Handlers/ManipulateUserConditionHandler.cs.meta b/Editor/Drawers/Manipulation/Handlers/ManipulateUserConditionHandler.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Manipulation/Handlers/ManipulateUserConditionHandler.cs.meta rename to Editor/Drawers/Manipulation/Handlers/ManipulateUserConditionHandler.cs.meta diff --git a/Editor/EditorAddons/Drawers/Manipulation/Handlers/ReadOnlyFieldAttributeHandler.cs b/Editor/Drawers/Manipulation/Handlers/ReadOnlyFieldAttributeHandler.cs similarity index 100% rename from Editor/EditorAddons/Drawers/Manipulation/Handlers/ReadOnlyFieldAttributeHandler.cs rename to Editor/Drawers/Manipulation/Handlers/ReadOnlyFieldAttributeHandler.cs diff --git a/Editor/EditorAddons/Drawers/Manipulation/Handlers/ReadOnlyFieldAttributeHandler.cs.meta b/Editor/Drawers/Manipulation/Handlers/ReadOnlyFieldAttributeHandler.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Manipulation/Handlers/ReadOnlyFieldAttributeHandler.cs.meta rename to Editor/Drawers/Manipulation/Handlers/ReadOnlyFieldAttributeHandler.cs.meta diff --git a/Editor/EditorAddons/Drawers/Manipulation/ManipulateDrawer.cs b/Editor/Drawers/Manipulation/ManipulateDrawer.cs similarity index 81% rename from Editor/EditorAddons/Drawers/Manipulation/ManipulateDrawer.cs rename to Editor/Drawers/Manipulation/ManipulateDrawer.cs index e2a2a74..6b93afd 100644 --- a/Editor/EditorAddons/Drawers/Manipulation/ManipulateDrawer.cs +++ b/Editor/Drawers/Manipulation/ManipulateDrawer.cs @@ -21,5 +21,11 @@ private void SerializedObjectChanged(ElementsContainer container) var wrapper = GetHandler(container.SerializedProperty); wrapper.UpdateState(container); } + + protected override void ContainerReleased(ElementsContainer container) + { + base.ContainerReleased(container); + container.SerializedObjectChanged -= SerializedObjectChanged; + } } } \ No newline at end of file diff --git a/Editor/EditorAddons/Drawers/Manipulation/ManipulateDrawer.cs.meta b/Editor/Drawers/Manipulation/ManipulateDrawer.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Manipulation/ManipulateDrawer.cs.meta rename to Editor/Drawers/Manipulation/ManipulateDrawer.cs.meta diff --git a/Editor/EditorAddons/Drawers/Misc.meta b/Editor/Drawers/Misc.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Misc.meta rename to Editor/Drawers/Misc.meta diff --git a/Editor/EditorAddons/Drawers/Misc/Handlers.meta b/Editor/Drawers/Misc/Handlers.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Misc/Handlers.meta rename to Editor/Drawers/Misc/Handlers.meta diff --git a/Editor/EditorAddons/Drawers/Misc/Handlers/CustomToolTipHandler.cs b/Editor/Drawers/Misc/Handlers/CustomToolTipHandler.cs similarity index 94% rename from Editor/EditorAddons/Drawers/Misc/Handlers/CustomToolTipHandler.cs rename to Editor/Drawers/Misc/Handlers/CustomToolTipHandler.cs index c736e03..bc57663 100644 --- a/Editor/EditorAddons/Drawers/Misc/Handlers/CustomToolTipHandler.cs +++ b/Editor/Drawers/Misc/Handlers/CustomToolTipHandler.cs @@ -1,5 +1,6 @@ using Better.Attributes.Runtime; using Better.Attributes.Runtime.Misc; +using Better.Attributes.Runtime.Utilities; using Better.Commons.EditorAddons.Drawers; using Better.Commons.EditorAddons.Helpers; diff --git a/Editor/EditorAddons/Drawers/Misc/Handlers/CustomToolTipHandler.cs.meta b/Editor/Drawers/Misc/Handlers/CustomToolTipHandler.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Misc/Handlers/CustomToolTipHandler.cs.meta rename to Editor/Drawers/Misc/Handlers/CustomToolTipHandler.cs.meta diff --git a/Editor/Drawers/Misc/Handlers/DetailedHandler.cs b/Editor/Drawers/Misc/Handlers/DetailedHandler.cs new file mode 100644 index 0000000..85d814e --- /dev/null +++ b/Editor/Drawers/Misc/Handlers/DetailedHandler.cs @@ -0,0 +1,118 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Reflection; +using Better.Attributes.EditorAddons.CustomEditors; +using Better.Attributes.EditorAddons.Drawers.EditorButton; +using Better.Attributes.Runtime.Misc; +using Better.Commons.EditorAddons.Drawers.Container; +using Better.Commons.EditorAddons.Extensions; +using Better.Commons.EditorAddons.Helpers; +using Better.Commons.EditorAddons.Utility; +using Better.Commons.Runtime.Extensions; +using Better.Commons.Runtime.Utility; +using Better.Internal.Core.Runtime; +using UnityEditor; +using UnityEngine; + +namespace Better.Attributes.EditorAddons.Drawers.Misc +{ + //TODO: add parameters + public class DetailedHandler : MiscHandler + { + private DetailedAttribute _detailedAttribute; + private EditorButtonDrawer _buttonDrawer; + + protected override void OnSetupContainer() + { + _detailedAttribute = (DetailedAttribute)_attribute; + + if (!ValidateNested()) + { + return; + } + + var target = GetValueFromContainer(_container); + + _buttonDrawer = new EditorButtonDrawer(_container.SerializedObject); + _container.CreateElementFrom(_buttonDrawer); + + if (target != null) + { + _buttonDrawer.CreateFromTarget(target); + } + + _container.SerializedPropertyChanged += OnPropertyChanged; + } + + private bool ValidateNested() + { + if (!_detailedAttribute.Nested) + { + return true; + } + + var serializedProperty = _container.SerializedProperty; + var list = new List(); + serializedProperty.CollectPropertyParents(ref list); + + for (var i = list.Count - 1; i >= 0; i--) + { + var valueTuple = list[i]; + var container = valueTuple.ParentInstance; + var fieldName = valueTuple.FieldName; + + if (fieldName.IsNullOrEmpty() || container.GetType().IsEnumerable()) + { + continue; + } + + var field = container.GetType().GetField(fieldName, Defines.FieldsFlags); + + if (field == null || field.GetCustomAttributes(typeof(DetailedAttribute), true).Length <= 0) + { + return false; + } + + if (container is MonoBehaviour or ScriptableObject) + { + return true; + } + } + + return false; + } + + private object GetValueFromContainer(ElementsContainer elementsContainer) + { + var property = elementsContainer.SerializedProperty; + switch (property.propertyType) + { + case SerializedPropertyType.Generic: + return property.GetValue(); + case SerializedPropertyType.ManagedReference: + return property.managedReferenceValue; + default: + return null; + } + } + + private void OnPropertyChanged(ElementsContainer container) + { + var target = GetValueFromContainer(_container); + + if (target == null) + { + _buttonDrawer.Clear(); + return; + } + + _buttonDrawer.CreateFromTarget(target); + } + + public override void Deconstruct() + { + _container.SerializedPropertyChanged -= OnPropertyChanged; + } + } +} \ No newline at end of file diff --git a/Editor/Drawers/Misc/Handlers/DetailedHandler.cs.meta b/Editor/Drawers/Misc/Handlers/DetailedHandler.cs.meta new file mode 100644 index 0000000..67aadbf --- /dev/null +++ b/Editor/Drawers/Misc/Handlers/DetailedHandler.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 9d5d7dfb57b34cd6be00a1ff786947c9 +timeCreated: 1725358184 \ No newline at end of file diff --git a/Editor/EditorAddons/Drawers/Misc/Handlers/EnumButtonsHandler.cs b/Editor/Drawers/Misc/Handlers/EnumButtonsHandler.cs similarity index 100% rename from Editor/EditorAddons/Drawers/Misc/Handlers/EnumButtonsHandler.cs rename to Editor/Drawers/Misc/Handlers/EnumButtonsHandler.cs diff --git a/Editor/EditorAddons/Drawers/Misc/Handlers/EnumButtonsHandler.cs.meta b/Editor/Drawers/Misc/Handlers/EnumButtonsHandler.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Misc/Handlers/EnumButtonsHandler.cs.meta rename to Editor/Drawers/Misc/Handlers/EnumButtonsHandler.cs.meta diff --git a/Editor/EditorAddons/Drawers/Misc/Handlers/HelpBoxHandler.cs b/Editor/Drawers/Misc/Handlers/HelpBoxHandler.cs similarity index 89% rename from Editor/EditorAddons/Drawers/Misc/Handlers/HelpBoxHandler.cs rename to Editor/Drawers/Misc/Handlers/HelpBoxHandler.cs index 0c71d97..70ba329 100644 --- a/Editor/EditorAddons/Drawers/Misc/Handlers/HelpBoxHandler.cs +++ b/Editor/Drawers/Misc/Handlers/HelpBoxHandler.cs @@ -12,9 +12,9 @@ protected override void OnSetupContainer() { var helpBoxAttribute = (HelpBoxAttribute)_attribute; - var textOrSelector = helpBoxAttribute.Text; + var textOrSelector = helpBoxAttribute.TextOrSelector; - var instance = _container.SerializedProperty.GetLastNonCollectionContainer(); + var instance = _container.SerializedProperty.GetLastNonCollectionParent(); if (SelectorUtility.TryGetValue(textOrSelector, instance, out var value)) { diff --git a/Editor/EditorAddons/Drawers/Misc/Handlers/HelpBoxHandler.cs.meta b/Editor/Drawers/Misc/Handlers/HelpBoxHandler.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Misc/Handlers/HelpBoxHandler.cs.meta rename to Editor/Drawers/Misc/Handlers/HelpBoxHandler.cs.meta diff --git a/Editor/EditorAddons/Drawers/Misc/Handlers/HideLabelHandler.cs b/Editor/Drawers/Misc/Handlers/HideLabelHandler.cs similarity index 100% rename from Editor/EditorAddons/Drawers/Misc/Handlers/HideLabelHandler.cs rename to Editor/Drawers/Misc/Handlers/HideLabelHandler.cs diff --git a/Editor/EditorAddons/Drawers/Misc/Handlers/HideLabelHandler.cs.meta b/Editor/Drawers/Misc/Handlers/HideLabelHandler.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Misc/Handlers/HideLabelHandler.cs.meta rename to Editor/Drawers/Misc/Handlers/HideLabelHandler.cs.meta diff --git a/Editor/EditorAddons/Drawers/Misc/Handlers/MiscHandler.cs b/Editor/Drawers/Misc/Handlers/MiscHandler.cs similarity index 100% rename from Editor/EditorAddons/Drawers/Misc/Handlers/MiscHandler.cs rename to Editor/Drawers/Misc/Handlers/MiscHandler.cs diff --git a/Editor/EditorAddons/Drawers/Misc/Handlers/MiscHandler.cs.meta b/Editor/Drawers/Misc/Handlers/MiscHandler.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Misc/Handlers/MiscHandler.cs.meta rename to Editor/Drawers/Misc/Handlers/MiscHandler.cs.meta diff --git a/Editor/EditorAddons/Drawers/Misc/Handlers/MiscLabelHandler.cs b/Editor/Drawers/Misc/Handlers/MiscLabelHandler.cs similarity index 100% rename from Editor/EditorAddons/Drawers/Misc/Handlers/MiscLabelHandler.cs rename to Editor/Drawers/Misc/Handlers/MiscLabelHandler.cs diff --git a/Editor/EditorAddons/Drawers/Misc/Handlers/MiscLabelHandler.cs.meta b/Editor/Drawers/Misc/Handlers/MiscLabelHandler.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Misc/Handlers/MiscLabelHandler.cs.meta rename to Editor/Drawers/Misc/Handlers/MiscLabelHandler.cs.meta diff --git a/Editor/EditorAddons/Drawers/Misc/Handlers/RenameFieldHandler.cs b/Editor/Drawers/Misc/Handlers/RenameFieldHandler.cs similarity index 100% rename from Editor/EditorAddons/Drawers/Misc/Handlers/RenameFieldHandler.cs rename to Editor/Drawers/Misc/Handlers/RenameFieldHandler.cs diff --git a/Editor/EditorAddons/Drawers/Misc/Handlers/RenameFieldHandler.cs.meta b/Editor/Drawers/Misc/Handlers/RenameFieldHandler.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Misc/Handlers/RenameFieldHandler.cs.meta rename to Editor/Drawers/Misc/Handlers/RenameFieldHandler.cs.meta diff --git a/Editor/EditorAddons/Drawers/Misc/MiscDrawer.cs b/Editor/Drawers/Misc/MiscDrawer.cs similarity index 100% rename from Editor/EditorAddons/Drawers/Misc/MiscDrawer.cs rename to Editor/Drawers/Misc/MiscDrawer.cs diff --git a/Editor/EditorAddons/Drawers/Misc/MiscDrawer.cs.meta b/Editor/Drawers/Misc/MiscDrawer.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Misc/MiscDrawer.cs.meta rename to Editor/Drawers/Misc/MiscDrawer.cs.meta diff --git a/Editor/Drawers/Parameters.meta b/Editor/Drawers/Parameters.meta new file mode 100644 index 0000000..174a87b --- /dev/null +++ b/Editor/Drawers/Parameters.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 265b1c57ccc14c62aafeda9bf9db75e3 +timeCreated: 1725848161 \ No newline at end of file diff --git a/Editor/Drawers/Parameters/FieldFactory.cs b/Editor/Drawers/Parameters/FieldFactory.cs new file mode 100644 index 0000000..f5c9d15 --- /dev/null +++ b/Editor/Drawers/Parameters/FieldFactory.cs @@ -0,0 +1,17 @@ +using System; +using UnityEngine.UIElements; + +namespace Better.Attributes.EditorAddons.Drawers.Parameters +{ + internal class FieldFactory + { + public Func SupportedFunc { get; } + public Func CreateFunc { get; } + + public FieldFactory(Func supportedFunc, Func createFunc) + { + SupportedFunc = supportedFunc; + CreateFunc = createFunc; + } + } +} \ No newline at end of file diff --git a/Editor/Drawers/Parameters/FieldFactory.cs.meta b/Editor/Drawers/Parameters/FieldFactory.cs.meta new file mode 100644 index 0000000..4c0361d --- /dev/null +++ b/Editor/Drawers/Parameters/FieldFactory.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 76110228d40a4daa9405ac4e6dca5d78 +timeCreated: 1728170017 \ No newline at end of file diff --git a/Editor/Drawers/Parameters/FieldFactoryExtensions.cs b/Editor/Drawers/Parameters/FieldFactoryExtensions.cs new file mode 100644 index 0000000..4b9b423 --- /dev/null +++ b/Editor/Drawers/Parameters/FieldFactoryExtensions.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using UnityEngine.UIElements; + +namespace Better.Attributes.EditorAddons.Drawers.Parameters +{ + internal static class FieldFactoryExtensions + { + public static void Add(this List self, Func supportedFunc, Func createFunc) + { + var fieldFactory = new FieldFactory(supportedFunc, createFunc); + self.Add(fieldFactory); + } + } +} \ No newline at end of file diff --git a/Editor/Drawers/Parameters/FieldFactoryExtensions.cs.meta b/Editor/Drawers/Parameters/FieldFactoryExtensions.cs.meta new file mode 100644 index 0000000..8365765 --- /dev/null +++ b/Editor/Drawers/Parameters/FieldFactoryExtensions.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: c28b76082e0f44ad97236aa46ff275f5 +timeCreated: 1728170017 \ No newline at end of file diff --git a/Editor/Drawers/Parameters/Parameter.cs b/Editor/Drawers/Parameters/Parameter.cs new file mode 100644 index 0000000..e8df834 --- /dev/null +++ b/Editor/Drawers/Parameters/Parameter.cs @@ -0,0 +1,25 @@ +using System; +using System.Reflection; +using Better.Commons.Runtime.Extensions; + +namespace Better.Attributes.EditorAddons.Drawers.Parameters +{ + internal class Parameter + { + public Type ParameterType { get; } + public string Name { get; } + public object Data { get; private set; } + + public Parameter(ParameterInfo info) + { + ParameterType = info.ParameterType; + Name = info.Name; + Data = info.HasDefaultValue ? info.DefaultValue : info.ParameterType.GetDefault(); + } + + public void SetData(object newData) + { + Data = newData; + } + } +} \ No newline at end of file diff --git a/Editor/Drawers/Parameters/Parameter.cs.meta b/Editor/Drawers/Parameters/Parameter.cs.meta new file mode 100644 index 0000000..81a83a2 --- /dev/null +++ b/Editor/Drawers/Parameters/Parameter.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: cf89768481e84de38506f9dace919d85 +timeCreated: 1727930947 \ No newline at end of file diff --git a/Editor/Drawers/Parameters/ParameterFieldProvider.cs b/Editor/Drawers/Parameters/ParameterFieldProvider.cs new file mode 100644 index 0000000..7871b4b --- /dev/null +++ b/Editor/Drawers/Parameters/ParameterFieldProvider.cs @@ -0,0 +1,172 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Better.Commons.EditorAddons.Utility; +using Better.Commons.Runtime.Extensions; +using UnityEditor; +using UnityEditor.UIElements; +using UnityEngine; +using UnityEngine.UIElements; +using Object = UnityEngine.Object; + +namespace Better.Attributes.EditorAddons.Drawers.Parameters +{ + internal static class ParameterFieldProvider + { + private const string ObjectFieldDisplayClassName = "unity-object-field-display"; + private static List _factories; + + static ParameterFieldProvider() + { + _factories = new List(); + + _factories.Add(SupportDirectType, ConfigureIntegerField); + + _factories.Add(SupportDirectType, ConfigureField); + + _factories.Add(SupportDirectType, ConfigureField); + + _factories.Add(SupportDirectType, ConfigureField); + + _factories.Add(SupportDirectType, ConfigureField); + + _factories.Add(SupportDirectType, ConfigureStringField); + + _factories.Add(SupportDirectType, ConfigureCharField); + + _factories.Add(type => SupportDirectType(type) || SupportDirectType(type), ConfigureField); + + _factories.Add(SupportDirectType, ConfigureField); + + _factories.Add(type => type.IsSubclassOf(), ConfigureEnumField); + + _factories.Add(SupportDirectType, ConfigureField); + + _factories.Add(SupportDirectType, ConfigureField); + + _factories.Add(SupportDirectType, ConfigureField); + + _factories.Add(SupportDirectType, ConfigureField); + + _factories.Add(SupportDirectType, ConfigureField); + + _factories.Add(SupportDirectType, ConfigureField); + + _factories.Add(SupportDirectType, ConfigureField); + + _factories.Add(SupportDirectType, ConfigureField); + + _factories.Add(SupportDirectType, ConfigureField); + + _factories.Add(SupportDirectType, ConfigureField); + + _factories.Add(SupportDirectType, ConfigureField); + + _factories.Add(SupportDirectType, ConfigureField); + + _factories.Add(type => type.IsSubclassOf(), ConfigureObjectField); + } + + private static bool SupportDirectType(Type type) + { + return type == typeof(T); + } + + private static VisualElement ConfigureEnumField(Parameter parameter) + { + var enumType = parameter.ParameterType; + var enumValues = enumType.GetEnumValues().Cast().ToList(); + var enumDisplayNames = enumValues.Select(enumValue => ObjectNames.NicifyVariableName(enumValue.ToString())).ToList(); + var enumValueIndex = enumValues.IndexOf(parameter.Data); + if (enumType.IsDefined(typeof(FlagsAttribute), false)) + { + var enumField = ConfigureField(parameter); + enumField.choices = enumDisplayNames; + enumField.value = (Enum)Enum.ToObject(enumType, enumValueIndex); + return enumField; + } + + + var propertyFieldIndex = enumValueIndex < 0 || enumValueIndex >= enumDisplayNames.Count ? -1 : enumValueIndex; + + var popupField = ConfigureField, string>(parameter); + + popupField.choices = enumDisplayNames; + popupField.index = propertyFieldIndex; + + return popupField; + } + + private static VisualElement ConfigureStringField(Parameter parameter) + { + var textField = ConfigureField(parameter); + textField.maxLength = -1; + return textField; + } + + private static VisualElement ConfigureCharField(Parameter parameter) + { + var textField = ConfigureField(parameter); + textField.maxLength = -1; + return textField; + } + + private static VisualElement ConfigureObjectField(Parameter parameter) + { + var objectField = ConfigureField(parameter); + objectField.objectType = parameter.ParameterType; + objectField.allowSceneObjects = true; + + var visualElement = objectField.Q(ObjectFieldDisplayClassName); + visualElement?.style.Width(StyleDefinition.OneStyleLength); + + return objectField; + } + + private static VisualElement ConfigureIntegerField(Parameter parameter) + { + var integerField = ConfigureField(parameter); + integerField.isDelayed = false; + return integerField; + } + + private static TField ConfigureField( + Parameter parameter) + where TField : BaseField, new() + { + var field = new TField(); + field.RegisterValueChangedCallback(evt => { parameter.SetData(evt.newValue); }); + field.value = (TValue)parameter.Data; + field.label = ObjectNames.NicifyVariableName(parameter.Name); + field.style.FlexGrow(StyleDefinition.OneStyleFloat); + field.labelElement.style.MinWidth(StyleKeyword.Auto); + return field; + } + + public static bool IsSupported(Type type) + { + foreach (var factory in _factories) + { + if (factory.SupportedFunc.Invoke(type)) + { + return true; + } + } + + return false; + } + + public static VisualElement CreateParameterField(Parameter parameter) + { + foreach (var factory in _factories) + { + if (factory.SupportedFunc.Invoke(parameter.ParameterType)) + { + return factory.CreateFunc.Invoke(parameter); + } + } + + return null; + } + } +} \ No newline at end of file diff --git a/Editor/Drawers/Parameters/ParameterFieldProvider.cs.meta b/Editor/Drawers/Parameters/ParameterFieldProvider.cs.meta new file mode 100644 index 0000000..9ba7501 --- /dev/null +++ b/Editor/Drawers/Parameters/ParameterFieldProvider.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: f9426f96b055458db7a5ffa05c121c48 +timeCreated: 1728165033 \ No newline at end of file diff --git a/Editor/Drawers/Parameters/ParametersElementDrawer.cs b/Editor/Drawers/Parameters/ParametersElementDrawer.cs new file mode 100644 index 0000000..70516e8 --- /dev/null +++ b/Editor/Drawers/Parameters/ParametersElementDrawer.cs @@ -0,0 +1,31 @@ +using System.Linq; +using Better.Commons.Runtime.Extensions; +using UnityEngine.UIElements; + +namespace Better.Attributes.EditorAddons.Drawers.Parameters +{ + internal class ParametersElementDrawer : VisualElement + { + private readonly Parameter[] _parameters; + + public ParametersElementDrawer(Parameter[] parameters) + { + _parameters = parameters; + + foreach (var parameter in _parameters) + { + var element = ParameterFieldProvider.CreateParameterField(parameter); + Add(element); + } + + AddToClassList(HelpBox.ussClassName); + style.PaddingRight(5f) + .FlexDirection(FlexDirection.Column); + } + + public object[] GetData() + { + return _parameters.Select(parameter => parameter.Data).ToArray(); + } + } +} \ No newline at end of file diff --git a/Editor/Drawers/Parameters/ParametersElementDrawer.cs.meta b/Editor/Drawers/Parameters/ParametersElementDrawer.cs.meta new file mode 100644 index 0000000..7497348 --- /dev/null +++ b/Editor/Drawers/Parameters/ParametersElementDrawer.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 07792e463aa74c54a5e41505711bd9de +timeCreated: 1727930947 \ No newline at end of file diff --git a/Editor/EditorAddons/Drawers/Preview.meta b/Editor/Drawers/Preview.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Preview.meta rename to Editor/Drawers/Preview.meta diff --git a/Editor/EditorAddons/Drawers/Preview/Handlers.meta b/Editor/Drawers/Preview/Handlers.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Preview/Handlers.meta rename to Editor/Drawers/Preview/Handlers.meta diff --git a/Editor/EditorAddons/Drawers/Preview/Handlers/AssetHandler.cs b/Editor/Drawers/Preview/Handlers/AssetHandler.cs similarity index 100% rename from Editor/EditorAddons/Drawers/Preview/Handlers/AssetHandler.cs rename to Editor/Drawers/Preview/Handlers/AssetHandler.cs diff --git a/Editor/EditorAddons/Drawers/Preview/Handlers/AssetHandler.cs.meta b/Editor/Drawers/Preview/Handlers/AssetHandler.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Preview/Handlers/AssetHandler.cs.meta rename to Editor/Drawers/Preview/Handlers/AssetHandler.cs.meta diff --git a/Editor/EditorAddons/Drawers/Preview/Handlers/PreviewHandler.cs b/Editor/Drawers/Preview/Handlers/PreviewHandler.cs similarity index 100% rename from Editor/EditorAddons/Drawers/Preview/Handlers/PreviewHandler.cs rename to Editor/Drawers/Preview/Handlers/PreviewHandler.cs diff --git a/Editor/EditorAddons/Drawers/Preview/Handlers/PreviewHandler.cs.meta b/Editor/Drawers/Preview/Handlers/PreviewHandler.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Preview/Handlers/PreviewHandler.cs.meta rename to Editor/Drawers/Preview/Handlers/PreviewHandler.cs.meta diff --git a/Editor/EditorAddons/Drawers/Preview/Handlers/SpriteHandler.cs b/Editor/Drawers/Preview/Handlers/SpriteHandler.cs similarity index 100% rename from Editor/EditorAddons/Drawers/Preview/Handlers/SpriteHandler.cs rename to Editor/Drawers/Preview/Handlers/SpriteHandler.cs diff --git a/Editor/EditorAddons/Drawers/Preview/Handlers/SpriteHandler.cs.meta b/Editor/Drawers/Preview/Handlers/SpriteHandler.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Preview/Handlers/SpriteHandler.cs.meta rename to Editor/Drawers/Preview/Handlers/SpriteHandler.cs.meta diff --git a/Editor/EditorAddons/Drawers/Preview/Handlers/TextureHandler.cs b/Editor/Drawers/Preview/Handlers/TextureHandler.cs similarity index 100% rename from Editor/EditorAddons/Drawers/Preview/Handlers/TextureHandler.cs rename to Editor/Drawers/Preview/Handlers/TextureHandler.cs diff --git a/Editor/EditorAddons/Drawers/Preview/Handlers/TextureHandler.cs.meta b/Editor/Drawers/Preview/Handlers/TextureHandler.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Preview/Handlers/TextureHandler.cs.meta rename to Editor/Drawers/Preview/Handlers/TextureHandler.cs.meta diff --git a/Editor/EditorAddons/Drawers/Preview/PreviewDrawer.cs b/Editor/Drawers/Preview/PreviewDrawer.cs similarity index 100% rename from Editor/EditorAddons/Drawers/Preview/PreviewDrawer.cs rename to Editor/Drawers/Preview/PreviewDrawer.cs diff --git a/Editor/EditorAddons/Drawers/Preview/PreviewDrawer.cs.meta b/Editor/Drawers/Preview/PreviewDrawer.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Preview/PreviewDrawer.cs.meta rename to Editor/Drawers/Preview/PreviewDrawer.cs.meta diff --git a/Editor/EditorAddons/Drawers/Preview/PreviewSceneRenderer.cs b/Editor/Drawers/Preview/PreviewSceneRenderer.cs similarity index 100% rename from Editor/EditorAddons/Drawers/Preview/PreviewSceneRenderer.cs rename to Editor/Drawers/Preview/PreviewSceneRenderer.cs diff --git a/Editor/EditorAddons/Drawers/Preview/PreviewSceneRenderer.cs.meta b/Editor/Drawers/Preview/PreviewSceneRenderer.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Preview/PreviewSceneRenderer.cs.meta rename to Editor/Drawers/Preview/PreviewSceneRenderer.cs.meta diff --git a/Editor/EditorAddons/Drawers/Select.meta b/Editor/Drawers/Select.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Select.meta rename to Editor/Drawers/Select.meta diff --git a/Editor/EditorAddons/Drawers/Select/Handlers.meta b/Editor/Drawers/Select/Handlers.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Select/Handlers.meta rename to Editor/Drawers/Select/Handlers.meta diff --git a/Editor/EditorAddons/Drawers/Select/Handlers/BaseSelectHandler.cs b/Editor/Drawers/Select/Handlers/BaseSelectHandler.cs similarity index 96% rename from Editor/EditorAddons/Drawers/Select/Handlers/BaseSelectHandler.cs rename to Editor/Drawers/Select/Handlers/BaseSelectHandler.cs index 8694e3c..15cf034 100644 --- a/Editor/EditorAddons/Drawers/Select/Handlers/BaseSelectHandler.cs +++ b/Editor/Drawers/Select/Handlers/BaseSelectHandler.cs @@ -3,6 +3,7 @@ using System.Reflection; using Better.Attributes.Runtime; using Better.Attributes.Runtime.Select; +using Better.Attributes.Runtime.Utilities; using Better.Commons.EditorAddons.Drawers; using Better.Commons.EditorAddons.Drawers.Container; using Better.Commons.EditorAddons.Drawers.Handlers; @@ -32,7 +33,7 @@ public void Setup(ElementsContainer container, FieldInfo fieldInfo, BaseSelectAt Container = container; FieldInfo = fieldInfo; Attribute = attribute; - PropertyContainer = Container.SerializedProperty.GetLastNonCollectionContainer(); + PropertyContainer = Container.SerializedProperty.GetLastNonCollectionParent(); CurrentValue = GetCurrentValue(); OnSetup(); } @@ -144,7 +145,8 @@ public virtual void OnPopulateContainer() if (IsSkippingFieldDraw()) { var label = VisualElementUtility.CreateLabelFor(Container.SerializedProperty); - Container.RootElement.Insert(0, label); + var element = Container.CreateElementFrom(label); + element.SendToBack(); label.style.Width(StyleDefinition.LabelWidthStyle); label.SendToBack(); label.AddToClassList(PropertyField.labelUssClassName); diff --git a/Editor/EditorAddons/Drawers/Select/Handlers/BaseSelectHandler.cs.meta b/Editor/Drawers/Select/Handlers/BaseSelectHandler.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Select/Handlers/BaseSelectHandler.cs.meta rename to Editor/Drawers/Select/Handlers/BaseSelectHandler.cs.meta diff --git a/Editor/EditorAddons/Drawers/Select/Handlers/BaseSelectTypeHandler.cs b/Editor/Drawers/Select/Handlers/BaseSelectTypeHandler.cs similarity index 98% rename from Editor/EditorAddons/Drawers/Select/Handlers/BaseSelectTypeHandler.cs rename to Editor/Drawers/Select/Handlers/BaseSelectTypeHandler.cs index 198dc32..353343b 100644 --- a/Editor/EditorAddons/Drawers/Select/Handlers/BaseSelectTypeHandler.cs +++ b/Editor/Drawers/Select/Handlers/BaseSelectTypeHandler.cs @@ -4,6 +4,7 @@ using Better.Attributes.EditorAddons.Extensions; using Better.Attributes.Runtime; using Better.Attributes.Runtime.Select; +using Better.Attributes.Runtime.Utilities; using Better.Commons.EditorAddons.Utility; using Better.Commons.Runtime.Utility; using UnityEngine; diff --git a/Editor/EditorAddons/Drawers/Select/Handlers/BaseSelectTypeHandler.cs.meta b/Editor/Drawers/Select/Handlers/BaseSelectTypeHandler.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Select/Handlers/BaseSelectTypeHandler.cs.meta rename to Editor/Drawers/Select/Handlers/BaseSelectTypeHandler.cs.meta diff --git a/Editor/EditorAddons/Drawers/Select/Handlers/DropdownCollection.meta b/Editor/Drawers/Select/Handlers/DropdownCollection.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Select/Handlers/DropdownCollection.meta rename to Editor/Drawers/Select/Handlers/DropdownCollection.meta diff --git a/Editor/EditorAddons/Drawers/Select/Handlers/DropdownCollection/DictionaryCollection.cs b/Editor/Drawers/Select/Handlers/DropdownCollection/DictionaryCollection.cs similarity index 98% rename from Editor/EditorAddons/Drawers/Select/Handlers/DropdownCollection/DictionaryCollection.cs rename to Editor/Drawers/Select/Handlers/DropdownCollection/DictionaryCollection.cs index 7af98fd..85b181b 100644 --- a/Editor/EditorAddons/Drawers/Select/Handlers/DropdownCollection/DictionaryCollection.cs +++ b/Editor/Drawers/Select/Handlers/DropdownCollection/DictionaryCollection.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using Better.Attributes.Runtime; +using Better.Attributes.Runtime.Utilities; using Better.Commons.Runtime.Extensions; using UnityEngine; diff --git a/Editor/EditorAddons/Drawers/Select/Handlers/DropdownCollection/DictionaryCollection.cs.meta b/Editor/Drawers/Select/Handlers/DropdownCollection/DictionaryCollection.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Select/Handlers/DropdownCollection/DictionaryCollection.cs.meta rename to Editor/Drawers/Select/Handlers/DropdownCollection/DictionaryCollection.cs.meta diff --git a/Editor/EditorAddons/Drawers/Select/Handlers/DropdownCollection/EnumerableCollection.cs b/Editor/Drawers/Select/Handlers/DropdownCollection/EnumerableCollection.cs similarity index 98% rename from Editor/EditorAddons/Drawers/Select/Handlers/DropdownCollection/EnumerableCollection.cs rename to Editor/Drawers/Select/Handlers/DropdownCollection/EnumerableCollection.cs index 62cdd96..20067b3 100644 --- a/Editor/EditorAddons/Drawers/Select/Handlers/DropdownCollection/EnumerableCollection.cs +++ b/Editor/Drawers/Select/Handlers/DropdownCollection/EnumerableCollection.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Runtime.CompilerServices; using Better.Attributes.Runtime; +using Better.Attributes.Runtime.Utilities; using Better.Commons.Runtime.Extensions; namespace Better.Attributes.EditorAddons.Drawers.Select diff --git a/Editor/EditorAddons/Drawers/Select/Handlers/DropdownCollection/EnumerableCollection.cs.meta b/Editor/Drawers/Select/Handlers/DropdownCollection/EnumerableCollection.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Select/Handlers/DropdownCollection/EnumerableCollection.cs.meta rename to Editor/Drawers/Select/Handlers/DropdownCollection/EnumerableCollection.cs.meta diff --git a/Editor/EditorAddons/Drawers/Select/Handlers/DropdownCollection/IDataCollection.cs b/Editor/Drawers/Select/Handlers/DropdownCollection/IDataCollection.cs similarity index 100% rename from Editor/EditorAddons/Drawers/Select/Handlers/DropdownCollection/IDataCollection.cs rename to Editor/Drawers/Select/Handlers/DropdownCollection/IDataCollection.cs diff --git a/Editor/EditorAddons/Drawers/Select/Handlers/DropdownCollection/IDataCollection.cs.meta b/Editor/Drawers/Select/Handlers/DropdownCollection/IDataCollection.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Select/Handlers/DropdownCollection/IDataCollection.cs.meta rename to Editor/Drawers/Select/Handlers/DropdownCollection/IDataCollection.cs.meta diff --git a/Editor/EditorAddons/Drawers/Select/Handlers/DropdownCollection/KeyTupleComparer.cs b/Editor/Drawers/Select/Handlers/DropdownCollection/KeyTupleComparer.cs similarity index 100% rename from Editor/EditorAddons/Drawers/Select/Handlers/DropdownCollection/KeyTupleComparer.cs rename to Editor/Drawers/Select/Handlers/DropdownCollection/KeyTupleComparer.cs diff --git a/Editor/EditorAddons/Drawers/Select/Handlers/DropdownCollection/KeyTupleComparer.cs.meta b/Editor/Drawers/Select/Handlers/DropdownCollection/KeyTupleComparer.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Select/Handlers/DropdownCollection/KeyTupleComparer.cs.meta rename to Editor/Drawers/Select/Handlers/DropdownCollection/KeyTupleComparer.cs.meta diff --git a/Editor/EditorAddons/Drawers/Select/Handlers/DropdownCollection/NoneCollection.cs b/Editor/Drawers/Select/Handlers/DropdownCollection/NoneCollection.cs similarity index 100% rename from Editor/EditorAddons/Drawers/Select/Handlers/DropdownCollection/NoneCollection.cs rename to Editor/Drawers/Select/Handlers/DropdownCollection/NoneCollection.cs diff --git a/Editor/EditorAddons/Drawers/Select/Handlers/DropdownCollection/NoneCollection.cs.meta b/Editor/Drawers/Select/Handlers/DropdownCollection/NoneCollection.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Select/Handlers/DropdownCollection/NoneCollection.cs.meta rename to Editor/Drawers/Select/Handlers/DropdownCollection/NoneCollection.cs.meta diff --git a/Editor/EditorAddons/Drawers/Select/Handlers/DropdownHandler.cs b/Editor/Drawers/Select/Handlers/DropdownHandler.cs similarity index 99% rename from Editor/EditorAddons/Drawers/Select/Handlers/DropdownHandler.cs rename to Editor/Drawers/Select/Handlers/DropdownHandler.cs index 24e78a4..4255d34 100644 --- a/Editor/EditorAddons/Drawers/Select/Handlers/DropdownHandler.cs +++ b/Editor/Drawers/Select/Handlers/DropdownHandler.cs @@ -5,6 +5,7 @@ using Better.Attributes.EditorAddons.Extensions; using Better.Attributes.Runtime; using Better.Attributes.Runtime.Select; +using Better.Attributes.Runtime.Utilities; using Better.Commons.EditorAddons.Extensions; using Better.Commons.EditorAddons.Utility; using Better.Commons.Runtime.Comparers; @@ -62,8 +63,7 @@ protected override List GetObjects() { return _collection.GetValues(); } - - + protected override GUIContent GetResolvedName(object value, DisplayName displayName) { if (value == null) diff --git a/Editor/EditorAddons/Drawers/Select/Handlers/DropdownHandler.cs.meta b/Editor/Drawers/Select/Handlers/DropdownHandler.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Select/Handlers/DropdownHandler.cs.meta rename to Editor/Drawers/Select/Handlers/DropdownHandler.cs.meta diff --git a/Editor/EditorAddons/Drawers/Select/Handlers/SelectEnumHandler.cs b/Editor/Drawers/Select/Handlers/SelectEnumHandler.cs similarity index 99% rename from Editor/EditorAddons/Drawers/Select/Handlers/SelectEnumHandler.cs rename to Editor/Drawers/Select/Handlers/SelectEnumHandler.cs index abbf933..a3ac679 100644 --- a/Editor/EditorAddons/Drawers/Select/Handlers/SelectEnumHandler.cs +++ b/Editor/Drawers/Select/Handlers/SelectEnumHandler.cs @@ -5,6 +5,7 @@ using Better.Attributes.EditorAddons.Extensions; using Better.Attributes.Runtime; using Better.Attributes.Runtime.Select; +using Better.Attributes.Runtime.Utilities; using Better.Commons.EditorAddons.Extensions; using Better.Commons.Runtime.Extensions; using Better.Commons.Runtime.Utility; diff --git a/Editor/EditorAddons/Drawers/Select/Handlers/SelectEnumHandler.cs.meta b/Editor/Drawers/Select/Handlers/SelectEnumHandler.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Select/Handlers/SelectEnumHandler.cs.meta rename to Editor/Drawers/Select/Handlers/SelectEnumHandler.cs.meta diff --git a/Editor/EditorAddons/Drawers/Select/Handlers/SelectImplementationHandler.cs b/Editor/Drawers/Select/Handlers/SelectImplementationHandler.cs similarity index 97% rename from Editor/EditorAddons/Drawers/Select/Handlers/SelectImplementationHandler.cs rename to Editor/Drawers/Select/Handlers/SelectImplementationHandler.cs index f47aed1..f649ece 100644 --- a/Editor/EditorAddons/Drawers/Select/Handlers/SelectImplementationHandler.cs +++ b/Editor/Drawers/Select/Handlers/SelectImplementationHandler.cs @@ -38,7 +38,7 @@ public override object GetCurrentValue() protected override IEnumerable GetInheritedTypes(Type fieldType) { var inheritedTypes = fieldType.GetAllInheritedTypesWithoutUnityObject() - .Where(type => !type.IsGenericType && !type.IsGenericTypeDefinition); + .Where(type => !type.IsGenericType && !type.IsGenericTypeDefinition && type.IsDefined(typeof(SerializableAttribute), false)); return inheritedTypes; } diff --git a/Editor/EditorAddons/Drawers/Select/Handlers/SelectImplementationHandler.cs.meta b/Editor/Drawers/Select/Handlers/SelectImplementationHandler.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Select/Handlers/SelectImplementationHandler.cs.meta rename to Editor/Drawers/Select/Handlers/SelectImplementationHandler.cs.meta diff --git a/Editor/EditorAddons/Drawers/Select/Handlers/SelectSerializedTypeHandler.cs b/Editor/Drawers/Select/Handlers/SelectSerializedTypeHandler.cs similarity index 99% rename from Editor/EditorAddons/Drawers/Select/Handlers/SelectSerializedTypeHandler.cs rename to Editor/Drawers/Select/Handlers/SelectSerializedTypeHandler.cs index c18c49c..7ba490c 100644 --- a/Editor/EditorAddons/Drawers/Select/Handlers/SelectSerializedTypeHandler.cs +++ b/Editor/Drawers/Select/Handlers/SelectSerializedTypeHandler.cs @@ -5,6 +5,7 @@ using Better.Attributes.EditorAddons.Extensions; using Better.Attributes.Runtime; using Better.Attributes.Runtime.Select; +using Better.Attributes.Runtime.Utilities; using Better.Commons.EditorAddons.Extensions; using Better.Commons.EditorAddons.Utility; using Better.Commons.Runtime.DataStructures.SerializedTypes; diff --git a/Editor/EditorAddons/Drawers/Select/Handlers/SelectSerializedTypeHandler.cs.meta b/Editor/Drawers/Select/Handlers/SelectSerializedTypeHandler.cs.meta similarity index 100% rename from Editor/EditorAddons/Drawers/Select/Handlers/SelectSerializedTypeHandler.cs.meta rename to Editor/Drawers/Select/Handlers/SelectSerializedTypeHandler.cs.meta diff --git a/Editor/EditorAddons/Drawers/Select/SelectDrawer.cs b/Editor/Drawers/Select/SelectDrawer.cs similarity index 89% rename from Editor/EditorAddons/Drawers/Select/SelectDrawer.cs rename to Editor/Drawers/Select/SelectDrawer.cs index ffb16a7..22f7b5c 100644 --- a/Editor/EditorAddons/Drawers/Select/SelectDrawer.cs +++ b/Editor/Drawers/Select/SelectDrawer.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using Better.Attributes.Runtime.Select; using Better.Commons.EditorAddons.Comparers; using Better.Commons.EditorAddons.Drawers; @@ -7,11 +6,9 @@ using Better.Commons.EditorAddons.Drawers.Container; using Better.Commons.EditorAddons.DropDown; using Better.Commons.EditorAddons.Extensions; -using Better.Commons.EditorAddons.Helpers; using Better.Commons.EditorAddons.Utility; using Better.Commons.Runtime.Extensions; using UnityEditor; -using UnityEditor.UIElements; using UnityEngine; using UnityEngine.UIElements; @@ -57,7 +54,10 @@ protected override void PopulateContainer(ElementsContainer container) handler.OnPopulateContainer(); - container.RootElement.OnElementAppear