Example #1
0
    protected override void HandleMsg(EPhotonMsg pReceivedMsg, object[] pParams, ByteBuffer bb)
    {
        switch (pReceivedMsg)
        {
        case EPhotonMsg.MainMenu_SyncGameInfo:

            GameInitInfoS infoS    = GameInitInfoS.GetRootAsGameInitInfoS(bb);
            GameInitInfo  gameInfo = GameInitInfo.Deserialize(infoS);
            Debug.Log(gameInfo);

            //reset current game info - DONT assign it
            //it will be set from UI elements
            brainiacs.GameInitInfo = new GameInitInfo();
            mainMenu.GameSetup.OpenMain(gameInfo);
            break;

        case EPhotonMsg.MainMenu_SyncPlayerInfo:
            PlayerInitInfoS playerInfoS = PlayerInitInfoS.GetRootAsPlayerInitInfoS(bb);
            PlayerInitInfo  playerInfo  = PlayerInitInfo.Deserialize(playerInfoS);
            mainMenu.GameSetup.SetupMain.UpdatePlayer(playerInfo);
            break;

        case EPhotonMsg.None:
        default:
            Debug.LogError("Message not handled");

            break;
        }
    }
Example #2
0
    //http://google.github.io/flatbuffers/flatbuffers_guide_tutorial.html
    internal byte[] Serialize()
    {
        FlatBufferBuilder fbb = new FlatBufferBuilder(1);

        //serialize players
        GameInitInfoS.StartPlayersVector(fbb, Players.Count);
        var playersOffset = new Offset <PlayerInitInfoS> [Players.Count];

        for (int i = 0; i < Players.Count; i++)
        {
            playersOffset[i] = Players[i].Create(ref fbb);
        }
        //nested tables needs to be CREATED before START
        VectorOffset playersVectorOffset = GameInitInfoS.CreatePlayersVector(fbb, playersOffset);

        //serialize whole game init info
        GameInitInfoS.StartGameInitInfoS(fbb);

        GameInitInfoS.AddMode(fbb, (int)Mode);
        GameInitInfoS.AddMap(fbb, (int)Map);
        GameInitInfoS.AddGameModeValue(fbb, GameModeValue);
        GameInitInfoS.AddPlayers(fbb, playersVectorOffset);

        Offset <GameInitInfoS> gameInfoOffset = GameInitInfoS.EndGameInitInfoS(fbb);

        fbb.Finish(gameInfoOffset.Value);
        byte[] result = fbb.SizedByteArray();
        return(result);
    }
Example #3
0
 public static Offset <GameInitInfoS> CreateGameInitInfoS(FlatBufferBuilder builder,
                                                          int mode                   = 0,
                                                          int map                    = 0,
                                                          int gameModeValue          = 0,
                                                          VectorOffset playersOffset = default(VectorOffset))
 {
     builder.StartTable(4);
     GameInitInfoS.AddPlayers(builder, playersOffset);
     GameInitInfoS.AddGameModeValue(builder, gameModeValue);
     GameInitInfoS.AddMap(builder, map);
     GameInitInfoS.AddMode(builder, mode);
     return(GameInitInfoS.EndGameInitInfoS(builder));
 }
Example #4
0
    internal static GameInitInfo Deserialize(GameInitInfoS pGameInfoS)
    {
        GameInitInfo gameInfo = new GameInitInfo();

        gameInfo.Mode          = (EGameMode)pGameInfoS.Mode;
        gameInfo.Map           = (EMap)pGameInfoS.Map;
        gameInfo.GameModeValue = pGameInfoS.GameModeValue;
        for (int i = 0; i < pGameInfoS.PlayersLength; i++)
        {
            PlayerInitInfoS?playerS = pGameInfoS.Players(i);
            if (playerS != null)
            {
                gameInfo.AddPlayer(PlayerInitInfo.Deserialize((PlayerInitInfoS)playerS));
            }
        }
        return(gameInfo);
    }
Example #5
0
 public static GameInitInfoS GetRootAsGameInitInfoS(ByteBuffer _bb, GameInitInfoS obj)
 {
     return(obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb));
 }