예제 #1
0
        // 新建任务
        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());
            }
        }
예제 #2
0
        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
        }
예제 #3
0
        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" : "")));
        }
예제 #4
0
        /// <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);
        }
예제 #5
0
        /// <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);
        }
예제 #6
0
        /// <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);
        }
예제 #7
0
        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();
                }
            }
        }
예제 #8
0
        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();
        }
예제 #9
0
 public void NewDeleteTask(IStorageTarget target)
 {
     CheckDispos();
     _taskQueue.Enqueue(SaveTask.CreateDeleteTask(target));
 }
예제 #10
0
 public void NewSaveTask(IStorageSource source, IStorageTarget target)
 {
     CheckDispos();
     _taskQueue.Enqueue(SaveTask.CreateSaveTask(target, source.Read()));
 }
예제 #11
0
 public void NewLoadTask(IStorageSource source, IStorageTarget target)
 {
     CheckDispos();
     _taskQueue.Enqueue(SaveTask.CreateLoadTask(source, target));
 }
예제 #12
0
 /// <summary>
 /// 新建删除任务
 /// </summary>
 public void NewDeleteTask(IStorageTarget target)
 {
     NewTask(SaveTask.Type.Delete, null, target);
 }
예제 #13
0
 /// <summary>
 /// 新建加载任务
 /// </summary>
 public void NewLoadTask(Save save, IStorageTarget target)
 {
     NewTask(SaveTask.Type.Load, save, target);
 }
예제 #14
0
 /// <summary>
 /// 新建保存任务
 /// </summary>
 public void NewSaveTask(Save save, IStorageTarget target)
 {
     NewTask(SaveTask.Type.Save, save, target);
 }