コード例 #1
0
    static bool SaveBlackSaveData(BlackSaveData blackSaveData)
    {
        //ConDebug.LogFormat("Start Saving JSON Data: {0}", JsonUtility.ToJson(blackSaveData));
        var saveDataArray = MessagePackSerializer.Serialize(blackSaveData, Data.DefaultOptions);

        ConDebug.LogFormat("Saving path: {0}", SaveFileName);
        if (lastSaveDataArray != null && lastSaveDataArray.SequenceEqual(saveDataArray))
        {
            ConDebug.LogFormat("Saving skipped since there is no difference made compared to last time saved.");
        }
        else
        {
            try
            {
                // 진짜 쓰자!!
                WriteAllBytesAtomically(SaveFileName, saveDataArray);

                // 마지막 저장 데이터 갱신
                lastSaveDataArray = saveDataArray;
                ConDebug.Log($"{SaveFileName} Saved. (written to disk)");

                // 유저 서비스를 위해 필요할 수도 있으니까 개발 중일 때는 base64 인코딩 버전 세이브 파일도 저장한다.
                // 실서비스 버전에서는 불필요한 기능이다.
                if (Application.isEditor)
                {
                    var base64Path = SaveFileName + ".base64.txt";
                    ConDebug.LogFormat("Saving path (base64): {0}", base64Path);
                    File.WriteAllText(base64Path, Convert.ToBase64String(saveDataArray));
                    ConDebug.Log($"{base64Path} Saved. (written to disk)");
                }

                IncreaseSaveDataSlotAndWrite();
                var lastBlackLevel = blackSaveData.lastClearedStageId;
                var gem            = (blackSaveData.freeGemScUInt128 + blackSaveData.paidGemScUInt128).ToUInt128()
                                     .ToClampedLong();
                BlackLogManager.Add(BlackLogEntry.Type.GameSaved, lastBlackLevel, gem);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                Debug.LogError("Writing to disk failed!!!");
                ConfirmPopup.instance.Open("Writing to disk failed!!!");
                BlackLogManager.Add(BlackLogEntry.Type.GameSaveFailure, 0, 0);
                return(false);
            }
        }

        return(true);
    }
コード例 #2
0
    public static bool Save(IBlackContext context, ConfigPopup configPopup, Sound sound, Data data, StageSaveData wipStageSaveData)
    {
        // 에디터에서 간혹 게임 플레이 시작할 때 Load도 호출되기도 전에 Save가 먼저 호출되기도 한다.
        // (OnApplicationPause 통해서)
        // 실제 기기에서도 이럴 수 있나? 이러면 망인데...
        // 그래서 플래그를 하나 추가한다. 이 플래그는 로드가 제대로 한번 됐을 때 true로 변경된다.
        if (context == null || context.LoadedAtLeastOnce == false)
        {
            Debug.LogWarning(
                "****** Save() called before first Load(). There might be an error during Load(). Save() will be skipped to prevent losing your save data.");
            return(false);
        }

        var blackSaveData = new BlackSaveData
        {
            version                  = LatestVersion,
            lastClearedStageId       = BlackContext.instance.LastClearedStageId,
            lastClearedStageIdEvent  = BlackContext.instance.LastClearedStageIdEvent,
            goldScUInt128            = BlackContext.instance.Gold,
            clearedDebrisIndexList   = BlackContext.instance.GetDebrisState(),
            pendingGoldScUInt128     = BlackContext.instance.PendingGold,
            bgmAudioVolume           = 1.0f,
            sfxAudioVolume           = 1.0f,
            muteBgmAudioSource       = Sound.instance.BgmAudioSourceActive == false,
            muteSfxAudioSource       = Sound.instance.SfxAudioSourceActive == false,
            maxBlackLevelGathered    = BlackContext.instance.AchievementGathered.MaxBlackLevel,
            maxBlackLevelRedeemed    = BlackContext.instance.AchievementRedeemed.MaxBlackLevel,
            maxColoringComboGathered = BlackContext.instance.AchievementGathered.MaxColoringCombo,
            maxColoringComboRedeemed = BlackContext.instance.AchievementRedeemed.MaxColoringCombo,
            //stageLockRemainTime = StageDetail.instance.StageLockDetailTime,
            wipStageSaveData = wipStageSaveData,
            performanceMode  = ConfigPopup.instance.IsPerformanceModeOn,
        };

        return(SaveBlackSaveData(blackSaveData));
    }