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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
11
Src/Unity/Scripts/UX/Utils/UXTabContainerEvent.cs.meta
Normal file
11
Src/Unity/Scripts/UX/Utils/UXTabContainerEvent.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1348cd99518aa184dadd0fd312462029
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@@ -5,6 +6,7 @@ using BITKit;
|
||||
using UnityEngine.Events;
|
||||
namespace BITKit.UX
|
||||
{
|
||||
[Obsolete]
|
||||
public class UXWindowEvent : MonoBehaviour, IWindowComponent
|
||||
{
|
||||
public UnityEvent<bool> onSetActive = new();
|
||||
|
Reference in New Issue
Block a user