This commit is contained in:
CortexCore
2023-10-24 23:38:22 +08:00
parent 2c4710bc5d
commit bd40165ade
152 changed files with 3681 additions and 1531 deletions

View File

@@ -1,13 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using Cysharp.Threading.Tasks;
// ReSharper disable MethodHasAsyncOverload
namespace BITKit
{
public interface IEntryGroup { }
public interface IEntryGroup
{
}
public interface IEntryElement
{
bool IsEntered { get; set; }
void Entry();
UniTask EntryAsync();
void Exit();
UniTask ExitAsync();
}
[System.Serializable]
@@ -15,7 +24,11 @@ namespace BITKit
{
public int index = -1;
public List<T> list = new();
int m_index;
private int m_index = -1;
private bool completed=true;
public event Action<T> OnEntry;
public event Action<T> OnExit;
public void Entry(T t)
{
if (t is not null)
@@ -60,24 +73,53 @@ namespace BITKit
value = default;
return false;
}
private void EnsureConfiguration()
private async void EnsureConfiguration()
{
if (MathE.Equals(this.index, m_index))
try
{
if(completed is false) return;
completed = false;
if (index == m_index)
{
}
else
{
var currentIndex = m_index;
m_index = index;
if (currentIndex is not -1 && list.TryGetElementAt(currentIndex, out var element))
{
element.Exit();
try
{
await element.ExitAsync();
}
catch (OperationCanceledException)
{
}
element.IsEntered = false;
OnExit?.Invoke(element);
}
if (index is not -1 && list.TryGetElementAt(index, out element))
{
element.IsEntered = true;
element.Entry();
try
{
await element.EntryAsync();
}
catch (OperationCanceledException){}
OnEntry?.Invoke(element);
}
}
completed = true;
}
else
catch (Exception e)
{
if (m_index is not -1)
{
list[m_index].Exit();
}
if (index is not -1)
{
list[index].Entry();
}
BIT4Log.LogException(e);
}
m_index = index;
}
}
}