コード例 #1
0
        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);
                    });
                }
            });
        }
コード例 #2
0
        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);
            });
        }
コード例 #3
0
        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;
                });
            }));
        }
コード例 #4
0
        /// <summary>
        /// Finishes the loading process.
        /// </summary>
        private void FinalizeLoad()
        {
            UnityThread.DispatchUnattended(() =>
            {
                TemporaryStore.Clear();

                isComplete.Value = true;
                return(null);
            });
        }
コード例 #5
0
 public void Remove(INotification notification)
 {
     UnityThread.DispatchUnattended(() =>
     {
         if (notifications.Remove(notification))
         {
             OnRemoveNotification?.Invoke(notification);
         }
         return(null);
     });
 }
コード例 #6
0
        public void Add(Notification notification)
        {
            PostProcessNotification(notification);

            UnityThread.DispatchUnattended(() =>
            {
                if (notification.Scope != NotificationScope.Temporary)
                {
                    notifications.Add(notification);
                }
                OnNewNotification?.Invoke(notification);
                return(null);
            });
        }
コード例 #7
0
 /// <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);
         });
     }
 }
コード例 #8
0
        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);
            }
        }
コード例 #9
0
 /// <summary>
 /// Sets the current progress and invokes changed event.
 /// </summary>
 private void SetProgress(float progress)
 {
     UnityThread.DispatchUnattended(() => this.progress.Value = progress);
 }
コード例 #10
0
 /// <summary>
 /// Assigns the current status and invokes changed event.
 /// </summary>
 private void SetState(string state)
 {
     UnityThread.DispatchUnattended(() => this.state.Value = state);
 }