public SaveStorageCommand(int chapter, Vector3 position) { this.StoragePoint = new StoragePoint { Chapter = chapter, Postion = position }; }
/// <summary> /// On load storage command. Check return value. /// </summary> /// <returns>StoragePoint.</returns> /// <param name="cmd">Cmd.</param> public void OnLoadStorageCommand(LoadStorageCommand cmd) { if (Model.IsGuest) { Debug.Log("load storage from local."); StoragePoint point = null; try { if (File.Exists(GetStoragePointFilename())) { string json = File.ReadAllText(GetStoragePointFilename(), Encoding.UTF8); if (!string.IsNullOrWhiteSpace(json)) { point = JsonUtility.FromJson <StoragePoint>(json); if (point.Items == null) { point.Items = new List <string>(); } if (point.UnlockedChapters == null) { point.UnlockedChapters = new List <int> { 0 }; } } } else { Debug.Log("there is no local storage."); point = new StoragePoint() { Chapter = -1, Items = new List <string>(), UnlockedChapters = new List <int>() { 0 } }; } Model.StoragePoint = point; } catch { Debug.Log("failed to load storage from local."); } cmd.callback?.Invoke(point); return; } if (string.IsNullOrWhiteSpace(Model.Token)) { return; } Debug.Log("load storage form server."); StoragePoint storagePoint = null; Dictionary <string, string> form = new Dictionary <string, string> { { "token", Model.Token } }; StartCoroutine( IOUtil.Post( IOUtil.GetFullUrl("/storage/load"), form, (HttpResponse obj) => { if (obj.code == 0 && obj.data != null && !string.IsNullOrWhiteSpace(obj.data.ToString())) { storagePoint = JsonUtility.FromJson <StoragePoint>(obj.data.ToString()); // todo call before enter chapter Call (new Biz.Item.InitCommand (storagePoint.Items)); } else { storagePoint = new StoragePoint() { Chapter = -1, Items = new List <string>(), UnlockedChapters = new List <int>() { 0 } }; } cmd.callback?.Invoke(storagePoint); Model.StoragePoint = storagePoint; }, (float obj) => { // ignore }) ); }
public SaveStorageCommand(StoragePoint point) { this.StoragePoint = point; }