protected static void HandleSendInput(byte[] mInput) { SerializableInput nInput = mInput.DeserializeObject <SerializableInput>(); //=================================================================== SerializableVector3 nVelocity = nInput.Vector; //=================================================================== Vector3 velocity = new Vector3(nVelocity.x, nVelocity.y, nVelocity.z); //=================================================================== //Neutron.Enqueue(() => playerRB.velocity = velocity); }
public static void OnUDPReceive(IAsyncResult ia) { try { byte[] data = _UDPSocket.EndReceive(ia, ref _IEPRef); //==============================================================================================\\ _UDPSocket.BeginReceive(OnUDPReceive, null); //==============================================================================================\\ if (data.Length > 0) { byte[] decompressedBuffer = data.Decompress(COMPRESSION_MODE, data.Length); //==================================================================================\\ using (NeutronReader mReader = new NeutronReader(decompressedBuffer)) { Packet mCommand = mReader.ReadPacket <Packet>(); switch (mCommand) { case Packet.SendInput: SerializableInput nInput = mReader.ReadBytes(2048).DeserializeObject <SerializableInput>(); //================================================================================================================================ SerializableVector3 nVelocity = nInput.Vector; //================================================================================================================================ Vector3 velocity = new Vector3(nVelocity.x, nVelocity.y, nVelocity.z); //================================================================================================================================ //Neutron.Enqueue(() => playerRB.velocity = velocity); break; case Packet.RPC: HandleRPC(mReader.ReadInt32(), mReader.ReadBytes(4096)); break; case Packet.VoiceChat: HandleVoiceChat(mReader.ReadInt32(), mReader.ReadBytes(4096)); break; } } } else { LoggerError("UDP Error"); } } catch (SocketException ex) { LoggerError(ex.Message + ":" + ex.ErrorCode); } }
protected void HandleSendInput(Player mSender, Packet mCommand, byte[] Input) { try { if (mSender.IsInChannel()) { Player playerToMove = mSender; //============================================================================================\\ SerializableInput authInput = Input.DeserializeObject <SerializableInput>(); //============================================================================================\\ Rigidbody rbPlayer = playersState[playerToMove.tcpClient].rigidBody; //============================================================================================\\ Vector3 newPos = new Vector3(authInput.Horizontal, 0, authInput.Vertical); //============================================================================================\\ Enqueue(() => { rbPlayer.velocity = (newPos * MOVE_SPEED * Time.deltaTime); //============================================================================================\\ Vector3 velocity = rbPlayer.velocity; //============================================================================================\\ SerializableInput nInput = new SerializableInput(authInput.Horizontal, authInput.Vertical, new SerializableVector3(velocity.x, velocity.y, velocity.z)); //============================================================================================\\ using (NeutronWriter writer = new NeutronWriter()) { writer.WritePacket(mCommand); writer.Write(nInput.Serialize()); //============================================================================================\\ //SendTCP(mSender.tcpClient, SendTo.Only, writer.GetBuffer()); } }, ref monoBehaviourActions); } else { SendErrorMessage(mSender, Packet.SendChat, "ERROR: You are not on a channel/room."); } } catch { Debug.LogError("Corrupted Bytes"); } }
public ScriptManagerData() { Input = new SerializableInput(); }