Skip to content

Instantly share code, notes, and snippets.

@aevitas
Created March 10, 2020 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aevitas/e0a1b330b0767168416841350ea41a01 to your computer and use it in GitHub Desktop.
Save aevitas/e0a1b330b0767168416841350ea41a01 to your computer and use it in GitHub Desktop.
public static unsafe byte[] WriteVectorBuffer(ref Vector3 vec)
{
Span<byte> buffer = stackalloc byte[sizeof(Vector3)];
fixed (byte* b = buffer)
Unsafe.Write(b, vec);
return buffer.ToArray();
}
public static unsafe Vector3 ReadVector(Span<byte> buffer)
{
fixed (byte* b = buffer)
return Unsafe.Read<Vector3>(b);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment