private void AppendLeaderboardResults(IUnityTask unityTask, List <PlayerLeaderboardEntry> leaderboardEntries) { if (unityTask.HasError || leaderboardEntries == null) { // TODO [bgish]: Do some error handling return; } if (leaderboardEntries.Count == 0) { return; } bool addToBeginningOfList = this.entries.Count != 0 && leaderboardEntries[0].Position < this.entries[0].Position; if (addToBeginningOfList) { // removing dups from the results for (int i = leaderboardEntries.Count - 1; i >= 0; i--) { if (leaderboardEntries[i].Position >= this.entries[0].Position) { leaderboardEntries.RemoveAt(i); } } // Shifting results so don't get a pop this.ShiftContent(-leaderboardEntries.Count); leaderboardEntries.AddRange(this.entries); this.entries = leaderboardEntries; } else { // Adding to the end of the list this.entries.AddRange(leaderboardEntries); this.moreBottomEntriesExist = leaderboardEntries.Count >= this.maxResultsCount; } // Trimming elements that are over the max entries size if (this.entries.Count > this.maxEntriesBeforeTrimming) { int itemsToTrimCount = this.entries.Count - this.maxEntriesBeforeTrimming; if (addToBeginningOfList) { this.entries.RemoveRange(this.entries.Count - itemsToTrimCount, itemsToTrimCount); } else { this.entries.RemoveRange(0, itemsToTrimCount); this.ShiftContent(itemsToTrimCount); } } // Making sure more top entries exist this.moreTopEntiresExist = this.entries[0].Position != 0; this.SetCount(this.entries.Count); }
/// <summary> /// Creates a continuation that executes synchronously on the UI thread when the target UnityTask completes /// </summary> /// <param name="action">An action to run when the UnityTask completes. When run, the delegate will be passed the completed UnityTask as an argument</param> public void ContinueOnUIThread(Action <UnityTask> action) { Action wrapper = () => { action(this); }; _continuation = new UnityUITask(wrapper); }
/// <summary> /// Creates a continuation that executes asynchronously when the target UnityTask completes /// </summary> /// <typeparam name="TResult">The type of the result produced by the continuation</typeparam> /// <param name="function">A function to run when the UnityTask completes. When run, the delegate will be passed the completed UnityTask as an argument</param> /// <returns>A new continuation UnityTask</returns> public UnityTask <TResult> ContinueWith <TResult>(Func <UnityTask, TResult> function) { Func <TResult> wrapperFunc = () => { return(function(this)); }; UnityTask <TResult> continuation = new UnityTask <TResult>(wrapperFunc); _continuation = continuation; return(continuation); }
private void Log(IUnityTask task, Exception e = null) { var type = task.GetType(); if (_logIgnoreTasks.Contains(type)) { return; } if (e != null) { Debug.LogError($"Failed to execute {type}:\n{e}"); } else { Debug.Log($"Executed task {type}"); } }
/// <summary> /// Creates a continuation that executes asynchronously when the target UnityTask completes /// </summary> /// <param name="action">An action to run when the UnityTask completes. When run, the delegate will be passed the completed UnityTask as an argument</param> /// <returns>A new continuation UnityTask</returns> public UnityTask ContinueWith(Action <UnityTask> action) { Action wrapper = () => { try { action(this); } catch { State = UnityTaskState.Faulted; throw; } }; UnityTask continuation = new UnityTask(wrapper); _continuation = continuation; return(continuation); }
protected void AddTask(IUnityTask task) { _taskQueue.AddTask(task); }
public void AddTask(IUnityTask newTask) { _queue.Enqueue(newTask); }