From 88b575539a32f14af65494ceb3fe631239cf99f9 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 17 Feb 2021 16:05:59 +0100 Subject: [PATCH] Add more utilities to SceneReference --- Source/Engine/Engine/SceneReference.cs | 90 +++++++++++++++++++++++++- 1 file changed, 89 insertions(+), 1 deletion(-) diff --git a/Source/Engine/Engine/SceneReference.cs b/Source/Engine/Engine/SceneReference.cs index 0cdadf2e9..c40035c2a 100644 --- a/Source/Engine/Engine/SceneReference.cs +++ b/Source/Engine/Engine/SceneReference.cs @@ -7,7 +7,7 @@ namespace FlaxEngine /// /// Represents the reference to the scene asset. Stores the unique ID of the scene to reference. Can be used to load the selected scene. /// - public struct SceneReference + public struct SceneReference : IComparable, IComparable, IComparable { /// /// The identifier of the scene asset (and the scene object). @@ -22,5 +22,93 @@ namespace FlaxEngine { ID = id; } + + /// + /// Compares two values and returns true if are equal or false if unequal. + /// + /// The left value. + /// The right value. + /// True if values are equal, otherwise false. + public static bool operator ==(SceneReference left, SceneReference right) + { + return left.ID == right.ID; + } + + /// + /// Compares two values and returns false if are equal or true if unequal. + /// + /// The left value. + /// The right value. + /// True if values are not equal, otherwise false. + public static bool operator !=(SceneReference left, SceneReference right) + { + return left.ID != right.ID; + } + + /// + /// Compares two values and returns true if are equal or false if unequal. + /// + /// The left value. + /// The right value. + /// True if values are equal, otherwise false. + public static bool operator ==(SceneReference left, Guid right) + { + return left.ID == right; + } + + /// + /// Compares two values and returns false if are equal or true if unequal. + /// + /// The left value. + /// The right value. + /// True if values are not equal, otherwise false. + public static bool operator !=(SceneReference left, Guid right) + { + return left.ID != right; + } + + /// + public int CompareTo(object obj) + { + if (obj is Guid id) + return CompareTo(id); + if (obj is SceneReference other) + return CompareTo(other); + return 0; + } + + /// + public int CompareTo(Guid other) + { + return ID.CompareTo(other); + } + + /// + public int CompareTo(SceneReference other) + { + return ID.CompareTo(other.ID); + } + + /// + public override bool Equals(object obj) + { + if (obj is Guid id) + return ID == id; + if (obj is SceneReference other) + return ID == other.ID; + return false; + } + + /// + public override int GetHashCode() + { + return ID.GetHashCode(); + } + + /// + public override string ToString() + { + return ID.ToString(); + } } }