This commit is contained in:
CortexCore
2023-10-06 23:43:19 +08:00
parent ebf9c1f526
commit 2c4710bc5d
186 changed files with 111802 additions and 764 deletions

View 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);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1348cd99518aa184dadd0fd312462029
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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();