From ed30659fdf8ce8a5e1313cafe1b27fca2a1cbc0e Mon Sep 17 00:00:00 2001 From: Anatoly Brizhan Date: Fri, 12 Jul 2024 20:29:53 +0200 Subject: [PATCH 1/2] Update SerializedType equaliting --- .../SerializedTypes/SerializedType.cs | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/Assets/BetterCommons/Runtime/DataStructures/SerializedTypes/SerializedType.cs b/Assets/BetterCommons/Runtime/DataStructures/SerializedTypes/SerializedType.cs index 9fbc69f..c6a699c 100644 --- a/Assets/BetterCommons/Runtime/DataStructures/SerializedTypes/SerializedType.cs +++ b/Assets/BetterCommons/Runtime/DataStructures/SerializedTypes/SerializedType.cs @@ -8,7 +8,7 @@ namespace Better.Commons.Runtime.DataStructures.SerializedTypes /// Enables the serialization of a System.Type reference within Unity, storing the type's assembly qualified name. /// [Serializable] - public class SerializedType : ISerializationCallbackReceiver + public class SerializedType : ISerializationCallbackReceiver, IEquatable { [FormerlySerializedAs("fullQualifiedName")] [SerializeField] private protected string _fullQualifiedName; // The full name of the type, used for serialization. @@ -29,6 +29,7 @@ public Type Type _fullQualifiedName = string.Empty; } } + return _type; } } @@ -71,7 +72,7 @@ public SerializedType(Type type) _type = type; _fullQualifiedName = type.AssemblyQualifiedName; } - + private static bool TryGetReferenceType(string value, out Type type) { type = !string.IsNullOrEmpty(value) ? Type.GetType(value) : null; @@ -119,5 +120,30 @@ void ISerializationCallbackReceiver.OnBeforeSerialize() public static implicit operator string(SerializedType typeReference) => typeReference._fullQualifiedName; public static implicit operator Type(SerializedType typeReference) => typeReference.Type; public static implicit operator SerializedType(Type type) => new SerializedType(type); + + public bool Equals(SerializedType other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + return Type == other.Type; + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != this.GetType()) return false; + return Equals((SerializedType)obj); + } + + public override int GetHashCode() + { + if (Type == null) + { + return default; + } + + return Type.GetHashCode(); + } } -} +} \ No newline at end of file From 1e163359bd6b3de0d707af444d23c22323193039 Mon Sep 17 00:00:00 2001 From: Anatoly Brizhan Date: Fri, 12 Jul 2024 20:30:07 +0200 Subject: [PATCH 2/2] Update package version to 0.0.16 --- Assets/BetterCommons/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/BetterCommons/package.json b/Assets/BetterCommons/package.json index 498f48d..88edb0e 100644 --- a/Assets/BetterCommons/package.json +++ b/Assets/BetterCommons/package.json @@ -1,7 +1,7 @@ { "name": "com.tdw.better.commons", "displayName": "Better Commons", - "version": "0.0.15", + "version": "0.0.16", "unity": "2021.3", "description": " ", "dependencies": {