You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
928 B
C#
31 lines
928 B
C#
1 week ago
|
using System;
|
||
|
using Unity.Netcode;
|
||
|
|
||
|
namespace Unity.BossRoom.Infrastructure
|
||
|
{
|
||
|
public struct NetworkGuid : INetworkSerializeByMemcpy
|
||
|
{
|
||
|
public ulong FirstHalf;
|
||
|
public ulong SecondHalf;
|
||
|
}
|
||
|
|
||
|
public static class NetworkGuidExtensions
|
||
|
{
|
||
|
public static NetworkGuid ToNetworkGuid(this Guid id)
|
||
|
{
|
||
|
var networkId = new NetworkGuid();
|
||
|
networkId.FirstHalf = BitConverter.ToUInt64(id.ToByteArray(), 0);
|
||
|
networkId.SecondHalf = BitConverter.ToUInt64(id.ToByteArray(), 8);
|
||
|
return networkId;
|
||
|
}
|
||
|
|
||
|
public static Guid ToGuid(this NetworkGuid networkId)
|
||
|
{
|
||
|
var bytes = new byte[16];
|
||
|
Buffer.BlockCopy(BitConverter.GetBytes(networkId.FirstHalf), 0, bytes, 0, 8);
|
||
|
Buffer.BlockCopy(BitConverter.GetBytes(networkId.SecondHalf), 0, bytes, 8, 8);
|
||
|
return new Guid(bytes);
|
||
|
}
|
||
|
}
|
||
|
}
|