|
|
|
@@ -1,6 +1,7 @@
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using BITKit.Mod;
|
|
|
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
@@ -8,6 +9,8 @@ using UnityEngine;
|
|
|
|
|
using UnityEngine.Serialization;
|
|
|
|
|
using UnityEngine.InputSystem;
|
|
|
|
|
using UnityEngine.UIElements;
|
|
|
|
|
using Debug = UnityEngine.Debug;
|
|
|
|
|
|
|
|
|
|
// ReSharper disable MemberCanBeProtected.Global
|
|
|
|
|
// ReSharper disable ClassWithVirtualMembersNeverInherited.Global
|
|
|
|
|
// ReSharper disable UnusedMember.Global
|
|
|
|
@@ -30,6 +33,7 @@ namespace BITKit.UX
|
|
|
|
|
protected VisualTreeAsset VisualTreeAsset { get; private set; }
|
|
|
|
|
private readonly ValidHandle _isBusy = new();
|
|
|
|
|
public readonly UniTaskCompletionSource WaitUtilInitialized = new();
|
|
|
|
|
protected UniTaskCompletionSource WaitUtilTransitionCompleted=new();
|
|
|
|
|
protected UIToolKitPanel(IUXService uxService)
|
|
|
|
|
{
|
|
|
|
|
UXService = uxService;
|
|
|
|
@@ -86,11 +90,26 @@ namespace BITKit.UX
|
|
|
|
|
await OnInitiatedAsync.UniTaskFunc();
|
|
|
|
|
|
|
|
|
|
WaitUtilInitialized.TrySetResult();
|
|
|
|
|
|
|
|
|
|
RootVisualElement.RegisterCallback<TransitionRunEvent>(OnTransitionRun);
|
|
|
|
|
RootVisualElement.RegisterCallback<TransitionStartEvent>(OnTransitionStart);
|
|
|
|
|
RootVisualElement.RegisterCallback<TransitionEndEvent>(OnTransitionEnd);
|
|
|
|
|
RootVisualElement.RegisterCallback<TransitionCancelEvent>(OnTransitionEnd);
|
|
|
|
|
|
|
|
|
|
WaitUtilTransitionCompleted.TrySetResult();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual Optional<float> EntryDuration { get; }= new();
|
|
|
|
|
protected virtual Optional<float> ExitDuration { get; }= new();
|
|
|
|
|
|
|
|
|
|
private void OnTransitionStart(TransitionStartEvent evt)
|
|
|
|
|
{
|
|
|
|
|
WaitUtilTransitionCompleted = new();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnTransitionRun(TransitionRunEvent evt)
|
|
|
|
|
{
|
|
|
|
|
//WaitUtilTransitionCompleted = new();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected static readonly InputActionGroup InputActionGroup = new()
|
|
|
|
|
{
|
|
|
|
|
allowGlobalActivation = false,
|
|
|
|
@@ -120,27 +139,21 @@ namespace BITKit.UX
|
|
|
|
|
{
|
|
|
|
|
await InitializeAsync();
|
|
|
|
|
|
|
|
|
|
//WaitUtilTransitionCompleted = new();
|
|
|
|
|
|
|
|
|
|
RootVisualElement.SetActive(true);
|
|
|
|
|
|
|
|
|
|
//await UniTask.NextFrame();
|
|
|
|
|
|
|
|
|
|
RootVisualElement.AddToClassList(USSEntry);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await UniTask.NextFrame();
|
|
|
|
|
|
|
|
|
|
RootVisualElement.AddToClassList(USSEntryAsync);
|
|
|
|
|
|
|
|
|
|
await UniTask.NextFrame();
|
|
|
|
|
|
|
|
|
|
if (EntryDuration.Allow)
|
|
|
|
|
{
|
|
|
|
|
var task = EntryAsync();
|
|
|
|
|
var durationTask = UniTask.Delay(TimeSpan.FromSeconds(EntryDuration.Value));
|
|
|
|
|
|
|
|
|
|
await durationTask;
|
|
|
|
|
RootVisualElement.RemoveFromClassList(USSEntry);
|
|
|
|
|
RootVisualElement.RemoveFromClassList(USSEntryAsync);
|
|
|
|
|
RootVisualElement.AddToClassList(USSEntered);
|
|
|
|
|
|
|
|
|
|
await task;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await EntryAsync();
|
|
|
|
|
}
|
|
|
|
|
await EntryAsync();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
@@ -153,9 +166,17 @@ namespace BITKit.UX
|
|
|
|
|
{
|
|
|
|
|
BIT4Log.LogException(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await WaitUtilTransitionCompleted.Task;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public virtual UniTask EntryAsync()
|
|
|
|
|
RootVisualElement.AddToClassList(USSEntered);
|
|
|
|
|
}
|
|
|
|
|
private void OnTransitionEnd<TChangeEvent>(TChangeEvent evt)
|
|
|
|
|
{
|
|
|
|
|
WaitUtilTransitionCompleted.TrySetResult();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual UniTask EntryAsync()
|
|
|
|
|
{
|
|
|
|
|
return UniTask.CompletedTask;
|
|
|
|
|
}
|
|
|
|
@@ -163,11 +184,13 @@ namespace BITKit.UX
|
|
|
|
|
{
|
|
|
|
|
OnPanelEntry();
|
|
|
|
|
OnEntryCompleted?.Invoke();
|
|
|
|
|
|
|
|
|
|
RootVisualElement.RemoveFromClassList(USSEntry);
|
|
|
|
|
RootVisualElement.RemoveFromClassList(USSEntryAsync);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IEntryElement.Exit()
|
|
|
|
|
{
|
|
|
|
|
RootVisualElement?.AddToClassList(USSExit);
|
|
|
|
|
OnPanelExit();
|
|
|
|
|
InputActionGroup.allowInput.RemoveElement(this);
|
|
|
|
|
OnExit?.Invoke();
|
|
|
|
@@ -175,17 +198,26 @@ namespace BITKit.UX
|
|
|
|
|
async UniTask IEntryElement.ExitAsync()
|
|
|
|
|
{
|
|
|
|
|
RootVisualElement?.RemoveFromClassList(USSEntered);
|
|
|
|
|
await UniTask.NextFrame();
|
|
|
|
|
|
|
|
|
|
RootVisualElement?.AddToClassList(USSExit);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await UniTask.NextFrame();
|
|
|
|
|
|
|
|
|
|
RootVisualElement?.AddToClassList(USSExitAsync);
|
|
|
|
|
|
|
|
|
|
await UniTask.NextFrame();
|
|
|
|
|
|
|
|
|
|
await OnExitAsync.UniTaskFunc();
|
|
|
|
|
if (EntryDuration.Allow is false) return;
|
|
|
|
|
await UniTask.Delay(TimeSpan.FromSeconds(EntryDuration.Value));
|
|
|
|
|
|
|
|
|
|
await WaitUtilTransitionCompleted.Task;
|
|
|
|
|
}
|
|
|
|
|
void IEntryElement.Exited()
|
|
|
|
|
{
|
|
|
|
|
RootVisualElement?.RemoveFromClassList(USSExit);
|
|
|
|
|
RootVisualElement?.RemoveFromClassList(USSExitAsync);
|
|
|
|
|
RootVisualElement?.AddToClassList(USSEntry);
|
|
|
|
|
RootVisualElement?.AddToClassList(USSExited);
|
|
|
|
|
RootVisualElement?.SetActive(false);
|
|
|
|
|
|
|
|
|
|
if (AllowReload)
|
|
|
|
|