This commit is contained in:
CortexCore
2025-03-24 14:42:40 +08:00
parent 18239a5ae4
commit 9845d20f7f
99 changed files with 5418 additions and 5512 deletions

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Text;
using System.Threading;
using BITKit.Mod;
using BITKit.StateMachine;
using Cysharp.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Unity.Mathematics;
@@ -27,10 +28,9 @@ namespace BITKit.UX
_ticker = ticker;
_serviceProvider = serviceProvider;
_cancellationTokenSource = cancellationTokenSource;
_entryGroup.OnEntry += OnEntry;
_entryGroup.OnStateChanged += OnEntry;
_windowEntryGroup.OnEntry += OnWindowEntry;
_windowEntryGroup.OnExit += OnWindowExit;
_windowEntryGroup.OnStateChanged += OnWindowEntry;
_ticker.Add(OnTick);
}
@@ -41,15 +41,15 @@ namespace BITKit.UX
BITInputSystem.AllowInput.RemoveDisableElements(_windowEntryGroup);
}
private void OnWindowEntry(IUXPanel obj)
private void OnWindowEntry(IUXPanel prev, IUXPanel next)
{
BITAppForUnity.AllowCursor.SetElements(_windowEntryGroup, obj.AllowCursor);
if (obj.AllowInput is false)
BITInputSystem.AllowInput.AddDisableElements(_windowEntryGroup);
BITAppForUnity.AllowCursor.SetElements(_windowEntryGroup, next is { AllowCursor: true });
BITInputSystem.AllowInput.SetDisableElements(_windowEntryGroup, next is { AllowInput: false });
}
private readonly EntryGroup<IUXPanel> _entryGroup = new();
private readonly EntryGroup<IUXPanel> _windowEntryGroup = new();
private readonly AsyncStateMachine<IUXPanel> _entryGroup = new();
private readonly AsyncStateMachine<IUXPanel> _windowEntryGroup = new();
/// <summary>
/// 内部注册面板队列
/// </summary>
@@ -163,9 +163,9 @@ Object.Destroy(gameObject);
public void Return()
{
if(_windowEntryGroup.TryGetEntried(out _))
if (_windowEntryGroup.CurrentState is not null)
{
_windowEntryGroup.Entry(-1);
_windowEntryGroup.DisposeState();
return;
}
if (History.TryPop(out var returnPanel))
@@ -173,16 +173,15 @@ Object.Destroy(gameObject);
_returnBuffer.Release(returnPanel);
}
}
private bool _initialized;
private void OnEntry(IUXPanel obj)
private void OnEntry(IUXPanel prev,IUXPanel next)
{
OnPanelChanged?.Invoke(_currentPanel,obj);
_currentPanel = obj;
OnPanelChanged?.Invoke(_currentPanel,next);
_currentPanel = next;
}
private void OnTick(float delta)
{
@@ -192,20 +191,20 @@ Object.Destroy(gameObject);
while (_registryQueue.TryDequeue(out var result))
{
if (result is null) continue;
_entryGroup.list.Add(result);
_entryGroup.Register(result);
_panels.Set(result.Index, result);
}
while (_unRegistryQueue.TryDequeue(out var result))
{
if (result is null) continue;
_entryGroup.list.Remove(result);
_entryGroup.UnRegister(result);
_panels.Remove(result.Index);
}
if (_returnBuffer.TryGetRelease(out var returnPanel))
{
_entryGroup.Entry(x=>x.Index==returnPanel.Index);
_entryGroup.TransitionState(returnPanel);
BITAppForUnity.AllowCursor.SetElements(this, returnPanel.AllowCursor);
BITInputSystem.AllowInput.SetElements(this, returnPanel.AllowInput);
}
@@ -221,22 +220,23 @@ Object.Destroy(gameObject);
{
if (nextPanel.IsWindow)
{
_windowEntryGroup.Entry(nextPanel);
_windowEntryGroup.TransitionState(nextPanel);
return;
}
_windowEntryGroup.Entry(-1);
_windowEntryGroup.DisposeState();
History.Push(_currentPanel);
_entryGroup.Entry(x=>x.Index==nextPanel.Index);
_entryGroup.TransitionState(nextPanel);
BITAppForUnity.AllowCursor.SetElements(this, nextPanel.AllowCursor);
BITInputSystem.AllowInput.SetElements(this, nextPanel.AllowInput);
}
if (_entryGroup.TryGetEntried(out var currentPanel))
if (_entryGroup.CurrentState is {Enabled:true})
{
currentPanel.OnTick(Time.deltaTime);
_entryGroup.CurrentState.OnTick(delta);
}
if(_windowEntryGroup.TryGetEntried(out var windowPanel))
if (_windowEntryGroup.CurrentState is {Enabled:true})
{
windowPanel.OnTick(Time.deltaTime);
_windowEntryGroup.CurrentState.OnTick(delta);
}
}
catch (Exception e)
@@ -256,13 +256,8 @@ Object.Destroy(gameObject);
}
_ticker.Remove(OnTick);
await UniTask.SwitchToMainThread();
if (_currentPanel is not null)
{
// ReSharper disable once MethodHasAsyncOverload
_currentPanel.Exit();
await _currentPanel.ExitAsync();
_currentPanel.Exited();
}
_entryGroup.Dispose();
_windowEntryGroup.Dispose();
}
}
}