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; } } } } }
protected abstract void OnSyncedDataReceived(TSPlayer player, SyncedData[] data);
protected abstract void OnSyncedDataReceived(TSPlayer player, List <SyncedData> data);
protected override void OnSyncedDataReceived(TSPlayer player, List <SyncedData> data) { player.AddDataRollback(data); }
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; } } } } }