protected override void ParseResponseData(JToken responseData) { Task.Run(() => { try { var data = responseData.ToObject <JObject>(); Mapsets = data["mapsets"].ToObject <OnlineMapset[]>(); if (data.ContainsKey("cursor")) { Cursor = data["cursor"].ToString(); } if (data.ContainsKey("total")) { Total = data["total"].Value <int>(); } UnityThread.DispatchUnattended(() => { EvaluateSuccess(); return(null); }); } catch (Exception e) { UnityThread.DispatchUnattended(() => { EvaluateFail(e.Message); return(null); }); } }); }
public void RemoveById(string id, bool multiple) { if (string.IsNullOrEmpty(id)) { return; } UnityThread.DispatchUnattended(() => { for (int i = notifications.Count - 1; i >= 0; i--) { var notif = notifications[i]; if (notif.Id == id) { notifications.RemoveAt(i); OnRemoveNotification?.Invoke(notif); if (!multiple) { return(null); } } } return(null); }); }
public Task Reload(TaskListener listener = null) { return(Task.Run(async() => { if (listener != null) { listener.HasOwnProgress = false; } // Wait for store reloading. await store.Reload(listener?.CreateSubListener()); // Run on the main thread UnityThread.DispatchUnattended(() => { // Refill the mapset list allMapsets.Clear(); allMapsets.AddRange(store.Mapsets); // TODO: Process for a case where the previously selected map no longer exists. // Fill the displayed mapsets list using last search term. Search(lastSearch); // Finished listener?.SetFinished(); return null; }); })); }
/// <summary> /// Finishes the loading process. /// </summary> private void FinalizeLoad() { UnityThread.DispatchUnattended(() => { TemporaryStore.Clear(); isComplete.Value = true; return(null); }); }
public void Remove(INotification notification) { UnityThread.DispatchUnattended(() => { if (notifications.Remove(notification)) { OnRemoveNotification?.Invoke(notification); } return(null); }); }
public void Add(Notification notification) { PostProcessNotification(notification); UnityThread.DispatchUnattended(() => { if (notification.Scope != NotificationScope.Temporary) { notifications.Add(notification); } OnNewNotification?.Invoke(notification); return(null); }); }
/// <summary> /// Pipes the specified message to the notification box. /// </summary> private void Pipe(LogType type, object message) { if (NotificationBox != null && type >= PipeLogLevel) { UnityThread.DispatchUnattended(() => { NotificationBox.Add(new Notification() { Message = message.ToString(), Type = (NotificationType)type, }); return(null); }); } }
public IEnumerator TestDispatchUnattended() { bool finished = false; int unityThread = Thread.CurrentThread.ManagedThreadId; UnityThread.Initialize(); Task.Run(() => { Assert.AreNotEqual(unityThread, Thread.CurrentThread.ManagedThreadId); Thread.Sleep(500); UnityThread.DispatchUnattended(() => finished = true); }); while (!finished) { yield return(null); } }
/// <summary> /// Sets the current progress and invokes changed event. /// </summary> private void SetProgress(float progress) { UnityThread.DispatchUnattended(() => this.progress.Value = progress); }
/// <summary> /// Assigns the current status and invokes changed event. /// </summary> private void SetState(string state) { UnityThread.DispatchUnattended(() => this.state.Value = state); }