SyncVarGameObject/NetworkBehaviour/NetworkIdentity .Equals/.GetHashCode too

This commit is contained in:
vis2k 2022-02-01 12:41:09 +08:00
parent f03dd3f8b8
commit 0fd0aa2135
3 changed files with 12 additions and 0 deletions

View File

@ -127,5 +127,9 @@ static GameObject GetGameObject(uint netId)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(GameObject a, SyncVarGameObject b) => !(a == b);
// if we overwrite == operators, we also need to overwrite .Equals.
public override bool Equals(object obj) => obj is SyncVarGameObject value && this == value;
public override int GetHashCode() => Value.GetHashCode();
}
}

View File

@ -80,6 +80,10 @@ public SyncVarNetworkBehaviour(T value = null)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(NetworkBehaviour a, SyncVarNetworkBehaviour<T> b) => !(a == b);
// if we overwrite == operators, we also need to overwrite .Equals.
public override bool Equals(object obj) => obj is SyncVarNetworkBehaviour<T> value && this == value;
public override int GetHashCode() => Value.GetHashCode();
// helper functions to get/set netId, componentIndex from ulong
internal static ulong Pack(uint netId, byte componentIndex)
{

View File

@ -102,5 +102,9 @@ public SyncVarNetworkIdentity(NetworkIdentity value = null)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(NetworkIdentity a, SyncVarNetworkIdentity b) => !(a == b);
// if we overwrite == operators, we also need to overwrite .Equals.
public override bool Equals(object obj) => obj is SyncVarNetworkIdentity value && this == value;
public override int GetHashCode() => Value.GetHashCode();
}
}