This commit is contained in:
CortexCore
2024-06-27 18:53:49 +08:00
parent 4a8c97d1fd
commit 21bbfe0617
5 changed files with 22 additions and 11 deletions

View File

@@ -37,6 +37,7 @@ namespace BITKit
public object Container => container;
internal VisualElement container;
internal Label label;
internal Action OnDispose;
public async void SetMessage(string message)
{
await UniTask.SwitchToMainThread();
@@ -49,6 +50,8 @@ namespace BITKit
BIT4Log.Log<UXWaiting>("WaitingHandle is destroyed");
}
}
public void Dispose() => OnDispose?.Invoke();
}
[SerializeField] private VisualTreeAsset handleTemplate;
@@ -59,14 +62,15 @@ namespace BITKit
[UXBindPath("waiting-root")]
private VisualElement _root;
private Pool<IUXWaitingHandle> _pool;
private readonly HashSet<IUXWaitingHandle> _handles = new();
private Pool<WaitingHandle> _pool;
private readonly HashSet<WaitingHandle> _handles = new();
public IUXWaitingHandle Get()
{
var handle = _pool.Take();
Active();
_handles.Add(handle);
handle.OnDispose = () => Release(handle);
return handle;
async void Active()
{
@@ -79,8 +83,8 @@ namespace BITKit
{
await UniTask.SwitchToMainThread();
if (destroyCancellationToken.IsCancellationRequested) return;
_pool.Return(handle);
_handles.Remove(handle);
_pool.Return(handle.As<WaitingHandle>());
_handles.Remove(handle.As<WaitingHandle>());
Check();
}
protected override void Awake()
@@ -88,7 +92,7 @@ namespace BITKit
base.Awake();
UXUtils.Inject(this);
_container.Clear();
_pool = new Pool<IUXWaitingHandle>(Create,OnReset,10);
_pool = new Pool<WaitingHandle>(Create,OnReset,10);
if (asGlobal)
{
DI.Register<IUXWaiting>(this);
@@ -114,7 +118,7 @@ namespace BITKit
if(destroyCancellationToken.IsCancellationRequested) return;
_root.SetActive(_handles.Count>0);
}
private IUXWaitingHandle Create()
private WaitingHandle Create()
{
var handle = new WaitingHandle
{