This commit is contained in:
parent
66ba9c8a77
commit
d33e1c1713
|
@ -1,4 +1,4 @@
|
||||||
#if UNITY_5_3_OR_NEWER
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
@ -9,7 +9,9 @@ using System.Threading;
|
||||||
#if UNITY_WINDOW
|
#if UNITY_WINDOW
|
||||||
using AnotherFileBrowser.Windows;
|
using AnotherFileBrowser.Windows;
|
||||||
#endif
|
#endif
|
||||||
|
#if UNITY_5_3_OR_NEWER
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
#endif
|
||||||
|
|
||||||
using Cysharp.Threading.Tasks;
|
using Cysharp.Threading.Tasks;
|
||||||
|
|
||||||
|
@ -225,5 +227,3 @@ namespace BITKit.IO
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
|
@ -78,47 +78,45 @@ namespace BITKit.UX
|
||||||
background?.SetOpacity(0);
|
background?.SetOpacity(0);
|
||||||
if (IsWindow) document.sortingOrder++;
|
if (IsWindow) document.sortingOrder++;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void Start()
|
protected virtual void Start()
|
||||||
{
|
{
|
||||||
BITKit.UX.UXUtils.Inject(this);
|
BITKit.UX.UXUtils.Inject(this);
|
||||||
|
|
||||||
UXService.Register(this);
|
UXService.Register(this);
|
||||||
destroyCancellationToken.Register(() =>
|
destroyCancellationToken.Register(() => { UXService.UnRegister(this); });
|
||||||
{
|
|
||||||
UXService.UnRegister(this);
|
if (IsValid && autoEntry)
|
||||||
});
|
|
||||||
|
|
||||||
if(IsValid && autoEntry)
|
|
||||||
UXService.Entry(this);
|
UXService.Entry(this);
|
||||||
|
|
||||||
var returnButton= document.rootVisualElement.Q("return-button");
|
var returnButton = document.rootVisualElement.Q("return-button");
|
||||||
returnButton?.RegisterCallback<MouseDownEvent>(x =>
|
returnButton?.RegisterCallback<MouseDownEvent>(x =>
|
||||||
{
|
{
|
||||||
if (x.button is 0)
|
if (x.button is 0)
|
||||||
OnReturn();
|
OnReturn();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var invisible = document.rootVisualElement.Create<VisualElement>();
|
||||||
|
invisible.name = "invisible_return_generate";
|
||||||
|
invisible.style.position = Position.Absolute;
|
||||||
|
invisible.pickingMode = PickingMode.Ignore;
|
||||||
|
invisible.style.left = 0;
|
||||||
|
invisible.style.right = 0;
|
||||||
|
invisible.style.top = 0;
|
||||||
|
invisible.style.bottom = 0;
|
||||||
|
invisible.SendToBack();
|
||||||
|
|
||||||
|
if (closeWhenClickOutside)
|
||||||
|
{
|
||||||
|
invisible.RegisterCallback<MouseDownEvent>(x => { OnReturn(); });
|
||||||
|
invisible.pickingMode = PickingMode.Position;
|
||||||
|
}
|
||||||
if (isWindow)
|
if (isWindow)
|
||||||
{
|
{
|
||||||
var invisible = document.rootVisualElement.Create<VisualElement>();
|
|
||||||
invisible.name = "invisible_return_generate";
|
|
||||||
invisible.style.position = Position.Absolute;
|
|
||||||
invisible.style.left = 0;
|
|
||||||
invisible.style.right = 0;
|
|
||||||
invisible.style.top = 0;
|
|
||||||
invisible.style.bottom = 0;
|
|
||||||
invisible.SendToBack();
|
|
||||||
invisible.style.backgroundColor = new Color(0, 0, 0, 0.9f);
|
invisible.style.backgroundColor = new Color(0, 0, 0, 0.9f);
|
||||||
{
|
|
||||||
if(closeWhenClickOutside)
|
|
||||||
invisible.RegisterCallback<MouseDownEvent>(x =>
|
|
||||||
{
|
|
||||||
OnReturn();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsEntered { get; set; }
|
public bool IsEntered { get; set; }
|
||||||
public void Entry()
|
public void Entry()
|
||||||
{
|
{
|
||||||
|
|
|
@ -39,22 +39,8 @@ namespace BITKit
|
||||||
internal VisualElement container;
|
internal VisualElement container;
|
||||||
internal Label label;
|
internal Label label;
|
||||||
internal Action OnDispose;
|
internal Action OnDispose;
|
||||||
internal Action<Label,string> OnSetMessage;
|
internal Action<string> OnSetMessage;
|
||||||
public async void SetMessage(string message)
|
public void SetMessage(string message) => OnSetMessage?.Invoke(message);
|
||||||
{
|
|
||||||
OnSetMessage?.Invoke(label,message);
|
|
||||||
// await UniTask.SwitchToMainThread();
|
|
||||||
// BIT4Log.Log<UXWaiting>($"SetMessage {message}");
|
|
||||||
// if(container.panel!=null)
|
|
||||||
// {
|
|
||||||
// label.text = message;
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// BIT4Log.Log<UXWaiting>("WaitingHandle is destroyed");
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose() => OnDispose?.Invoke();
|
public void Dispose() => OnDispose?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,90 +52,61 @@ namespace BITKit
|
||||||
[UXBindPath("waiting-root")]
|
[UXBindPath("waiting-root")]
|
||||||
private VisualElement _root;
|
private VisualElement _root;
|
||||||
|
|
||||||
private Pool<WaitingHandle> _pool;
|
private readonly ConcurrentQueue<(WaitingHandle handle,string text)> _messageQueue = new();
|
||||||
private readonly HashSet<WaitingHandle> _handles = new();
|
private readonly ConcurrentQueue<WaitingHandle> _initializedHandles = new();
|
||||||
private readonly ConcurrentQueue<(Label label,string text)> _messageQueue = new();
|
private readonly ConcurrentQueue<WaitingHandle> _disposeQueue = new();
|
||||||
|
private readonly ValidHandle _visibleHandle = new();
|
||||||
public IUXWaitingHandle Get()
|
public IUXWaitingHandle Get()
|
||||||
{
|
{
|
||||||
var handle = _pool.Take();
|
var handle = new WaitingHandle();
|
||||||
Active();
|
_initializedHandles.Enqueue(handle);
|
||||||
_handles.Add(handle);
|
handle.OnSetMessage = (text) =>
|
||||||
handle.OnDispose = () => Release(handle);
|
|
||||||
return handle;
|
|
||||||
async void Active()
|
|
||||||
{
|
{
|
||||||
await UniTask.SwitchToMainThread();
|
_messageQueue.Enqueue((handle,text));
|
||||||
handle.As<WaitingHandle>().container.SetActive(true);
|
};
|
||||||
_root.SetActive(true);
|
handle.OnDispose = () =>
|
||||||
}
|
{
|
||||||
|
_disposeQueue.Enqueue(handle);
|
||||||
|
};
|
||||||
|
return handle;
|
||||||
}
|
}
|
||||||
public async void Release(IUXWaitingHandle handle)
|
public void Release(IUXWaitingHandle handle)
|
||||||
{
|
{
|
||||||
await UniTask.SwitchToMainThread();
|
handle.Dispose();
|
||||||
if (destroyCancellationToken.IsCancellationRequested) return;
|
|
||||||
_pool.Return(handle.As<WaitingHandle>());
|
|
||||||
_handles.Remove(handle.As<WaitingHandle>());
|
|
||||||
Check();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
|
while (_initializedHandles.TryDequeue(out var handle))
|
||||||
|
{
|
||||||
|
var container = _container.Create(handleTemplate);
|
||||||
|
handle.container = container;
|
||||||
|
handle.label = container.Get<Label>();
|
||||||
|
}
|
||||||
while (_messageQueue.TryDequeue(out var message))
|
while (_messageQueue.TryDequeue(out var message))
|
||||||
{
|
{
|
||||||
message.label.text = message.text;
|
message.handle.label.text = message.text;
|
||||||
}
|
}
|
||||||
|
while (_disposeQueue.TryDequeue(out var handle))
|
||||||
|
{
|
||||||
|
handle.container.RemoveFromHierarchy();
|
||||||
|
}
|
||||||
|
_visibleHandle.SetElements(0, _container.childCount>0);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Awake()
|
protected override void Awake()
|
||||||
{
|
{
|
||||||
base.Awake();
|
base.Awake();
|
||||||
UXUtils.Inject(this);
|
UXUtils.Inject(this);
|
||||||
_container.Clear();
|
_container.Clear();
|
||||||
_pool = new Pool<WaitingHandle>(Create,OnReset,10);
|
|
||||||
if (asGlobal)
|
if (asGlobal)
|
||||||
{
|
{
|
||||||
DI.Register<IUXWaiting>(this);
|
DI.Register<IUXWaiting>(this);
|
||||||
}
|
}
|
||||||
_root.SetActive(false);
|
_root.SetActive(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
Check();
|
_visibleHandle.AddListener(_root.SetActive);
|
||||||
}
|
_visibleHandle.Invoke();
|
||||||
|
|
||||||
private async void OnReset(IUXWaitingHandle obj)
|
|
||||||
{
|
|
||||||
await UniTask.SwitchToMainThread();
|
|
||||||
obj.As<WaitingHandle>().container.SetActive(false);
|
|
||||||
}
|
|
||||||
[BIT]
|
|
||||||
private async void Check()
|
|
||||||
{
|
|
||||||
await UniTask.Yield();
|
|
||||||
await UniTask.SwitchToMainThread();
|
|
||||||
if(destroyCancellationToken.IsCancellationRequested) return;
|
|
||||||
_root.SetActive(_handles.Count>0);
|
|
||||||
}
|
|
||||||
private WaitingHandle Create()
|
|
||||||
{
|
|
||||||
var handle = new WaitingHandle
|
|
||||||
{
|
|
||||||
container = _container.Create(handleTemplate),
|
|
||||||
label = _container.Q<Label>(UXConstant.ContextLabel)
|
|
||||||
};
|
|
||||||
|
|
||||||
handle.OnSetMessage = (label, text) =>
|
|
||||||
{
|
|
||||||
_messageQueue.Enqueue((label,text));
|
|
||||||
};
|
|
||||||
|
|
||||||
handle.SetMessage($"未初始化");
|
|
||||||
|
|
||||||
handle.container.SetActive(false);
|
|
||||||
|
|
||||||
return handle;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements">
|
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
|
||||||
<ui:VisualElement style="flex-grow: 1;">
|
<ui:VisualElement style="flex-grow: 1;">
|
||||||
<ui:Label tabindex="-1" text="等待加载中..." parse-escape-sequences="true" display-tooltip-when-elided="true" name="context-label" />
|
<ui:Label tabindex="-1" text="等待加载中..." parse-escape-sequences="true" display-tooltip-when-elided="true" name="Label--0" />
|
||||||
</ui:VisualElement>
|
</ui:VisualElement>
|
||||||
</ui:UXML>
|
</ui:UXML>
|
||||||
|
|
Loading…
Reference in New Issue