diff --git a/Editor/Comparers/SelectImplementationTypeComparer.cs b/Editor/Comparers/SelectImplementationTypeComparer.cs new file mode 100644 index 0000000..eaf3b92 --- /dev/null +++ b/Editor/Comparers/SelectImplementationTypeComparer.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using Better.Commons.Runtime.Comparers; + +namespace Better.Attributes.EditorAddons.Comparers +{ + public class SelectImplementationTypeComparer : BaseComparer, IEqualityComparer + { + public bool Equals(Type x, Type y) + { + if (ReferenceEquals(x, y)) return true; + if (ReferenceEquals(x, null)) return false; + if (ReferenceEquals(y, null)) return false; + if (x.IsAssignableFrom(y) || x == y) return true; + if ((y.IsInterface || y.IsAbstract) && x == typeof(Type)) return true; + return x == typeof(Type); + } + + public int GetHashCode(Type obj) + { + return 0; + } + } +} \ No newline at end of file diff --git a/Editor/Comparers/SelectImplementationTypeComparer.cs.meta b/Editor/Comparers/SelectImplementationTypeComparer.cs.meta new file mode 100644 index 0000000..09913ba --- /dev/null +++ b/Editor/Comparers/SelectImplementationTypeComparer.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 4d010b6bc3674e49b4b426837abd4c6f +timeCreated: 1728271758 \ No newline at end of file diff --git a/Editor/Drawers/HandlerMaps/SelectTypeHandlerBinder.cs b/Editor/Drawers/HandlerMaps/SelectTypeHandlerBinder.cs index fce98f0..396184a 100644 --- a/Editor/Drawers/HandlerMaps/SelectTypeHandlerBinder.cs +++ b/Editor/Drawers/HandlerMaps/SelectTypeHandlerBinder.cs @@ -20,7 +20,7 @@ protected override BaseHandlersTypeCollection GenerateCollection() return new HandlersTypeCollection(TypeComparer.Instance) { { - typeof(SelectAttribute), new Dictionary(TypeComparer.Instance) + typeof(SelectAttribute), new Dictionary(SelectImplementationTypeComparer.Instance) { { typeof(SerializedType), typeof(SelectSerializedTypeHandler) }, { typeof(Enum), typeof(SelectEnumHandler) }, diff --git a/Editor/Drawers/Select/Handlers/SelectImplementationHandler.cs b/Editor/Drawers/Select/Handlers/SelectImplementationHandler.cs index f649ece..7359a68 100644 --- a/Editor/Drawers/Select/Handlers/SelectImplementationHandler.cs +++ b/Editor/Drawers/Select/Handlers/SelectImplementationHandler.cs @@ -50,7 +50,7 @@ public override bool IsSkippingFieldDraw() public override bool CheckSupported() { var baseType = GetFieldOrElementType(); - return baseType.IsAbstract || baseType.IsInterface; + return baseType.IsAbstract || baseType.IsInterface || baseType.HasParameterlessConstructor(); } public override bool ValidateSelected(object item) diff --git a/package.json b/package.json index 98b8aa5..baf7c7d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "com.tdw.better.attributes", "displayName": "Better Attributes", - "version": "0.0.2", + "version": "0.0.3", "unity": "2021.3", "description": "Unity attributes, allows to serialize interfaces, draw handles for Vector3/Vector2/Quaternion/Bounds, create read only fields.", "dependencies": {