Skip to content

Commit

Permalink
Merge pull request #11 from techno-dwarf-works/feature/refactoring
Browse files Browse the repository at this point in the history
Version 0.0.3
  • Loading branch information
uurha committed Oct 7, 2024
1 parent 6bd91bc commit 8ca9c54
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
24 changes: 24 additions & 0 deletions Editor/Comparers/SelectImplementationTypeComparer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using Better.Commons.Runtime.Comparers;

namespace Better.Attributes.EditorAddons.Comparers
{
public class SelectImplementationTypeComparer : BaseComparer<SelectImplementationTypeComparer, Type>, IEqualityComparer<Type>
{
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;
}
}
}
3 changes: 3 additions & 0 deletions Editor/Comparers/SelectImplementationTypeComparer.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Editor/Drawers/HandlerMaps/SelectTypeHandlerBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected override BaseHandlersTypeCollection GenerateCollection()
return new HandlersTypeCollection(TypeComparer.Instance)
{
{
typeof(SelectAttribute), new Dictionary<Type, Type>(TypeComparer.Instance)
typeof(SelectAttribute), new Dictionary<Type, Type>(SelectImplementationTypeComparer.Instance)
{
{ typeof(SerializedType), typeof(SelectSerializedTypeHandler) },
{ typeof(Enum), typeof(SelectEnumHandler) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit 8ca9c54

Please sign in to comment.