This repository has been archived by the owner on Jan 18, 2022. It is now read-only.
/
EntityId.cs
86 lines (76 loc) · 2.37 KB
/
EntityId.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;
namespace Improbable.Gdk.Core
{
/// <summary>
/// A unique identifier used to look up an entity in SpatialOS.
/// </summary>
/// <remarks>
/// Instances of this type should be treated as transient identifiers that will not be
/// consistent between different runs of the same simulation.
/// </remarks>
public struct EntityId : IEquatable<EntityId>
{
/// <summary>
/// The value of the EntityId.
/// </summary>
/// <remarks>
/// Though this value is numeric, you should not perform any mathematical operations on it.
/// </remarks>
public readonly long Id;
/// <summary>
/// Constructs a new instance of an EntityId.
/// </summary>
public EntityId(long id)
{
Id = id;
}
/// <summary>
/// Whether this represents a valid SpatialOS entity ID. Specifically, <code>Id > 0</code>.
/// </summary>
/// <returns>True iff valid.</returns>
public bool IsValid()
{
return Id > 0;
}
/// <inheritdoc cref="IEquatable{T}" />
public override bool Equals(object obj)
{
if (!(obj is EntityId))
{
return false;
}
return Equals((EntityId) obj);
}
/// <inheritdoc cref="IEquatable{T}" />
public bool Equals(EntityId obj)
{
return Id.Equals(obj.Id);
}
/// <summary>
/// Returns true if entityId1 is exactly equal to entityId2.
/// </summary>
public static bool operator ==(EntityId entityId1, EntityId entityId2)
{
return entityId1.Equals(entityId2);
}
/// <summary>
/// Returns true if entityId1 is not exactly equal to entityId2.
/// </summary>
public static bool operator !=(EntityId entityId1, EntityId entityId2)
{
return !entityId1.Equals(entityId2);
}
/// <inheritdoc cref="object" />
public override int GetHashCode()
{
var res = 1327;
res = res * 977 + Id.GetHashCode();
return res;
}
/// <inheritdoc cref="object" />
public override string ToString()
{
return Id.ToString();
}
}
}