// 新建任务 void NewTask(SaveTask.Type type, Save save, IStorageTarget target) { if (_disposed) { throw new Exception("SaveManager had already disposed."); } var task = new SaveTask() { type = type, save = save, target = target, }; // 前期处理 switch (type) { case SaveTask.Type.Save: task.exception = save.ToBytes(out task.data); break; default: task.data = null; task.exception = null; break; } _tasks.Enqueue(task); // 第一个任务需要主动唤起处理线程 if (_tasks.Count == 1) { OnBeginTask(_tasks.Peek()); } }
void Start() { instance = this; // GameSave var gameSavables = new IBinarySavable[] { Player.instance, }; gameSave = new BinarySavableCollection(gameSavables); // Settings var settingsSavables = new ITextSavable[] { new TextSavableField ( "Quality Level", t => QualitySettings.SetQualityLevel(int.Parse(t)), w => w.Write(QualitySettings.GetQualityLevel()), () => QualitySettings.SetQualityLevel(0) ), new TextSavableField ( "Audio Volume", t => AudioListener.volume = float.Parse(t), w => w.Write(AudioListener.volume), () => AudioListener.volume = 1 ), }; settings = new TextSavableCollection(settingsSavables); // platform-dependent #if UNITY_PS4 var saveManager = new PS4SaveManager(); gameSaveTarget = new PS4StorageTarget("TestGameSave.bin"); gameSaveManager = saveManager; settingsTarget = new PS4StorageTarget("TestSettings.txt"); settingsManager = saveManager; #else // Standalone #if STEAM gameSaveTarget = new SteamStorageTarget("TestGameSave.bin"); gameSaveManager = new SteamSaveManager(); settingsTarget = new FileStorageTarget("TestSettings.txt"); settingsManager = new BackgroundThreadSaveManager(); #else // File System var saveManager = new BackgroundThreadSaveManager(); gameSaveTarget = new FileStorageTarget("TestGameSave.bin"); gameSaveManager = saveManager; settingsTarget = new FileStorageTarget("TestSettings.txt"); settingsManager = saveManager; #endif #endif }
public string GetPath(IStorageTarget storeTarget, Language language, string modelType, int version, string tag, bool compressed) { string path = storeTarget.GetPath(BasePath, language, PathExtensions.GetValidPathName(modelType), version, tag); tag = PathExtensions.GetValidFileName(tag); return(Path.Combine(path, (string.IsNullOrWhiteSpace(tag) ? $"model-v{version:000000}.bin" : $"model-{tag}-v{version:000000}.bin") + (compressed ? "z" : ""))); }
/// <summary> /// 创建一个删除操作 /// </summary> /// <param name="target"></param> /// <returns></returns> public static SaveTask CreateDeleteTask(IStorageTarget target) { SaveTask saveTask = new SaveTask(); saveTask.type = TaskType.DELETE; saveTask.target = target; return(saveTask); }
/// <summary> /// 创建一个保存操作 /// </summary> /// <param name="target"></param> /// <param name="data"></param> /// <returns></returns> public static SaveTask CreateSaveTask(IStorageTarget target, byte[] data) { SaveTask saveTask = new SaveTask(); saveTask.type = TaskType.SAVE; saveTask.target = target; saveTask.data = data; return(saveTask); }
/// <summary> /// 创建一个加载操作 /// </summary> /// <param name="source"></param> /// <param name="target"></param> /// <returns></returns> public static SaveTask CreateLoadTask(IStorageSource source, IStorageTarget target) { SaveTask saveTask = new SaveTask(); saveTask.type = TaskType.LOAD; saveTask.source = source; saveTask.target = target; return(saveTask); }
private void cmbTargetStorage_SelectedIndexChanged(object sender, EventArgs e) { ComboBox cmbSender = (ComboBox)sender; if (_TargetDisk != null) { if (_TargetDisk.TargetStorage == null && cmbSender.SelectedItem != null) { if (cmbSender.SelectedItem.GetType() == typeof(Azure.MigrationTarget.StorageAccount)) { _TargetDisk.TargetStorage = (Azure.MigrationTarget.StorageAccount)cmbSender.SelectedItem; } else if (cmbSender.SelectedItem.GetType() == typeof(Azure.Arm.StorageAccount)) { _TargetDisk.TargetStorage = (Azure.Arm.StorageAccount)cmbSender.SelectedItem; } } if (_TargetDisk.TargetStorage.GetType() == typeof(Azure.MigrationTarget.ManagedDiskStorage)) { ManagedDiskStorage managedDiskStorage = (ManagedDiskStorage)_TargetDisk.TargetStorage; if (cmbSender.SelectedItem.ToString() == "Premium_LRS") { managedDiskStorage.StorageAccountType = StorageAccountType.Premium_LRS; } else { managedDiskStorage.StorageAccountType = StorageAccountType.Standard_LRS; } } else { if (cmbSender.SelectedItem != null) { IStorageTarget targetStorageAccount = (IStorageTarget)cmbSender.SelectedItem; _TargetDisk.TargetStorage = targetStorageAccount; } else { _TargetDisk.TargetStorage = null; } } if (!_IsBinding) { PropertyChanged?.Invoke(); } } }
private void cmbTargetStorage_SelectedIndexChanged(object sender, EventArgs e) { ComboBox cmbSender = (ComboBox)sender; if (_TargetDisk != null) { _TargetDisk.TargetStorageAccount = null; } if (cmbSender.SelectedItem != null) { IStorageTarget targetStorageAccount = (IStorageTarget)cmbSender.SelectedItem; if (_TargetDisk != null) { _TargetDisk.TargetStorageAccount = targetStorageAccount; } } PropertyChanged?.Invoke(); }
public void NewDeleteTask(IStorageTarget target) { CheckDispos(); _taskQueue.Enqueue(SaveTask.CreateDeleteTask(target)); }
public void NewSaveTask(IStorageSource source, IStorageTarget target) { CheckDispos(); _taskQueue.Enqueue(SaveTask.CreateSaveTask(target, source.Read())); }
public void NewLoadTask(IStorageSource source, IStorageTarget target) { CheckDispos(); _taskQueue.Enqueue(SaveTask.CreateLoadTask(source, target)); }
/// <summary> /// 新建删除任务 /// </summary> public void NewDeleteTask(IStorageTarget target) { NewTask(SaveTask.Type.Delete, null, target); }
/// <summary> /// 新建加载任务 /// </summary> public void NewLoadTask(Save save, IStorageTarget target) { NewTask(SaveTask.Type.Load, save, target); }
/// <summary> /// 新建保存任务 /// </summary> public void NewSaveTask(Save save, IStorageTarget target) { NewTask(SaveTask.Type.Save, save, target); }