This commit is contained in:
parent
4a8c97d1fd
commit
21bbfe0617
|
@ -4,7 +4,7 @@ using System.Collections.Generic;
|
||||||
|
|
||||||
namespace BITKit.UX
|
namespace BITKit.UX
|
||||||
{
|
{
|
||||||
public interface IUXWaitingHandle
|
public interface IUXWaitingHandle:IDisposable
|
||||||
{
|
{
|
||||||
string Message { get; set; }
|
string Message { get; set; }
|
||||||
object Container { get; }
|
object Container { get; }
|
||||||
|
|
|
@ -11,7 +11,8 @@
|
||||||
"GUID:d525ad6bd40672747bde77962f1c401e",
|
"GUID:d525ad6bd40672747bde77962f1c401e",
|
||||||
"GUID:49b49c76ee64f6b41bf28ef951cb0e50",
|
"GUID:49b49c76ee64f6b41bf28ef951cb0e50",
|
||||||
"GUID:517785bb4600a5140b47eac5fa49b8fc",
|
"GUID:517785bb4600a5140b47eac5fa49b8fc",
|
||||||
"GUID:be17a8778dbfe454890ed8279279e153"
|
"GUID:be17a8778dbfe454890ed8279279e153",
|
||||||
|
"GUID:d8b63aba1907145bea998dd612889d6b"
|
||||||
],
|
],
|
||||||
"includePlatforms": [],
|
"includePlatforms": [],
|
||||||
"excludePlatforms": [],
|
"excludePlatforms": [],
|
||||||
|
|
|
@ -9,6 +9,8 @@ using BITKit.Entities;
|
||||||
using Cysharp.Threading.Tasks;
|
using Cysharp.Threading.Tasks;
|
||||||
using UnityEngine.Profiling;
|
using UnityEngine.Profiling;
|
||||||
using UnityEngine.UIElements;
|
using UnityEngine.UIElements;
|
||||||
|
using Random = UnityEngine.Random;
|
||||||
|
|
||||||
// ReSharper disable RedundantTypeArgumentsOfMethod
|
// ReSharper disable RedundantTypeArgumentsOfMethod
|
||||||
|
|
||||||
namespace BITKit.Entities
|
namespace BITKit.Entities
|
||||||
|
@ -147,9 +149,9 @@ namespace BITKit.Entities
|
||||||
}
|
}
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
if (Id.IsDefault())
|
if (Id is 0)
|
||||||
Id = GetInstanceID();
|
Id = Guid.NewGuid().GetHashCode();
|
||||||
CancellationToken = gameObject.GetCancellationTokenOnDestroy();
|
CancellationToken = destroyCancellationToken;
|
||||||
Set(CancellationToken);
|
Set(CancellationToken);
|
||||||
|
|
||||||
if (useAwake)
|
if (useAwake)
|
||||||
|
|
|
@ -89,6 +89,10 @@ namespace BITKit.Net.Kcp
|
||||||
address = m_host;
|
address = m_host;
|
||||||
if(port is 27014 or 0)
|
if(port is 27014 or 0)
|
||||||
port = m_port;
|
port = m_port;
|
||||||
|
|
||||||
|
m_host = address;
|
||||||
|
m_port = port;
|
||||||
|
|
||||||
return _netClientImplementation.Connect(address, port);
|
return _netClientImplementation.Connect(address, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ namespace BITKit
|
||||||
public object Container => container;
|
public object Container => container;
|
||||||
internal VisualElement container;
|
internal VisualElement container;
|
||||||
internal Label label;
|
internal Label label;
|
||||||
|
internal Action OnDispose;
|
||||||
public async void SetMessage(string message)
|
public async void SetMessage(string message)
|
||||||
{
|
{
|
||||||
await UniTask.SwitchToMainThread();
|
await UniTask.SwitchToMainThread();
|
||||||
|
@ -49,6 +50,8 @@ namespace BITKit
|
||||||
BIT4Log.Log<UXWaiting>("WaitingHandle is destroyed");
|
BIT4Log.Log<UXWaiting>("WaitingHandle is destroyed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose() => OnDispose?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
[SerializeField] private VisualTreeAsset handleTemplate;
|
[SerializeField] private VisualTreeAsset handleTemplate;
|
||||||
|
@ -59,14 +62,15 @@ namespace BITKit
|
||||||
[UXBindPath("waiting-root")]
|
[UXBindPath("waiting-root")]
|
||||||
private VisualElement _root;
|
private VisualElement _root;
|
||||||
|
|
||||||
private Pool<IUXWaitingHandle> _pool;
|
private Pool<WaitingHandle> _pool;
|
||||||
private readonly HashSet<IUXWaitingHandle> _handles = new();
|
private readonly HashSet<WaitingHandle> _handles = new();
|
||||||
|
|
||||||
public IUXWaitingHandle Get()
|
public IUXWaitingHandle Get()
|
||||||
{
|
{
|
||||||
var handle = _pool.Take();
|
var handle = _pool.Take();
|
||||||
Active();
|
Active();
|
||||||
_handles.Add(handle);
|
_handles.Add(handle);
|
||||||
|
handle.OnDispose = () => Release(handle);
|
||||||
return handle;
|
return handle;
|
||||||
async void Active()
|
async void Active()
|
||||||
{
|
{
|
||||||
|
@ -79,8 +83,8 @@ namespace BITKit
|
||||||
{
|
{
|
||||||
await UniTask.SwitchToMainThread();
|
await UniTask.SwitchToMainThread();
|
||||||
if (destroyCancellationToken.IsCancellationRequested) return;
|
if (destroyCancellationToken.IsCancellationRequested) return;
|
||||||
_pool.Return(handle);
|
_pool.Return(handle.As<WaitingHandle>());
|
||||||
_handles.Remove(handle);
|
_handles.Remove(handle.As<WaitingHandle>());
|
||||||
Check();
|
Check();
|
||||||
}
|
}
|
||||||
protected override void Awake()
|
protected override void Awake()
|
||||||
|
@ -88,7 +92,7 @@ namespace BITKit
|
||||||
base.Awake();
|
base.Awake();
|
||||||
UXUtils.Inject(this);
|
UXUtils.Inject(this);
|
||||||
_container.Clear();
|
_container.Clear();
|
||||||
_pool = new Pool<IUXWaitingHandle>(Create,OnReset,10);
|
_pool = new Pool<WaitingHandle>(Create,OnReset,10);
|
||||||
if (asGlobal)
|
if (asGlobal)
|
||||||
{
|
{
|
||||||
DI.Register<IUXWaiting>(this);
|
DI.Register<IUXWaiting>(this);
|
||||||
|
@ -114,7 +118,7 @@ namespace BITKit
|
||||||
if(destroyCancellationToken.IsCancellationRequested) return;
|
if(destroyCancellationToken.IsCancellationRequested) return;
|
||||||
_root.SetActive(_handles.Count>0);
|
_root.SetActive(_handles.Count>0);
|
||||||
}
|
}
|
||||||
private IUXWaitingHandle Create()
|
private WaitingHandle Create()
|
||||||
{
|
{
|
||||||
var handle = new WaitingHandle
|
var handle = new WaitingHandle
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue