mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
TEngine全面更新,升级YooAsset2.1.1、UniTask、UIWindow、I2Localization
TEngine全面更新,升级YooAsset2.1.1、UniTask、UIWindow、I2Localization
This commit is contained in:
@@ -4,38 +4,50 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
{
|
||||
public static partial class UniTaskAsyncEnumerable
|
||||
{
|
||||
public static IUniTaskAsyncEnumerable<AsyncUnit> EveryUpdate(PlayerLoopTiming updateTiming = PlayerLoopTiming.Update)
|
||||
public static IUniTaskAsyncEnumerable<AsyncUnit> EveryUpdate(PlayerLoopTiming updateTiming = PlayerLoopTiming.Update, bool cancelImmediately = false)
|
||||
{
|
||||
return new EveryUpdate(updateTiming);
|
||||
return new EveryUpdate(updateTiming, cancelImmediately);
|
||||
}
|
||||
}
|
||||
|
||||
internal class EveryUpdate : IUniTaskAsyncEnumerable<AsyncUnit>
|
||||
{
|
||||
readonly PlayerLoopTiming updateTiming;
|
||||
readonly bool cancelImmediately;
|
||||
|
||||
public EveryUpdate(PlayerLoopTiming updateTiming)
|
||||
public EveryUpdate(PlayerLoopTiming updateTiming, bool cancelImmediately)
|
||||
{
|
||||
this.updateTiming = updateTiming;
|
||||
this.cancelImmediately = cancelImmediately;
|
||||
}
|
||||
|
||||
public IUniTaskAsyncEnumerator<AsyncUnit> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new _EveryUpdate(updateTiming, cancellationToken);
|
||||
return new _EveryUpdate(updateTiming, cancellationToken, cancelImmediately);
|
||||
}
|
||||
|
||||
class _EveryUpdate : MoveNextSource, IUniTaskAsyncEnumerator<AsyncUnit>, IPlayerLoopItem
|
||||
{
|
||||
readonly PlayerLoopTiming updateTiming;
|
||||
CancellationToken cancellationToken;
|
||||
readonly CancellationToken cancellationToken;
|
||||
readonly CancellationTokenRegistration cancellationTokenRegistration;
|
||||
|
||||
bool disposed;
|
||||
|
||||
public _EveryUpdate(PlayerLoopTiming updateTiming, CancellationToken cancellationToken)
|
||||
public _EveryUpdate(PlayerLoopTiming updateTiming, CancellationToken cancellationToken, bool cancelImmediately)
|
||||
{
|
||||
this.updateTiming = updateTiming;
|
||||
this.cancellationToken = cancellationToken;
|
||||
|
||||
if (cancelImmediately && cancellationToken.CanBeCanceled)
|
||||
{
|
||||
cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state =>
|
||||
{
|
||||
var source = (_EveryUpdate)state;
|
||||
source.completionSource.TrySetCanceled(source.cancellationToken);
|
||||
}, this);
|
||||
}
|
||||
|
||||
TaskTracker.TrackActiveTask(this, 2);
|
||||
PlayerLoopHelper.AddAction(updateTiming, this);
|
||||
}
|
||||
@@ -44,10 +56,14 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public UniTask<bool> MoveNextAsync()
|
||||
{
|
||||
// return false instead of throw
|
||||
if (disposed || cancellationToken.IsCancellationRequested) return CompletedTasks.False;
|
||||
|
||||
if (disposed) return CompletedTasks.False;
|
||||
|
||||
completionSource.Reset();
|
||||
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
completionSource.TrySetCanceled(cancellationToken);
|
||||
}
|
||||
return new UniTask<bool>(this, completionSource.Version);
|
||||
}
|
||||
|
||||
@@ -55,6 +71,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
{
|
||||
if (!disposed)
|
||||
{
|
||||
cancellationTokenRegistration.Dispose();
|
||||
disposed = true;
|
||||
TaskTracker.RemoveTracking(this);
|
||||
}
|
||||
@@ -63,7 +80,13 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (disposed || cancellationToken.IsCancellationRequested)
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
completionSource.TrySetCanceled(cancellationToken);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (disposed)
|
||||
{
|
||||
completionSource.TrySetResult(false);
|
||||
return false;
|
||||
|
Reference in New Issue
Block a user