void DemoLoad(bool forceFromDisk) { // Don't do more than one load/save at a time if (!_isLoading && !_isSaving) { _isLoading = true; // Load the save and handle the results. GameSaveSystem.Load <DemoGameSave>("demosave", forceFromDisk) .OnSuccess(f => { if (f.value.usedBackupFile) { Debug.LogWarning("Load successful, but a backup file was used.", this); } else { Debug.Log("Load successful. Was cached? " + f.value.wasCached, this); } _gameSave = f.value.save; }) .OnError(f => { Debug.LogWarning("Load failed: " + f.error.Message + ". Creating new game save for demo.", this); _gameSave = new DemoGameSave(); }) .OnComplete(f => _isLoading = false); } }
void DemoLoad(bool forceFromDisk) { // Don't do more than one load/save at a time if (!_isLoading && !_isSaving) { _isLoading = true; // Load the save and handle the results. GameSaveSystem.Load<DemoGameSave>("demosave", forceFromDisk) .OnSuccess(f => { if (f.value.usedBackupFile) { Debug.LogWarning("Load successful, but a backup file was used.", this); } else { Debug.Log("Load successful. Was cached? " + f.value.wasCached, this); } _gameSave = f.value.save; }) .OnError(f => { Debug.LogWarning("Load failed: " + f.error.Message + ". Creating new game save for demo.", this); _gameSave = new DemoGameSave(); }) .OnComplete(f => _isLoading = false); } }
void OnGUI() { // Show animated status if loading or saving. if (_isLoading) { GUILayout.Label("Loading" + new string('.', _dotCount)); } else if (_isSaving) { GUILayout.Label("Saving" + new string('.', _dotCount)); } else { // If we have a save, show the text from it and add an option to change the text if (_gameSave != null) { GUILayout.Label("Game save text: " + _gameSave.text); if (GUILayout.Button("Change demo save text")) { _gameSave.text = Guid.NewGuid().ToString(); } } // Show some buttons for playing with the save if (GUILayout.Button("New Save")) { _gameSave = new DemoGameSave(); } if (GUILayout.Button("Load")) { DemoLoad(false); } if (GUILayout.Button("Force Load")) { DemoLoad(true); } if (GUILayout.Button("Load and Fail")) { DemoGameSave.FailNextLoad = true; DemoLoad(true); } if (GUILayout.Button("Save")) { DemoSave(); } if (GUILayout.Button("Save and Fail")) { DemoGameSave.FailNextSave = true; DemoSave(); } } }