internal byte[] Serialize() { FlatBufferBuilder fbb = new FlatBufferBuilder(1); //serialize players GameResultInfoS.StartPlayerResultsVector(fbb, PlayerResults.Count); var playersOffset = new Offset <PlayerResultInfoS> [PlayerResults.Count]; for (int i = 0; i < PlayerResults.Count; i++) { playersOffset[i] = PlayerResults[i].Create(ref fbb); } //nested tables needs to be CREATED before START VectorOffset playersVectorOffset = GameResultInfoS.CreatePlayerResultsVector(fbb, playersOffset); //serialize whole game init info GameResultInfoS.StartGameResultInfoS(fbb); GameResultInfoS.AddPlayTime(fbb, PlayTime); GameResultInfoS.AddPlayerResults(fbb, playersVectorOffset); Offset <GameResultInfoS> gameResultInfoOffset = GameResultInfoS.EndGameResultInfoS(fbb); fbb.Finish(gameResultInfoOffset.Value); byte[] result = fbb.SizedByteArray(); return(result); }
protected override void HandleMsg(EPhotonMsg pReceivedMsg, object[] pParams, ByteBuffer bb) { //Debug.Log($"Game HandleMsg {pReceivedMsg}"); switch (pReceivedMsg) { case EPhotonMsg.Game_PlayerLoadedScene: if (!PhotonNetwork.IsMasterClient) { Debug.LogError("Only master should receive PlayerLoadedScene"); return; } PhotonPlayer player = PhotonNetwork.CurrentRoom.GetPlayer((int)pParams[0]); Debug.Log(player + " loaded game"); game.PlayerManager.OnRemotePlayerLoadedScene(player); break; //case EPhotonMsg.Game_Activate: // game.Activate(); // break; case EPhotonMsg.Game_Ui_ShowTimeValue: int timeValue = (int)pParams[0]; game.UIGameTime.ShowTimeValue(timeValue); break; case EPhotonMsg.Game_UpdatePlayerScore: int playerNumber = (int)pParams[0]; int kills = (int)pParams[1]; int deaths = (int)pParams[2]; game.Results.UpdatePlayerScore(playerNumber, kills, deaths); break; case EPhotonMsg.Game_EndGame: GameResultInfoS infoS = GameResultInfoS.GetRootAsGameResultInfoS(bb); GameResultInfo gameResultInfo = GameResultInfo.Deserialize(infoS); Debug.Log("Game_SetGameResultInfo"); Debug.Log(gameResultInfo); game.GameEnd.OnReceiveEndGame(gameResultInfo); break; case EPhotonMsg.Game_Lighting_SetMode: bool night = (bool)pParams[0]; game.Lighting.SetMode(night); break; case EPhotonMsg.Game_HandleEffect: EGameEffect effect = (EGameEffect)pParams[0]; game.GameEffect.HandleEffect(effect); break; default: Debug.LogError("Message not handled"); break; } }
public static Offset <GameResultInfoS> CreateGameResultInfoS(FlatBufferBuilder builder, int playTime = 0, VectorOffset playerResultsOffset = default(VectorOffset)) { builder.StartTable(2); GameResultInfoS.AddPlayerResults(builder, playerResultsOffset); GameResultInfoS.AddPlayTime(builder, playTime); return(GameResultInfoS.EndGameResultInfoS(builder)); }
internal static GameResultInfo Deserialize(GameResultInfoS pInfoS) { GameResultInfo gameResultInfo = new GameResultInfo(); gameResultInfo.PlayTime = pInfoS.PlayTime; for (int i = 0; i < pInfoS.PlayerResultsLength; i++) { PlayerResultInfoS?playerS = pInfoS.PlayerResults(i); if (playerS != null) { gameResultInfo.PlayerResults.Add(PlayerScoreInfo.Deserialize((PlayerResultInfoS)playerS)); } } return(gameResultInfo); }
public static GameResultInfoS GetRootAsGameResultInfoS(ByteBuffer _bb, GameResultInfoS obj) { return(obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); }