Skip to content

Commit 9c0ef38

Browse files
committed
Adding Equals, GetHashCode & CompareTo methods.
1 parent 3baeee6 commit 9c0ef38

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

Assets/DevLocker/Utils/SceneReference.cs

+37-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace DevLocker.Utils
2626
[InitializeOnLoad]
2727
#endif
2828
[Serializable]
29-
public class SceneReference : ISerializationCallbackReceiver
29+
public class SceneReference : ISerializationCallbackReceiver, IEquatable<SceneReference>, IComparable<SceneReference>
3030
{
3131

3232
#if UNITY_EDITOR
@@ -94,6 +94,42 @@ public string ScenePath
9494
/// </summary>
9595
public int BuildIndex => UnityEngine.SceneManagement.SceneUtility.GetBuildIndexByScenePath(ScenePath);
9696

97+
98+
public override bool Equals(object obj)
99+
{
100+
if (obj is SceneReference other) {
101+
return Equals(other);
102+
}
103+
104+
return false;
105+
}
106+
107+
public bool Equals(SceneReference other)
108+
{
109+
if (other == null)
110+
return false;
111+
112+
return ScenePath == other.ScenePath;
113+
}
114+
115+
public bool Equals(string scenePath)
116+
{
117+
return ScenePath == scenePath;
118+
}
119+
120+
public override int GetHashCode()
121+
{
122+
return ScenePath?.GetHashCode() ?? 0;
123+
}
124+
125+
public int CompareTo(SceneReference other)
126+
{
127+
if (other == null)
128+
return 1;
129+
130+
return ScenePath.CompareTo(other.ScenePath);
131+
}
132+
97133
public SceneReference() { }
98134

99135
public SceneReference(string scenePath)

0 commit comments

Comments
 (0)