add kcp
This commit is contained in:
65
Src/Unity/Scripts/UX/Utils/UXTabContainerEvent.cs
Normal file
65
Src/Unity/Scripts/UX/Utils/UXTabContainerEvent.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class UXTabContainerEvent : UXElement<TabContainer>
|
||||
{
|
||||
[Tooltip("基于<see cref=\"TabBar\"/>的Tab切换事件")]
|
||||
[SerializeField] private UnityEvent<bool>[] onEntryTab;
|
||||
|
||||
[SerializeField] private UnityEvent[] onEntry;
|
||||
[SerializeField] private UnityEvent[] onExit;
|
||||
|
||||
private readonly DoubleBuffer<int> tabBuffer = new();
|
||||
private CancellationToken _cancellationToken;
|
||||
public override void OnAwake()
|
||||
{
|
||||
base.OnAwake();
|
||||
_cancellationToken = gameObject.GetCancellationTokenOnDestroy();
|
||||
}
|
||||
|
||||
public override async void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
visualElement.OnTabChanged += OnTabChanged;
|
||||
foreach (var unityEvent in onEntryTab)
|
||||
{
|
||||
unityEvent.Invoke(false);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await UniTask.NextFrame(_cancellationToken);
|
||||
OnTabChanged(visualElement.CurrentTab);
|
||||
}
|
||||
catch(OperationCanceledException){}
|
||||
}
|
||||
private void OnTabChanged(int obj)
|
||||
{
|
||||
if(onEntryTab.TryGetElementAt(tabBuffer.Current,out var unityEvent))
|
||||
{
|
||||
unityEvent.Invoke(false);
|
||||
}
|
||||
if(onEntryTab.TryGetElementAt(obj, out unityEvent))
|
||||
{
|
||||
unityEvent.Invoke(true);
|
||||
}
|
||||
if(onExit.TryGetElementAt(tabBuffer.Current,out var exitEvent))
|
||||
{
|
||||
exitEvent.Invoke();
|
||||
}
|
||||
if(onEntry.TryGetElementAt(obj, out var entryEvent))
|
||||
{
|
||||
entryEvent.Invoke();
|
||||
}
|
||||
tabBuffer.Release(obj);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user