// Use this for initialization void Start() { buff_handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); buff_ptr = GCHandle.ToIntPtr(buff_handle); PacketHeader header; header.nodeSource = 42; header.type = MessageType.PING; SetNodeID sni; sni.Header = header; sni.NET_ID = 69; byte[] bytes = NetEngine.GetBytes <SetNodeID>(sni); PacketHeader deserialized = NetEngine.ByteArrayToStructure <PacketHeader>(bytes); Debug.Log(deserialized.nodeSource); Debug.Log(deserialized.type.ToString()); SetNodeID sni_des = NetEngine.ByteArrayToStructure <SetNodeID>(bytes); Debug.Log(sni_des.NET_ID); Debug.Log(Marshal.SizeOf(sni_des)); Buffer.BlockCopy(bytes, 0, buffer, 0, Marshal.SizeOf(sni_des)); SetNodeID sni_des2 = NetEngine.ByteArrayToStructure <SetNodeID>(buffer); Debug.Log(sni_des2.NET_ID); Debug.Log(Marshal.SizeOf(sni_des2)); }
public override byte[] GetState(out int size) { NetworkState state; PacketHeader packet; packet.type = MessageType.ENTITY_STATE; packet.nodeSource = NetEngine.instance.node_id; state.Header = packet; state.Pos = transform.position; state.Rotation = transform.rotation; state.SimTick = 0; state.NET_ID = NET_ID; size = Marshal.SizeOf(state); return(NetEngine.GetBytes <NetworkState>(state)); }