Skip to content

Commit

Permalink
Merge pull request #19 from techno-dwarf-works/feature/refactoring
Browse files Browse the repository at this point in the history
Version 0.0.16
  • Loading branch information
OpOpYaDev committed Jul 12, 2024
1 parent 64eb5a1 commit c139cc6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
32 changes: 29 additions & 3 deletions Runtime/DataStructures/SerializedTypes/SerializedType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/// </summary>
[Serializable]
public class SerializedType : ISerializationCallbackReceiver
public class SerializedType : ISerializationCallbackReceiver, IEquatable<SerializedType>
{
[FormerlySerializedAs("fullQualifiedName")]
[SerializeField] private protected string _fullQualifiedName; // The full name of the type, used for serialization.
Expand All @@ -29,6 +29,7 @@ public Type Type
_fullQualifiedName = string.Empty;
}
}

return _type;
}
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
}
}
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.commons",
"displayName": "Better Commons",
"version": "0.0.15",
"version": "0.0.16",
"unity": "2021.3",
"description": " ",
"dependencies": {
Expand Down

0 comments on commit c139cc6

Please sign in to comment.