private void OnEventDataReceived(byte eventCode, object content) { bool flag = eventCode == 199; if (flag) // 接收操作数据 { byte[] data = content as byte[]; List <SyncedData> list = SyncedData.Decode(data); // 解码 bool flag2 = list.Count > 0; if (flag2) // 有数据 { TSPlayer tSPlayer = this.players[list[0].inputData.ownerID]; // 找到对应的玩家 bool flag3 = !tSPlayer.dropped; if (flag3) // 该玩家没有掉线 { this.OnSyncedDataReceived(tSPlayer, list); // 处理同步数据 bool flag4 = list[0].dropPlayer && tSPlayer.ID != this.localPlayer.ID && !this.players[list[0].dropFromPlayerId].dropped; if (flag4) { tSPlayer.dropCount++; // 统计掉线玩家数量 } } else // 该玩家掉线了,回收数据对象 { int i = 0; int count = list.Count; while (i < count) { SyncedData.pool.GiveBack(list[i]); i++; } } SyncedData.poolList.GiveBack(list); } } else { bool flag5 = eventCode == 198; if (flag5) { byte[] infoBytes = content as byte[]; this.OnChecksumReceived(SyncedInfo.Decode(infoBytes)); } else { bool flag6 = eventCode == 197; if (flag6) { byte[] array = content as byte[]; bool flag7 = array.Length != 0; if (flag7) { bool flag8 = array[0] == 0; if (flag8) { this.Pause(); } else { bool flag9 = array[0] == 1; if (flag9) { this.Run(); } else { bool flag10 = array[0] == 3; if (flag10) { this.End(); } } } } } else { bool flag11 = eventCode == 196; if (flag11) { byte[] infoBytes2 = content as byte[]; SyncedInfo syncedInfo = SyncedInfo.Decode(infoBytes2); this.players[syncedInfo.playerId].sentSyncedStart = true; } } } } }
private void OnEventDataReceived(byte eventCode, object content) { // 199 bool flag = eventCode == SEND_CODE; if (flag) { byte[] data = content as byte[]; List <SyncedData> list = SyncedData.Decode(data); bool flag2 = list.Count > 0; if (flag2) { TSPlayer tSPlayer = this.players[list[0].inputData.ownerID]; bool flag3 = !tSPlayer.dropped; if (flag3) { this.OnSyncedDataReceived(tSPlayer, list); bool flag4 = list[0].dropPlayer && tSPlayer.ID != this.localPlayer.ID && !this.players[list[0].dropFromPlayerId].dropped; if (flag4) { tSPlayer.dropCount++; } } else { int i = 0; int count = list.Count; while (i < count) { SyncedData.pool.GiveBack(list[i]); i++; } } SyncedData.poolList.GiveBack(list); } } else { // 198 bool flag5 = eventCode == CHECKSUM_CODE; if (flag5) { byte[] infoBytes = content as byte[]; this.OnChecksumReceived(SyncedInfo.Decode(infoBytes)); } else { // 197 bool flag6 = eventCode == SIMULATION_CODE; if (flag6) { byte[] array = content as byte[]; bool flag7 = array.Length != 0; if (flag7) { bool flag8 = array[0] == 0; if (flag8) { this.Pause(); } else { bool flag9 = array[0] == 1; if (flag9) { this.Run(); } else { bool flag10 = array[0] == 3; if (flag10) { this.End(); } } } } } else { // 196 bool flag11 = eventCode == SYNCED_GAME_START_CODE; if (flag11) { byte[] infoBytes2 = content as byte[]; SyncedInfo syncedInfo = SyncedInfo.Decode(infoBytes2); this.players[syncedInfo.playerId].sentSyncedStart = true; } } } } }
private void OnEventDataReceived(byte eventCode, object content) { bool flag = eventCode == 199; if (flag) { byte[] data = content as byte[]; SyncedData[] array = SyncedData.Decode(data); bool flag2 = array.Length != 0; if (flag2) { TSPlayer tSPlayer = this.players[array[0].inputData.ownerID]; bool flag3 = !tSPlayer.dropped; if (flag3) { this.OnSyncedDataReceived(tSPlayer, array); bool flag4 = array[0].dropPlayer && tSPlayer.ID != this.localPlayer.ID && !this.players[array[0].dropFromPlayerId].dropped; if (flag4) { tSPlayer.dropCount++; } } } } else { bool flag5 = eventCode == 198; if (flag5) { byte[] infoBytes = content as byte[]; this.OnChecksumReceived(SyncedInfo.Decode(infoBytes)); } else { bool flag6 = eventCode == 197; if (flag6) { byte[] array2 = content as byte[]; bool flag7 = array2.Length != 0; if (flag7) { bool flag8 = array2[0] == 0; if (flag8) { this.Pause(); } else { bool flag9 = array2[0] == 1; if (flag9) { this.Run(); } else { bool flag10 = array2[0] == 3; if (flag10) { this.End(); } } } } } else { bool flag11 = eventCode == 196; if (flag11) { byte[] infoBytes2 = content as byte[]; SyncedInfo syncedInfo = SyncedInfo.Decode(infoBytes2); this.players[syncedInfo.playerId].sentSyncedStart = true; } } } } }
/// <summary> /// 接收网络数据 /// </summary> /// <param name="eventCode"></param> /// <param name="content"></param> private void OnEventDataReceived(byte eventCode, object content) { if (eventCode == SEND_CODE) { byte[] data = content as byte[]; //一次只接收一个玩家的数据 List <SyncedData> list = SyncedData.Decode(data); //目前该list的容量是1,并且该list是由SyncedData.poolList.GetNew();来创建的,所以后面要用SyncedData.pool.GiveBack来销毁 //注意list是网络数据 if (list.Count > 0) { //取出对应的远端玩家数据来更新 TSPlayer tSPlayer = this.players[list[0].inputData.ownerID]; if (!tSPlayer.dropped) { this.OnSyncedDataReceived(tSPlayer, list); //调用TSPlayer.controls添加数据 //满足三个条件,dropCount才可以增加 //网络数据的dropPlayer必须为true,网络过来的玩家不是本地玩家,提取网络数据中的dropFromPlayerId,查找players,其对应的dropped为false //这里有dropPlayer dropped dropFromPlayerId 需要理解区分 if (list[0].dropPlayer && tSPlayer.ID != this.localPlayer.ID && !this.players[list[0].dropFromPlayerId].dropped) { tSPlayer.dropCount++; } } else { int i = 0; int count = list.Count; while (i < count) { SyncedData.pool.GiveBack(list[i]); //掉线直接回收 i++; } } SyncedData.poolList.GiveBack(list); } } else { bool flag5 = eventCode == CHECKSUM_CODE; if (flag5) { byte[] infoBytes = content as byte[]; this.OnChecksumReceived(SyncedInfo.Decode(infoBytes)); } else { //197事件,内容只有3种:0:pause,1:Run,3:End if (eventCode == SIMULATION_CODE) { byte[] array = content as byte[]; if (array.Length != 0) { switch (array[0]) { case 0: this.Pause(); break; case 1: Run(); break; case 3: End(); break; } } } //196事件 远程玩家准备好事件 else { //远程玩家准备好事件 if (eventCode == SYNCED_GAME_START_CODE) { byte[] infoBytes2 = content as byte[]; SyncedInfo syncedInfo = SyncedInfo.Decode(infoBytes2); this.players[syncedInfo.playerId].sentSyncedStart = true; //玩家准备好标志 } } } } }
private void OnEventDataReceived(byte eventCode, object content) { Debug.LogFormat("OnEventDataReceived eventCode is {0}", eventCode); if (eventCode == SEND_CODE) { byte[] data = content as byte[]; List <SyncedData> list = SyncedData.Decode(data);//只有list[0]是携带玩家ownerID数据,剩余的list都是该玩家的数据 if (list.Count > 0) { TSPlayer tSPlayer = players[list[0].inputData.ownerID]; if (!tSPlayer.dropped) { OnSyncedDataReceived(tSPlayer, list);//调用TSPlayer.addData添加数据 //满足三个条件,dropCount才可以增加 //网络数据的dropPlayer必须为true,网络过来的玩家不是本地玩家,提取网络数据中的dropFromPlayerId,查找players,其对应的dropped为false //这里有dropPlayer dropped dropFromPlayerId 需要理解区分 if (list[0].dropPlayer && tSPlayer.ID != localPlayer.ID && !players[list[0].dropFromPlayerId].dropped) { tSPlayer.dropCount++; } } else { int i = 0; int count = list.Count; while (i < count) { SyncedData.pool.GiveBack(list[i]); i++; } } SyncedData.poolList.GiveBack(list); } } else { if (eventCode == CHECKSUM_CODE) { byte[] infoBytes = content as byte[]; this.OnChecksumReceived(SyncedInfo.Decode(infoBytes)); } else { if (eventCode == SIMULATION_CODE) { byte[] array = content as byte[]; if (array.Length != 0) { if (array[0] == 0) { Pause(); } else { if (array[0] == 1) { Run(); } else { if (array[0] == 3) { End(); } } } } } else { if (eventCode == SYNCED_GAME_START_CODE) { byte[] infoBytes2 = content as byte[]; SyncedInfo syncedInfo = SyncedInfo.Decode(infoBytes2); players[syncedInfo.playerId].sentSyncedStart = true; } } } } }