Skip to content

Commit 5121411

Browse files
authored
Merge pull request #13 from AnnulusGames/implement-iequatable
Change: implements IEquatable<T>
2 parents 780e4ce + 27fa687 commit 5121411

3 files changed

Lines changed: 46 additions & 3 deletions

File tree

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1+
using System;
2+
13
namespace Arch.Unity.Conversion
24
{
3-
public readonly struct GameObjectDisabled { }
5+
public readonly struct GameObjectDisabled : IEquatable<GameObjectDisabled>
6+
{
7+
public bool Equals(GameObjectDisabled other) => true;
8+
public override bool Equals(object obj) => obj is GameObjectDisabled;
9+
public override int GetHashCode() => 0;
10+
public override string ToString() => "()";
11+
}
412
}
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
1+
using System;
12
using UnityEngine;
23

34
namespace Arch.Unity.Conversion
45
{
5-
public readonly struct GameObjectReference
6+
public readonly struct GameObjectReference : IEquatable<GameObjectReference>
67
{
78
public GameObjectReference(GameObject gameObject)
89
{
910
this.GameObject = gameObject;
1011
}
1112

1213
public readonly GameObject GameObject;
14+
15+
public bool Equals(GameObjectReference other)
16+
{
17+
return other.GameObject == GameObject;
18+
}
19+
20+
public override bool Equals(object obj)
21+
{
22+
if (obj is GameObjectReference reference) return Equals(reference);
23+
return false;
24+
}
25+
26+
public override int GetHashCode()
27+
{
28+
return GameObject.GetHashCode();
29+
}
1330
}
1431
}
Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
1+
using System;
2+
13
namespace Arch.Unity.Toolkit
24
{
3-
public struct SystemState
5+
public struct SystemState : IEquatable<SystemState>
46
{
57
public float DeltaTime;
68
public double Time;
9+
10+
public readonly bool Equals(SystemState other)
11+
{
12+
return other.DeltaTime == DeltaTime && other.Time == Time;
13+
}
14+
15+
public override readonly bool Equals(object obj)
16+
{
17+
if (obj is SystemState state) return Equals(state);
18+
return false;
19+
}
20+
21+
public override readonly int GetHashCode()
22+
{
23+
return HashCode.Combine(DeltaTime, Time);
24+
}
725
}
826
}

0 commit comments

Comments
 (0)