-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetworkMessageID.cs
More file actions
35 lines (26 loc) · 1.07 KB
/
Copy pathNetworkMessageID.cs
File metadata and controls
35 lines (26 loc) · 1.07 KB
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
using System;
using Mirror;
namespace Networking.Shared
{
[Serializable]
public readonly struct NetworkMessageID : IEquatable<NetworkMessageID>
{
public readonly int Value;
public NetworkMessageID(int value)
{
Value = value;
}
public static NetworkMessageID GetID<T>() where T : struct, NetworkMessage
{
string fullName = typeof(T).FullName;
int hash = fullName.GetStableHashCode();
return new NetworkMessageID(hash);
}
public bool Equals(NetworkMessageID other) => Value == other.Value;
public override bool Equals(object obj) => obj is NetworkMessageID other && Equals(other);
public override int GetHashCode() => Value.GetHashCode();
public override string ToString() => $"NetworkMessageID({Value})";
public static bool operator ==(NetworkMessageID left, NetworkMessageID right) => left.Equals(right);
public static bool operator !=(NetworkMessageID left, NetworkMessageID right) => !left.Equals(right);
}
}