1
This commit is contained in:
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Cysharp.Threading.Tasks;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
@@ -15,6 +16,7 @@ namespace BITKit.UX
|
||||
/// </summary>
|
||||
public class UXService : MonoBehaviour, IUXService
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 重新初始化,使用<see cref="RuntimeInitializeLoadType.SubsystemRegistration"/>确保在所有子系统注册后执行
|
||||
/// </summary>
|
||||
@@ -25,10 +27,13 @@ namespace BITKit.UX
|
||||
UnRegistryQueue.Clear();
|
||||
Panels.Clear();
|
||||
EntryQueue.Clear();
|
||||
EntryCompletedPanels.Clear();
|
||||
CurrentPanel = null;
|
||||
History.Clear();
|
||||
EntryGroup = new EntryGroup<IUXPanel>();
|
||||
}
|
||||
|
||||
|
||||
private static EntryGroup<IUXPanel> EntryGroup = new();
|
||||
/// <summary>
|
||||
/// 内部注册面板队列
|
||||
/// </summary>
|
||||
@@ -52,12 +57,12 @@ namespace BITKit.UX
|
||||
/// <summary>
|
||||
/// 已启用面板
|
||||
/// </summary>
|
||||
internal static readonly Stack<IUXPanel> EntryCompletedPanels = new();
|
||||
internal static IUXPanel CurrentPanel;
|
||||
|
||||
/// <summary>
|
||||
/// 历史面板
|
||||
/// </summary>
|
||||
private static readonly Stack<IUXPanel> History = new();
|
||||
internal static readonly Stack<IUXPanel> History = new();
|
||||
|
||||
public static void Register(IUXPanel panel) => RegistryQueue.Enqueue(panel);
|
||||
|
||||
@@ -67,7 +72,6 @@ namespace BITKit.UX
|
||||
|
||||
public static void Return()
|
||||
{
|
||||
if (!History.TryPop(out _)) return;
|
||||
if (History.TryPop(out var returnPanel))
|
||||
{
|
||||
Entry(returnPanel);
|
||||
@@ -80,57 +84,92 @@ namespace BITKit.UX
|
||||
|
||||
[SerializeReference, SubclassSelector] private IUXPanel initialPanel;
|
||||
|
||||
|
||||
|
||||
private bool initialized;
|
||||
private void Awake()
|
||||
{
|
||||
DI.Register<IUXService>(this);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
private void Start()
|
||||
{
|
||||
EntryGroup.OnEntry += OnEntry;
|
||||
EntryGroup.OnExit += OnExit;
|
||||
|
||||
if (initialPanel is not null)
|
||||
{
|
||||
Entry(initialPanel);
|
||||
}
|
||||
}
|
||||
private static void OnExit(IUXPanel obj)
|
||||
{
|
||||
History.Push(obj);
|
||||
}
|
||||
private static void OnEntry(IUXPanel obj)
|
||||
{
|
||||
CurrentPanel = obj;
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
while (UnRegistryQueue.TryDequeue(out var result))
|
||||
{
|
||||
if (result is null) continue;
|
||||
EntryGroup.list.Remove(result);
|
||||
Panels.Remove(result.Index);
|
||||
}
|
||||
|
||||
while (RegistryQueue.TryDequeue(out var result))
|
||||
{
|
||||
if (result is null) continue;
|
||||
EntryGroup.list.Add(result);
|
||||
Panels.Set(result.Index, result);
|
||||
result.Exit();
|
||||
}
|
||||
|
||||
if (initialized is false && initialPanel is not null)
|
||||
if (EntryQueue.TryPop(out var nextPanel))
|
||||
{
|
||||
initialized = true;
|
||||
Entry(initialPanel);
|
||||
EntryGroup.Entry(x=>x.Index==nextPanel.Index);
|
||||
BITAppForUnity.AllowCursor.SetElements(this, nextPanel.AllowCursor);
|
||||
BITInputSystem.AllowInput.SetElements(this, nextPanel.AllowInput);
|
||||
}
|
||||
|
||||
if (!EntryQueue.TryPop(out var next) || next is null) return;
|
||||
if (EntryGroup.TryGetEntried(out var currentPanel))
|
||||
{
|
||||
currentPanel.OnUpdate(Time.deltaTime);
|
||||
};
|
||||
|
||||
if (Panels.ContainsKey(next.Index) is false) return;
|
||||
|
||||
while (EntryCompletedPanels.TryPop(out var entryCompletedPanel))
|
||||
{
|
||||
entryCompletedPanel?.Exit();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
next.Entry();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogWarning(next.Index);
|
||||
Debug.LogException(e);
|
||||
}
|
||||
|
||||
BITAppForUnity.AllowCursor.SetElements(this, next.AllowCursor);
|
||||
BITInputSystem.AllowInput.SetElements(this, next.AllowInput);
|
||||
|
||||
EntryCompletedPanels.Push(next);
|
||||
History.Push(next);
|
||||
// if (initialized is false && initialPanel is not null)
|
||||
// {
|
||||
// initialized = true;
|
||||
// Entry(initialPanel);
|
||||
// }
|
||||
//
|
||||
// if (!EntryQueue.TryPop(out var next) || next is null) return;
|
||||
//
|
||||
// if (Panels.ContainsKey(next.Index) is false) return;
|
||||
//
|
||||
// while (EntryCompletedPanels.TryPop(out var entryCompletedPanel))
|
||||
// {
|
||||
// entryCompletedPanel?.Exit();
|
||||
// }
|
||||
//
|
||||
// try
|
||||
// {
|
||||
// next.Entry();
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// Debug.LogWarning(next.Index);
|
||||
// Debug.LogException(e);
|
||||
// }
|
||||
//
|
||||
// BITAppForUnity.AllowCursor.SetElements(this, next.AllowCursor);
|
||||
// BITInputSystem.AllowInput.SetElements(this, next.AllowInput);
|
||||
//
|
||||
// EntryCompletedPanels.Push(next);
|
||||
// History.Push(next);
|
||||
}
|
||||
|
||||
void IUXService.Register(IUXPanel panel) => Register(panel);
|
||||
@@ -151,6 +190,7 @@ namespace BITKit.UX
|
||||
{
|
||||
private Label currentPanelLabel;
|
||||
private Label panelsLabel;
|
||||
private Label historyLabel;
|
||||
public override VisualElement CreateInspectorGUI()
|
||||
{
|
||||
FillDefaultInspector();
|
||||
@@ -158,16 +198,18 @@ namespace BITKit.UX
|
||||
currentPanelLabel = root.Create<Label>();
|
||||
CreateSubTitle("Panels");
|
||||
panelsLabel = root.Create<Label>();
|
||||
CreateSubTitle("History");
|
||||
historyLabel = root.Create<Label>();
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
if (panelsLabel is null || currentPanelLabel is null) return;
|
||||
if (panelsLabel is null || currentPanelLabel is null || historyLabel is null) return;
|
||||
panelsLabel.text=string.Join("\n",UXService.Panels);
|
||||
currentPanelLabel.text = string.Join("\n",UXService.EntryCompletedPanels.Select(x=>x.Index));
|
||||
|
||||
currentPanelLabel.text = string.Join("\n",UXService.CurrentPanel?.Index);
|
||||
historyLabel.text = string.Join("\n",UXService.History.Select(x=>x.Index));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user