refactor to handle itemview kill/create, fix sorting table, cleanup

This commit is contained in:
Tyfon
2024-06-19 00:47:48 -07:00
parent 3ea9726189
commit 8a2eb49baa
4 changed files with 349 additions and 228 deletions

48
TaskSerializer.cs Normal file
View File

@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using UnityEngine;
namespace UIFixes
{
public class TaskSerializer<T> : MonoBehaviour
{
private Func<T, Task> func;
private Queue<T> items;
private Task currentTask;
private TaskCompletionSource totalTask;
public Task Initialize(IEnumerable<T> items, Func<T, Task> func)
{
this.items = new(items);
this.func = func;
currentTask = Task.CompletedTask;
totalTask = new TaskCompletionSource();
Update();
return totalTask.Task;
}
public void Update()
{
if (!currentTask.IsCompleted)
{
return;
}
if (items.Any())
{
currentTask = func(items.Dequeue());
}
else
{
totalTask.Complete();
func = null;
Destroy(this);
}
}
}
}