1
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace BITKit.UX
|
||||
{
|
||||
[Serializable]
|
||||
public class UIToolkitPanelMonoProxy : UXPanelImplement
|
||||
{
|
||||
[SerializeField] private GameObject monoBehaviour;
|
||||
protected override IUXPanel service => monoBehaviour.GetComponent<IUXPanel>();
|
||||
}
|
||||
}
|
@@ -2,17 +2,20 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using BITKit.Mod;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UIElements;
|
||||
// ReSharper disable MemberCanBeProtected.Global
|
||||
// ReSharper disable ClassWithVirtualMembersNeverInherited.Global
|
||||
// ReSharper disable UnusedMember.Global
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class UIToolKitPanel : MonoBehaviour,IUXPanel
|
||||
public abstract class UIToolKitPanel : IUXPanel
|
||||
{
|
||||
public const string USSEntry = "transition_entry";
|
||||
public const string USSEntryAsync = "transition_entry_async";
|
||||
@@ -20,146 +23,96 @@ namespace BITKit.UX
|
||||
public const string USSExit = "transition_exit";
|
||||
public const string USSExitAsync = "transition_exit_async";
|
||||
public const string USSExited = "transition_exited";
|
||||
|
||||
[RuntimeInitializeOnLoadMethod]
|
||||
private static void Reload()
|
||||
{
|
||||
|
||||
InputActionGroup = new InputActionGroup
|
||||
{
|
||||
allowGlobalActivation = false,
|
||||
Source = nameof(UIToolKitPanel)
|
||||
};
|
||||
InputActionGroup.allowInput.AddElement(0);
|
||||
}
|
||||
public UIToolKitPanel()
|
||||
{
|
||||
Index = GetType().FullName;
|
||||
}
|
||||
[Header(Constant.Header.Components)]
|
||||
[SerializeField] protected UIDocument document;
|
||||
|
||||
[Header(Constant.Header.Settings)]
|
||||
[SerializeField] private bool isWindow;
|
||||
[SerializeField] private bool closeWhenClickOutside;
|
||||
[SerializeField] private bool isAnimate;
|
||||
[SerializeField] private bool allowCursor;
|
||||
[SerializeField] private bool allowInput;
|
||||
protected readonly IUXService UXService;
|
||||
protected abstract string DocumentPath { get; }
|
||||
public VisualElement RootVisualElement { get; set; }
|
||||
protected VisualTreeAsset VisualTreeAsset { get; private set; }
|
||||
protected UIToolKitPanel(IUXService uxService)
|
||||
{
|
||||
UXService = uxService;
|
||||
uxService.Register(this);
|
||||
}
|
||||
|
||||
[Header(Constant.Header.Settings)]
|
||||
[SerializeField] private Optional<float> entryDuration;
|
||||
[SerializeField] private Optional<float> exitDuration;
|
||||
protected static InputActionGroup InputActionGroup = new()
|
||||
protected virtual Optional<float> EntryDuration { get; }= new();
|
||||
protected virtual Optional<float> ExitDuration { get; }= new();
|
||||
protected static readonly InputActionGroup InputActionGroup = new()
|
||||
{
|
||||
allowGlobalActivation = false,
|
||||
Source = nameof(UIToolKitPanel)
|
||||
};
|
||||
public bool IsWindow => isWindow;
|
||||
public string Index { get; private set; }
|
||||
public bool AllowCursor => allowCursor;
|
||||
public bool AllowInput => allowInput;
|
||||
protected float TargetOpacity { get; private set; }
|
||||
protected virtual VisualElement background => document.rootVisualElement;
|
||||
// protected float CurrentOpacity
|
||||
// {
|
||||
// get => background?.GetOpacity() ?? currentOpacity;
|
||||
// set
|
||||
// {
|
||||
// currentOpacity = value;
|
||||
// background?.SetOpacity(value);
|
||||
// }
|
||||
// }
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
Index= typeof(UIToolKitPanel) == GetType() ? gameObject.name : GetType().Name;
|
||||
document.rootVisualElement.SetActive(false);
|
||||
//background?.SetOpacity(0);
|
||||
if (IsWindow) document.sortingOrder++;
|
||||
}
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
UXUtils.Inject(this);
|
||||
|
||||
document.rootVisualElement.AddToClassList(USSEntry);
|
||||
|
||||
UxService.Register(this);
|
||||
|
||||
destroyCancellationToken.Register(() => { UxService.UnRegister(this); });
|
||||
|
||||
var returnButton = document.rootVisualElement.Q("return-button");
|
||||
returnButton?.RegisterCallback<MouseDownEvent>(x =>
|
||||
{
|
||||
if (x.button is 0)
|
||||
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)
|
||||
{
|
||||
invisible.style.backgroundColor = new Color(0, 0, 0, 0.9f);
|
||||
}
|
||||
}
|
||||
public virtual bool CloseWhenClickOutside { get;}
|
||||
public virtual bool IsWindow { get; }
|
||||
public virtual string Index => GetType().Name;
|
||||
public virtual bool AllowReload { get; }
|
||||
public virtual bool AllowCursor { get; }
|
||||
public virtual bool AllowInput { get; }
|
||||
|
||||
public bool IsEntered { get; set; }
|
||||
[BIT]
|
||||
public void Entry()
|
||||
{
|
||||
UxService.Entry(this);
|
||||
}
|
||||
protected virtual void OnReturn()
|
||||
{
|
||||
UxService.Return();
|
||||
UXService.Return();
|
||||
}
|
||||
protected virtual void OnEnable(){}
|
||||
protected virtual void OnDisable(){}
|
||||
protected virtual void OnPanelEntry(){}
|
||||
protected virtual void OnPanelExit(){}
|
||||
void IEntryElement.Entry()
|
||||
{
|
||||
try
|
||||
{
|
||||
document.rootVisualElement.SetActive(true);
|
||||
|
||||
OnEntry?.Invoke();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Log(gameObject.name);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
void IEntryElement.Entry()
|
||||
{
|
||||
InputActionGroup.allowInput.AddElement(this);
|
||||
OnEntry?.Invoke();
|
||||
}
|
||||
async UniTask IEntryElement.EntryAsync()
|
||||
{
|
||||
document.rootVisualElement.AddToClassList(USSEntry);
|
||||
|
||||
document.rootVisualElement.AddToClassList(USSEntryAsync);
|
||||
if (RootVisualElement is null)
|
||||
{
|
||||
VisualTreeAsset = await ModService.LoadAsset<VisualTreeAsset>(DocumentPath);
|
||||
|
||||
RootVisualElement = UXService.Root.As<VisualElement>().Create(VisualTreeAsset);
|
||||
RootVisualElement.pickingMode = PickingMode.Ignore;
|
||||
RootVisualElement.style.position = Position.Absolute;
|
||||
RootVisualElement.style.left = 0;
|
||||
RootVisualElement.style.right = 0;
|
||||
RootVisualElement.style.top = 0;
|
||||
RootVisualElement.style.bottom = 0;
|
||||
|
||||
if (entryDuration.Allow)
|
||||
var invisible = 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)
|
||||
{
|
||||
invisible.style.backgroundColor = new Color(0, 0, 0, 0.9f);
|
||||
}
|
||||
|
||||
UXUtils.Inject(this);
|
||||
}
|
||||
|
||||
RootVisualElement.SetActive(true);
|
||||
RootVisualElement.AddToClassList(USSEntry);
|
||||
|
||||
RootVisualElement.AddToClassList(USSEntryAsync);
|
||||
|
||||
if (EntryDuration.Allow)
|
||||
{
|
||||
var task = EntryAsync();
|
||||
var durationTask = UniTask.Delay(TimeSpan.FromSeconds(entryDuration.Value), cancellationToken: destroyCancellationToken);
|
||||
var durationTask = UniTask.Delay(TimeSpan.FromSeconds(EntryDuration.Value));
|
||||
|
||||
await durationTask;
|
||||
document.rootVisualElement.RemoveFromClassList(USSEntry);
|
||||
document.rootVisualElement.RemoveFromClassList(USSEntryAsync);
|
||||
document.rootVisualElement.AddToClassList(USSEntered);
|
||||
RootVisualElement.RemoveFromClassList(USSEntry);
|
||||
RootVisualElement.RemoveFromClassList(USSEntryAsync);
|
||||
RootVisualElement.AddToClassList(USSEntered);
|
||||
|
||||
await task;
|
||||
}
|
||||
@@ -167,6 +120,19 @@ namespace BITKit.UX
|
||||
{
|
||||
await EntryAsync();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (OnEntryAsync is not null)
|
||||
{
|
||||
await OnEntryAsync.UniTaskFunc();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
BIT4Log.LogException(e);
|
||||
}
|
||||
|
||||
}
|
||||
public virtual UniTask EntryAsync()
|
||||
{
|
||||
@@ -175,32 +141,48 @@ namespace BITKit.UX
|
||||
void IEntryElement.Entered()
|
||||
{
|
||||
OnPanelEntry();
|
||||
OnEntryCompleted?.Invoke();
|
||||
}
|
||||
|
||||
void IEntryElement.Exit()
|
||||
{
|
||||
document.rootVisualElement.AddToClassList(USSExit);
|
||||
//if (IsValid is false) return;
|
||||
RootVisualElement?.AddToClassList(USSExit);
|
||||
OnPanelExit();
|
||||
InputActionGroup.allowInput.RemoveElement(this);
|
||||
OnExit?.Invoke();
|
||||
}
|
||||
async UniTask IEntryElement.ExitAsync()
|
||||
{
|
||||
document.rootVisualElement.RemoveFromClassList(USSEntered);
|
||||
document.rootVisualElement.AddToClassList(USSExitAsync);
|
||||
if (entryDuration.Allow is false) return;
|
||||
await UniTask.Delay(TimeSpan.FromSeconds(entryDuration.Value), cancellationToken: destroyCancellationToken);
|
||||
RootVisualElement?.RemoveFromClassList(USSEntered);
|
||||
RootVisualElement?.AddToClassList(USSExitAsync);
|
||||
|
||||
await OnExitAsync.UniTaskFunc();
|
||||
if (EntryDuration.Allow is false) return;
|
||||
await UniTask.Delay(TimeSpan.FromSeconds(EntryDuration.Value));
|
||||
}
|
||||
void IEntryElement.Exited()
|
||||
{
|
||||
document.rootVisualElement.RemoveFromClassList(USSExit);
|
||||
document.rootVisualElement.RemoveFromClassList(USSExitAsync);
|
||||
document.rootVisualElement.AddToClassList(USSEntry);
|
||||
document.rootVisualElement.SetActive(false);
|
||||
OnExit?.Invoke();
|
||||
RootVisualElement?.RemoveFromClassList(USSExit);
|
||||
RootVisualElement?.RemoveFromClassList(USSExitAsync);
|
||||
RootVisualElement?.AddToClassList(USSEntry);
|
||||
RootVisualElement?.SetActive(false);
|
||||
|
||||
if (AllowReload)
|
||||
{
|
||||
RootVisualElement?.RemoveFromHierarchy();
|
||||
RootVisualElement = null;
|
||||
}
|
||||
|
||||
OnExitCompleted?.Invoke();
|
||||
}
|
||||
public event Action OnEntry;
|
||||
public event Func<UniTask> OnEntryAsync;
|
||||
public event Action OnEntryCompleted;
|
||||
public event Action OnExit;
|
||||
public virtual void OnUpdate(float deltaTime)
|
||||
public event Func<UniTask> OnExitAsync;
|
||||
public event Action OnExitCompleted;
|
||||
|
||||
public virtual void OnTick(float deltaTime)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
54
Src/Unity/Scripts/UX/Service/UI Toolkit/UIToolkitOverlay.cs
Normal file
54
Src/Unity/Scripts/UX/Service/UI Toolkit/UIToolkitOverlay.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using BITKit.Mod;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine.UIElements;
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public abstract class UIToolkitOverlay:IDisposable
|
||||
{
|
||||
protected readonly CancellationTokenSource CancellationToken;
|
||||
protected readonly IUXService UXService;
|
||||
protected VisualElement RootVisualElement { get; set; }
|
||||
private bool _initialized;
|
||||
protected UIToolkitOverlay(IUXService uxService, CancellationTokenSource cancellationToken)
|
||||
{
|
||||
UXService = uxService;
|
||||
CancellationToken = cancellationToken;
|
||||
CancellationToken.Token.Register(Dispose);
|
||||
}
|
||||
|
||||
protected abstract string DocumentPath { get; }
|
||||
// ReSharper disable once MemberCanBeProtected.Global
|
||||
public virtual async UniTask InitializeAsync()
|
||||
{
|
||||
if(_initialized)return;
|
||||
var asset =await ModService.LoadAsset<VisualTreeAsset>(DocumentPath);
|
||||
var root= RootVisualElement = UXService.Root.As<VisualElement>().Create(asset);
|
||||
|
||||
RootVisualElement.BringToFront();
|
||||
|
||||
RootVisualElement.name = GetType().Name;
|
||||
RootVisualElement.pickingMode = PickingMode.Ignore;
|
||||
|
||||
root.style.position = Position.Absolute;
|
||||
root.style.top = 0;
|
||||
root.style.bottom = 0;
|
||||
root.style.left = 0;
|
||||
root.style.right = 0;
|
||||
|
||||
UXUtils.Inject(this);
|
||||
_initialized = true;
|
||||
}
|
||||
public virtual void Dispose()
|
||||
{
|
||||
if(RootVisualElement is null)return;
|
||||
_initialized = false;
|
||||
RootVisualElement.RemoveFromHierarchy();
|
||||
RootVisualElement = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 66eb43c99c2ef43439773eee1acc7676
|
||||
guid: e78199af4607c0d438836fd782fdf8ff
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
@@ -1,18 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class UIToolkitPanelDebuger : UIToolKitPanel
|
||||
{
|
||||
[SerializeField] private InputActionGroup inputActionGroup;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
inputActionGroup = InputActionGroup;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
11
Src/Unity/Scripts/UX/Service/UI Toolkit/UIToolkitSubPanel.cs
Normal file
11
Src/Unity/Scripts/UX/Service/UI Toolkit/UIToolkitSubPanel.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using BITKit.UX;
|
||||
using UnityEngine;
|
||||
|
||||
public class UIToolkitSubPanel
|
||||
{
|
||||
public UIToolkitSubPanel()
|
||||
{
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2dbf277baef324944aa89bbd72966261
|
||||
guid: 398253ee7f746d143bbbcd9effab9da1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
@@ -1,64 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using BITKit.Mod;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace BITKit.UX
|
||||
{
|
||||
/// <summary>
|
||||
/// 适用于Unity的UX Service
|
||||
/// </summary>
|
||||
public class UxService : MonoBehaviour, IUXService
|
||||
public class UXService : IUXService
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 重新初始化,使用<see cref="RuntimeInitializeLoadType.SubsystemRegistration"/>确保在所有子系统注册后执行
|
||||
/// </summary>
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
private static void Initialized()
|
||||
private readonly IAfterTicker _ticker;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
public UXService(IAfterTicker ticker, IServiceProvider serviceProvider)
|
||||
{
|
||||
RegistryQueue.Clear();
|
||||
UnRegistryQueue.Clear();
|
||||
Panels.Clear();
|
||||
EntryQueue.Clear();
|
||||
_currentPanel = null;
|
||||
History.Clear();
|
||||
_entryGroup = new EntryGroup<IUXPanel>();
|
||||
_windowEntryGroup = new EntryGroup<IUXPanel>();
|
||||
_ticker = ticker;
|
||||
_serviceProvider = serviceProvider;
|
||||
_entryGroup.OnEntry += OnEntry;
|
||||
_ticker.Add(OnTick);
|
||||
}
|
||||
|
||||
|
||||
private static EntryGroup<IUXPanel> _entryGroup = new();
|
||||
private static EntryGroup<IUXPanel> _windowEntryGroup = new();
|
||||
|
||||
private readonly EntryGroup<IUXPanel> _entryGroup = new();
|
||||
private readonly EntryGroup<IUXPanel> _windowEntryGroup = new();
|
||||
/// <summary>
|
||||
/// 内部注册面板队列
|
||||
/// </summary>
|
||||
private static readonly Queue<IUXPanel> RegistryQueue = new();
|
||||
private readonly Queue<IUXPanel> _registryQueue = new();
|
||||
|
||||
/// <summary>
|
||||
/// 内部注销面板队列
|
||||
/// </summary>
|
||||
private static readonly Queue<IUXPanel> UnRegistryQueue = new();
|
||||
private readonly Queue<IUXPanel> _unRegistryQueue = new();
|
||||
|
||||
/// <summary>
|
||||
/// 已注册面板字典
|
||||
/// </summary>
|
||||
private static readonly Dictionary<string, IUXPanel> Panels = new();
|
||||
private readonly Dictionary<string, IUXPanel> _panels = new();
|
||||
|
||||
/// <summary>
|
||||
/// 等待启用的面板队列
|
||||
/// </summary>
|
||||
private static readonly Stack<IUXPanel> EntryQueue = new();
|
||||
private readonly Stack<IUXPanel> _entryQueue = new();
|
||||
private readonly List<string> _entryQueueByName = new();
|
||||
|
||||
/// <summary>
|
||||
/// 返回面板缓冲区
|
||||
/// </summary>
|
||||
private static readonly DoubleBuffer<IUXPanel> ReturnBuffer = new();
|
||||
private readonly DoubleBuffer<IUXPanel> _returnBuffer = new();
|
||||
|
||||
/// <summary>
|
||||
/// 已启用面板
|
||||
/// </summary>
|
||||
private static IUXPanel _currentPanel;
|
||||
private IUXPanel _currentPanel;
|
||||
|
||||
/// <summary>
|
||||
/// 历史面板
|
||||
@@ -70,13 +68,43 @@ namespace BITKit.UX
|
||||
/// </summary>
|
||||
public static void ClearHistory() => History.Clear();
|
||||
|
||||
public static void Register(IUXPanel panel) => RegistryQueue.Enqueue(panel);
|
||||
public object Root { get; private set; }
|
||||
public async UniTask InitializeAsync()
|
||||
{
|
||||
|
||||
var gameObject = new GameObject("UXService");
|
||||
Object.DontDestroyOnLoad(gameObject);
|
||||
var document = gameObject.AddComponent<UIDocument>();
|
||||
try
|
||||
{
|
||||
var panelSettings =await ModService.LoadAsset<PanelSettings>("ux_panel_settings");
|
||||
document.panelSettings = panelSettings;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
BIT4Log.Warning<UXService>("未找到ux_panel_settings");
|
||||
throw;
|
||||
}
|
||||
|
||||
|
||||
Root = document.rootVisualElement;
|
||||
}
|
||||
|
||||
public static void UnRegister(IUXPanel panel) => UnRegistryQueue.Enqueue(panel);
|
||||
public void Register(IUXPanel panel) => _registryQueue.Enqueue(panel);
|
||||
|
||||
public static void Entry<T>() where T : IUXPanel => EntryQueue.Push(Panels[typeof(T).Name]);
|
||||
public void UnRegister(IUXPanel panel) => _unRegistryQueue.Enqueue(panel);
|
||||
|
||||
public static void Return()
|
||||
public void Entry<T>() where T : IUXPanel
|
||||
{
|
||||
var panel = _serviceProvider.GetRequiredService<T>();
|
||||
Entry(panel);
|
||||
//Entry(typeof(T).Name);
|
||||
}
|
||||
|
||||
public void Entry(IUXPanel panel) => _entryQueue.Push(panel);
|
||||
public void Entry(string panelName) => _entryQueueByName.TryAdd(panelName);
|
||||
|
||||
public void Return()
|
||||
{
|
||||
if(_windowEntryGroup.TryGetEntried(out _))
|
||||
{
|
||||
@@ -85,70 +113,58 @@ namespace BITKit.UX
|
||||
}
|
||||
if (History.TryPop(out var returnPanel))
|
||||
{
|
||||
ReturnBuffer.Release(returnPanel);
|
||||
_returnBuffer.Release(returnPanel);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Entry(IUXPanel panel) => EntryQueue.Push(panel);
|
||||
private static void Entry(string panelName) => EntryQueue.Push(Panels[panelName]);
|
||||
|
||||
[SerializeReference, SubclassSelector] private IUXPanel initialPanel;
|
||||
|
||||
[SerializeField, ReadOnly(HideLabel = true)]
|
||||
private string log;
|
||||
private StringBuilder _reportBuilder = new();
|
||||
|
||||
|
||||
private bool _initialized;
|
||||
private void Start()
|
||||
{
|
||||
_entryGroup.OnEntry += OnEntry;
|
||||
_entryGroup.OnExit += OnExit;
|
||||
}
|
||||
private static void OnExit(IUXPanel obj)
|
||||
{
|
||||
//History.Push(obj);
|
||||
}
|
||||
private static void OnEntry(IUXPanel obj)
|
||||
|
||||
|
||||
private void OnEntry(IUXPanel obj)
|
||||
{
|
||||
_currentPanel = obj;
|
||||
}
|
||||
private void Update()
|
||||
private void OnTick(float delta)
|
||||
{
|
||||
try
|
||||
{
|
||||
while (RegistryQueue.TryDequeue(out var result))
|
||||
while (_registryQueue.TryDequeue(out var result))
|
||||
{
|
||||
if (result is null) continue;
|
||||
_reportBuilder.AppendLine(("注册面板:" + result.Index));
|
||||
_entryGroup.list.Add(result);
|
||||
Panels.Set(result.Index, result);
|
||||
_panels.Set(result.Index, result);
|
||||
}
|
||||
|
||||
while (UnRegistryQueue.TryDequeue(out var result))
|
||||
while (_unRegistryQueue.TryDequeue(out var result))
|
||||
{
|
||||
if (result is null) continue;
|
||||
_reportBuilder.AppendLine(("注销面板:" + result.Index));
|
||||
_entryGroup.list.Remove(result);
|
||||
Panels.Remove(result.Index);
|
||||
_panels.Remove(result.Index);
|
||||
}
|
||||
|
||||
if (ReturnBuffer.TryGetRelease(out var returnPanel))
|
||||
if (_returnBuffer.TryGetRelease(out var returnPanel))
|
||||
{
|
||||
_reportBuilder.AppendLine(("返回面板:" + returnPanel.Index));
|
||||
_entryGroup.Entry(x=>x.Index==returnPanel.Index);
|
||||
BITAppForUnity.AllowCursor.SetElements(this, returnPanel.AllowCursor);
|
||||
BITInputSystem.AllowInput.SetElements(this, returnPanel.AllowInput);
|
||||
}
|
||||
|
||||
if (EntryQueue.TryPop(out var nextPanel))
|
||||
|
||||
foreach (var panelName in _entryQueueByName)
|
||||
{
|
||||
if (!_panels.TryGetValue(panelName, out var panel))continue;
|
||||
_entryQueue.Push(panel);
|
||||
_entryQueueByName.TryRemove(panelName);
|
||||
break;
|
||||
}
|
||||
if (_entryQueue.TryPop(out var nextPanel))
|
||||
{
|
||||
if (nextPanel.IsWindow)
|
||||
{
|
||||
_reportBuilder.AppendLine(("窗口面板:" + nextPanel.Index));
|
||||
_windowEntryGroup.Entry(nextPanel);
|
||||
return;
|
||||
}
|
||||
_reportBuilder.AppendLine(("启用面板:" + nextPanel.Index));
|
||||
_windowEntryGroup.Entry(-1);
|
||||
History.Push(_currentPanel);
|
||||
_entryGroup.Entry(x=>x.Index==nextPanel.Index);
|
||||
@@ -157,36 +173,31 @@ namespace BITKit.UX
|
||||
}
|
||||
if (_entryGroup.TryGetEntried(out var currentPanel))
|
||||
{
|
||||
currentPanel.OnUpdate(Time.deltaTime);
|
||||
currentPanel.OnTick(Time.deltaTime);
|
||||
}
|
||||
if(_windowEntryGroup.TryGetEntried(out var windowPanel))
|
||||
{
|
||||
windowPanel.OnUpdate(Time.deltaTime);
|
||||
}
|
||||
|
||||
if (currentPanel is null && Panels.Count > 0)
|
||||
{
|
||||
Entry(initialPanel);
|
||||
windowPanel.OnTick(Time.deltaTime);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
BIT4Log.LogException(e);
|
||||
}
|
||||
log = _reportBuilder.ToString();
|
||||
}
|
||||
|
||||
void IUXService.Register(IUXPanel panel) => Register(panel);
|
||||
|
||||
void IUXService.UnRegister(IUXPanel panel) => UnRegister(panel);
|
||||
|
||||
void IUXService.Entry<T>() => Entry<T>();
|
||||
|
||||
void IUXService.Return() => Return();
|
||||
|
||||
void IUXService.Entry(IUXPanel panel) => Entry(panel);
|
||||
|
||||
void IUXService.Entry(string panelName) => Entry(panelName);
|
||||
public async void Dispose()
|
||||
{
|
||||
_ticker.Remove(OnTick);
|
||||
await UniTask.SwitchToMainThread();
|
||||
if (_currentPanel is not null)
|
||||
{
|
||||
// ReSharper disable once MethodHasAsyncOverload
|
||||
_currentPanel.Exit();
|
||||
await _currentPanel.ExitAsync();
|
||||
_currentPanel.Exited();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user