Beispiel #1
0
    public void SaveUserDataFile()
    {
        FlatBufferBuilder  fbb            = new FlatBufferBuilder(1024);
        Offset <PlayModel> playModeOffset = new Offset <PlayModel>();

        if (UserData.PlayData != null)
        {
            //lastParts
            int[] lastPartsCells = UserData.PlayData.LastParts.Cells;
            LastPartsModel.StartCellPartsArrayVector(fbb, lastPartsCells.Length);
            for (int i = lastPartsCells.Length - 1; i >= 0; i--)
            {
                fbb.AddInt(lastPartsCells[i]);
            }
            VectorOffset lastPartsCellsOffset = fbb.EndVector();

            LastPartsModel.StartLastPartsModel(fbb);
            LastPartsModel.AddAngleValue(fbb, UserData.PlayData.LastParts.AngleValue);
            LastPartsModel.AddCellPartsArray(fbb, lastPartsCellsOffset);
            Offset <LastPartsModel> lastPartsOffset = LastPartsModel.EndLastPartsModel(fbb);

            //cells
            Offset <int>[] cells = new Offset <int> [UserData.PlayData.LastParts.Cells.Length];

            Offset <CellModel>[] offsetCellModes = new Offset <CellModel> [GameConstants.CELL_ARRAY_SIZE * GameConstants.CELL_ARRAY_SIZE];
            int index = 0;
            for (int i = 0; i < GameConstants.CELL_ARRAY_SIZE; i++)
            {
                for (int j = 0; j < GameConstants.CELL_ARRAY_SIZE; j++)
                {
                    offsetCellModes[index] = CellModel.CreateCellModel(fbb, (short)i, (short)j, UserData.PlayData.Cells[i, j]);
                    index++;
                }
            }

            VectorOffset cellsVectorOffset = PlayModel.CreateCellArrayVector(fbb, offsetCellModes);

            //ItemUserCountArray
            int[] itemUseCountArray = UserData.PlayData.ItemUseCountInfo.ItemUseCountArray;
            PlayModel.StartItemUseCountArrayVector(fbb, itemUseCountArray.Length);
            for (int i = itemUseCountArray.Length - 1; i >= 0; i--)
            {
                Debug.Log((ItemType)i + " - " + itemUseCountArray[i]);
                fbb.AddInt(itemUseCountArray[i]);
            }
            VectorOffset itemUserCountArrayOffset = fbb.EndVector();

            //playmode
            PlayModel.StartPlayModel(fbb);
            PlayModel.AddScore(fbb, UserData.PlayData.Score);
            PlayModel.AddCoin(fbb, UserData.PlayData.Coin);
            PlayModel.AddAdContinueWatchCount(fbb, UserData.PlayData.AdContinueWatchCount);
            PlayModel.AddCellArray(fbb, cellsVectorOffset);
            PlayModel.AddLastPartsData(fbb, lastPartsOffset);
            PlayModel.AddItemUseCountArray(fbb, itemUserCountArrayOffset);
            playModeOffset = PlayModel.EndPlayModel(fbb);
        }

        StringOffset dailyRewardDayOffset   = fbb.CreateString(UserData.UserRewardInfo.DailyRewardDay);
        StringOffset coinBoxRewardDayoffset = fbb.CreateString(UserData.UserRewardInfo.CoinBoxRewardDay);

        UserModel.StartUserModel(fbb);
        UserModel.AddScore(fbb, UserData.Score);
        UserModel.AddCoin(fbb, UserData.Coin);
        UserModel.AddDailyRewardDay(fbb, dailyRewardDayOffset);
        UserModel.AddCoinBoxRewardDay(fbb, coinBoxRewardDayoffset);
        UserModel.AddCointBoxRewardCount(fbb, UserData.UserRewardInfo.CoinBoxRewardCount);
        UserModel.AddCointBoxRewardTimeStamp(fbb, UserData.UserRewardInfo.CointBoxRewardTimeStamp);
        UserModel.AddPlayData(fbb, playModeOffset);
        Offset <UserModel> userModelOffset = UserModel.EndUserModel(fbb);

        fbb.Finish(userModelOffset.Value);

        using (var ms = new MemoryStream(fbb.SizedByteArray()))
        {
            File.WriteAllBytes(GameConstants.SAVEFILE_PATH, ms.ToArray());

            Debug.Log("SaveUserDataFile File Write end ");
        }
    }