1
This commit is contained in:
@@ -5,7 +5,10 @@ using System.Threading;
|
||||
using BITKit.Mod;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UIElements;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
@@ -25,9 +28,26 @@ namespace BITKit.UX
|
||||
_serviceProvider = serviceProvider;
|
||||
_cancellationTokenSource = cancellationTokenSource;
|
||||
_entryGroup.OnEntry += OnEntry;
|
||||
|
||||
_windowEntryGroup.OnEntry += OnWindowEntry;
|
||||
_windowEntryGroup.OnExit += OnWindowExit;
|
||||
_ticker.Add(OnTick);
|
||||
}
|
||||
|
||||
|
||||
private void OnWindowExit(IUXPanel obj)
|
||||
{
|
||||
BITAppForUnity.AllowCursor.RemoveElement(_windowEntryGroup);
|
||||
if (obj.AllowInput is false)
|
||||
BITInputSystem.AllowInput.RemoveDisableElements(_windowEntryGroup);
|
||||
}
|
||||
|
||||
private void OnWindowEntry(IUXPanel obj)
|
||||
{
|
||||
BITAppForUnity.AllowCursor.SetElements(_windowEntryGroup, obj.AllowCursor);
|
||||
if (obj.AllowInput is false)
|
||||
BITInputSystem.AllowInput.AddDisableElements(_windowEntryGroup);
|
||||
}
|
||||
|
||||
private readonly EntryGroup<IUXPanel> _entryGroup = new();
|
||||
private readonly EntryGroup<IUXPanel> _windowEntryGroup = new();
|
||||
/// <summary>
|
||||
@@ -73,9 +93,9 @@ namespace BITKit.UX
|
||||
|
||||
public string SettingsPath { get; set; } = "ux_panel_settings";
|
||||
public object Root { get; private set; }
|
||||
public static VisualElement RootVisualElement { get; private set; }
|
||||
public async UniTask InitializeAsync()
|
||||
{
|
||||
|
||||
var gameObject = new GameObject("UXService");
|
||||
Object.DontDestroyOnLoad(gameObject);
|
||||
|
||||
@@ -87,6 +107,11 @@ Object.Destroy(gameObject);
|
||||
var document = gameObject.AddComponent<UIDocument>();
|
||||
try
|
||||
{
|
||||
if (Touchscreen.current is not null && SettingsPath == "ux_panel_settings")
|
||||
{
|
||||
SettingsPath = "ux_panel_settings_mobile";
|
||||
}
|
||||
|
||||
var panelSettings =await ModService.LoadAsset<PanelSettings>(SettingsPath);
|
||||
document.panelSettings = panelSettings;
|
||||
}
|
||||
@@ -96,8 +121,12 @@ Object.Destroy(gameObject);
|
||||
throw;
|
||||
}
|
||||
|
||||
|
||||
Root = document.rootVisualElement;
|
||||
Root = RootVisualElement= document.rootVisualElement;
|
||||
|
||||
if (Touchscreen.current is not null)
|
||||
{
|
||||
RootVisualElement.AddToClassList("mobile");
|
||||
}
|
||||
}
|
||||
|
||||
public void Register(IUXPanel panel) => _registryQueue.Enqueue(panel);
|
||||
@@ -115,6 +144,22 @@ Object.Destroy(gameObject);
|
||||
public void Entry(string panelName) => _entryQueueByName.TryAdd(panelName);
|
||||
public IUXPanel CurrentPanel => _currentPanel;
|
||||
public event Action<IUXPanel, IUXPanel> OnPanelChanged;
|
||||
public bool TryPick(float2 position, out object obj)
|
||||
{
|
||||
obj = null;
|
||||
if (!EventSystem.current.IsPointerOverGameObject())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
position.y = Screen.height - position.y;
|
||||
|
||||
var ve = RootVisualElement.panel.Pick(RuntimePanelUtils.ScreenToPanel(RootVisualElement.panel, position));
|
||||
|
||||
obj = ve;
|
||||
|
||||
return obj is not null;
|
||||
}
|
||||
|
||||
public void Return()
|
||||
{
|
||||
@@ -143,6 +188,7 @@ Object.Destroy(gameObject);
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
while (_registryQueue.TryDequeue(out var result))
|
||||
{
|
||||
if (result is null) continue;
|
||||
@@ -201,6 +247,13 @@ Object.Destroy(gameObject);
|
||||
|
||||
public async void Dispose()
|
||||
{
|
||||
foreach (var panelsValue in _panels.Values)
|
||||
{
|
||||
if (panelsValue is IDisposable disposable)
|
||||
{
|
||||
disposable.Dispose();
|
||||
}
|
||||
}
|
||||
_ticker.Remove(OnTick);
|
||||
await UniTask.SwitchToMainThread();
|
||||
if (_currentPanel is not null)
|
||||
|
Reference in New Issue
Block a user