transformInfo ByteArrayToNewStuff(byte[] bytes) { GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned); transformInfo stuff = (transformInfo)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(transformInfo)); handle.Free(); return(stuff); }
byte[] getBytes(transformInfo str) { int size = Marshal.SizeOf(str); byte[] arr = new byte[size]; IntPtr ptr = Marshal.AllocHGlobal(size); Marshal.StructureToPtr(str, ptr, true); Marshal.Copy(ptr, arr, 0, size); Marshal.FreeHGlobal(ptr); return(arr); }
private void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.isWriting) { transformInfo myTransform; myTransform.myPos = transform.position; myTransform.spriteRotation = playerSprite.transform.localRotation; myTransform.mp = mp; stream.SendNext(getBytes(myTransform)); } else { newInfo = ByteArrayToNewStuff((byte[])stream.ReceiveNext()); } }