public void OnNetworkReceive(NetPeer peer, NetDataReader reader, DeliveryMethod deliveryMethod) { // byte[] raw = new byte[reader.AvailableBytes]; //reader.GetBytes (raw, reader.AvailableBytes); //string str = System.Text.Encoding.ASCII.GetString (raw); //ClientInput input = new ClientInput (); //input.DecodeRawDataFromeString (str); // if (input.ClinetID == _netClient.LocalPort) { // Debug.Log("[YOU] inputed>" + input.ToString()); // } else { // Debug.Log("[OTHER] inputed>"+ input.ToString()); // } byte[] raw = new byte[reader.AvailableBytes]; reader.GetBytes(raw, reader.AvailableBytes); string str = NetdataUltility.DecodeRaw(raw); NetdataUltility.NetdataType dataType = NetdataUltility.NetdataType.UnknownData; string decoded = ""; dataType = NetdataUltility.DepacketData(str, out decoded); switch (dataType) { case NetdataUltility.NetdataType.EventData: NetEvent nEvent = new NetEvent(); nEvent.Decode(decoded); OnNetEvent(nEvent); break; case NetdataUltility.NetdataType.PlayerInputData: ClientInput cInput = new ClientInput(); cInput.Decode(decoded); ExecuteInpute(cInput); break; case NetdataUltility.NetdataType.SyncableData: break; case NetdataUltility.NetdataType.UnknownData: //Maybe drop this data ?? Debug.Log("[GameClient] receved a unknownData form server !"); break; } }
public void Deserialize(byte[] raw) { Decode(NetdataUltility.DecodeRaw(raw)); }