mirror of
https://github.com/Cysharp/UniTask.git
synced 2026-05-18 05:00:14 +00:00
remove legacy UniTask(occurs many compile error)
This commit is contained in:
@@ -9,31 +9,30 @@ using UnityEngine;
|
||||
|
||||
namespace UniRx.Async
|
||||
{
|
||||
// TODO:rename
|
||||
public partial struct UniTask2
|
||||
public partial struct UniTask
|
||||
{
|
||||
public static YieldAwaitable2 Yield(PlayerLoopTiming timing = PlayerLoopTiming.Update)
|
||||
public static YieldAwaitable Yield(PlayerLoopTiming timing = PlayerLoopTiming.Update)
|
||||
{
|
||||
// optimized for single continuation
|
||||
return new YieldAwaitable2(timing);
|
||||
return new YieldAwaitable(timing);
|
||||
}
|
||||
|
||||
public static UniTask2 Yield(PlayerLoopTiming timing, CancellationToken cancellationToken)
|
||||
public static UniTask Yield(PlayerLoopTiming timing, CancellationToken cancellationToken)
|
||||
{
|
||||
return new UniTask2(YieldPromise.Create(timing, cancellationToken, out var token), token);
|
||||
return new UniTask(YieldPromise.Create(timing, cancellationToken, out var token), token);
|
||||
}
|
||||
|
||||
public static UniTask2 DelayFrame(int delayFrameCount, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public static UniTask DelayFrame(int delayFrameCount, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
if (delayFrameCount < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("Delay does not allow minus delayFrameCount. delayFrameCount:" + delayFrameCount);
|
||||
}
|
||||
|
||||
return new UniTask2(DelayFramePromise.Create(delayFrameCount, delayTiming, cancellationToken, out var token), token);
|
||||
return new UniTask(DelayFramePromise.Create(delayFrameCount, delayTiming, cancellationToken, out var token), token);
|
||||
}
|
||||
|
||||
public static UniTask2 Delay(int millisecondsDelay, bool ignoreTimeScale = false, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public static UniTask Delay(int millisecondsDelay, bool ignoreTimeScale = false, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
var delayTimeSpan = TimeSpan.FromMilliseconds(millisecondsDelay);
|
||||
if (delayTimeSpan < TimeSpan.Zero)
|
||||
@@ -42,11 +41,11 @@ namespace UniRx.Async
|
||||
}
|
||||
|
||||
return (ignoreTimeScale)
|
||||
? new UniTask2(DelayIgnoreTimeScalePromise.Create(delayTimeSpan, delayTiming, cancellationToken, out var token), token)
|
||||
: new UniTask2(DelayPromise.Create(delayTimeSpan, delayTiming, cancellationToken, out token), token);
|
||||
? new UniTask(DelayIgnoreTimeScalePromise.Create(delayTimeSpan, delayTiming, cancellationToken, out var token), token)
|
||||
: new UniTask(DelayPromise.Create(delayTimeSpan, delayTiming, cancellationToken, out token), token);
|
||||
}
|
||||
|
||||
public static UniTask2 Delay(TimeSpan delayTimeSpan, bool ignoreTimeScale = false, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public static UniTask Delay(TimeSpan delayTimeSpan, bool ignoreTimeScale = false, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
if (delayTimeSpan < TimeSpan.Zero)
|
||||
{
|
||||
@@ -54,8 +53,8 @@ namespace UniRx.Async
|
||||
}
|
||||
|
||||
return (ignoreTimeScale)
|
||||
? new UniTask2(DelayIgnoreTimeScalePromise.Create(delayTimeSpan, delayTiming, cancellationToken, out var token), token)
|
||||
: new UniTask2(DelayPromise.Create(delayTimeSpan, delayTiming, cancellationToken, out token), token);
|
||||
? new UniTask(DelayIgnoreTimeScalePromise.Create(delayTimeSpan, delayTiming, cancellationToken, out var token), token)
|
||||
: new UniTask(DelayPromise.Create(delayTimeSpan, delayTiming, cancellationToken, out token), token);
|
||||
}
|
||||
|
||||
class YieldPromise : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem
|
||||
@@ -405,244 +404,6 @@ namespace UniRx.Async
|
||||
}
|
||||
}
|
||||
|
||||
// TODO:rename
|
||||
public struct YieldAwaitable2
|
||||
{
|
||||
readonly PlayerLoopTiming timing;
|
||||
|
||||
public YieldAwaitable2(PlayerLoopTiming timing)
|
||||
{
|
||||
this.timing = timing;
|
||||
}
|
||||
|
||||
public Awaiter GetAwaiter()
|
||||
{
|
||||
return new Awaiter(timing);
|
||||
}
|
||||
|
||||
public UniTask2 ToUniTask()
|
||||
{
|
||||
return UniTask2.Yield(timing, CancellationToken.None);
|
||||
}
|
||||
|
||||
public struct Awaiter : ICriticalNotifyCompletion
|
||||
{
|
||||
readonly PlayerLoopTiming timing;
|
||||
|
||||
public Awaiter(PlayerLoopTiming timing)
|
||||
{
|
||||
this.timing = timing;
|
||||
}
|
||||
|
||||
public bool IsCompleted => false;
|
||||
|
||||
public void GetResult() { }
|
||||
|
||||
public void OnCompleted(Action continuation)
|
||||
{
|
||||
PlayerLoopHelper.AddContinuation(timing, continuation);
|
||||
}
|
||||
|
||||
public void UnsafeOnCompleted(Action continuation)
|
||||
{
|
||||
PlayerLoopHelper.AddContinuation(timing, continuation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO:remove
|
||||
public partial struct UniTask
|
||||
{
|
||||
public static YieldAwaitable Yield(PlayerLoopTiming timing = PlayerLoopTiming.Update)
|
||||
{
|
||||
// optimized for single continuation
|
||||
return new YieldAwaitable(timing);
|
||||
}
|
||||
|
||||
public static UniTask Yield(PlayerLoopTiming timing, CancellationToken cancellationToken)
|
||||
{
|
||||
return new UniTask(new YieldPromise(timing, cancellationToken));
|
||||
}
|
||||
|
||||
public static UniTask<int> DelayFrame(int delayFrameCount, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
if (delayFrameCount < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("Delay does not allow minus delayFrameCount. delayFrameCount:" + delayFrameCount);
|
||||
}
|
||||
|
||||
var source = new DelayFramePromise(delayFrameCount, delayTiming, cancellationToken);
|
||||
return source.Task;
|
||||
}
|
||||
|
||||
public static UniTask Delay(int millisecondsDelay, bool ignoreTimeScale = false, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
var delayTimeSpan = TimeSpan.FromMilliseconds(millisecondsDelay);
|
||||
if (delayTimeSpan < TimeSpan.Zero)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("Delay does not allow minus delayFrameCount. delayTimeSpan:" + delayTimeSpan);
|
||||
}
|
||||
|
||||
return (ignoreTimeScale)
|
||||
? new DelayIgnoreTimeScalePromise(delayTimeSpan, delayTiming, cancellationToken).Task
|
||||
: new DelayPromise(delayTimeSpan, delayTiming, cancellationToken).Task;
|
||||
}
|
||||
|
||||
public static UniTask Delay(TimeSpan delayTimeSpan, bool ignoreTimeScale = false, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
if (delayTimeSpan < TimeSpan.Zero)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("Delay does not allow minus delayFrameCount. delayTimeSpan:" + delayTimeSpan);
|
||||
}
|
||||
|
||||
return (ignoreTimeScale)
|
||||
? new DelayIgnoreTimeScalePromise(delayTimeSpan, delayTiming, cancellationToken).Task
|
||||
: new DelayPromise(delayTimeSpan, delayTiming, cancellationToken).Task;
|
||||
}
|
||||
|
||||
class YieldPromise : PlayerLoopReusablePromiseBase
|
||||
{
|
||||
public YieldPromise(PlayerLoopTiming timing, CancellationToken cancellationToken)
|
||||
: base(timing, cancellationToken, 2)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnRunningStart()
|
||||
{
|
||||
}
|
||||
|
||||
public override bool MoveNext()
|
||||
{
|
||||
Complete();
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
TrySetCanceled();
|
||||
}
|
||||
else
|
||||
{
|
||||
TrySetResult();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class DelayFramePromise : PlayerLoopReusablePromiseBase<int>
|
||||
{
|
||||
readonly int delayFrameCount;
|
||||
int currentFrameCount;
|
||||
|
||||
public DelayFramePromise(int delayFrameCount, PlayerLoopTiming timing, CancellationToken cancellationToken)
|
||||
: base(timing, cancellationToken, 2)
|
||||
{
|
||||
this.delayFrameCount = delayFrameCount;
|
||||
this.currentFrameCount = 0;
|
||||
}
|
||||
|
||||
protected override void OnRunningStart()
|
||||
{
|
||||
currentFrameCount = 0;
|
||||
}
|
||||
|
||||
public override bool MoveNext()
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
Complete();
|
||||
TrySetCanceled();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (currentFrameCount == delayFrameCount)
|
||||
{
|
||||
Complete();
|
||||
TrySetResult(currentFrameCount);
|
||||
return false;
|
||||
}
|
||||
|
||||
currentFrameCount++;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class DelayPromise : PlayerLoopReusablePromiseBase
|
||||
{
|
||||
readonly float delayFrameTimeSpan;
|
||||
float elapsed;
|
||||
|
||||
public DelayPromise(TimeSpan delayFrameTimeSpan, PlayerLoopTiming timing, CancellationToken cancellationToken)
|
||||
: base(timing, cancellationToken, 2)
|
||||
{
|
||||
this.delayFrameTimeSpan = (float)delayFrameTimeSpan.TotalSeconds;
|
||||
}
|
||||
|
||||
protected override void OnRunningStart()
|
||||
{
|
||||
this.elapsed = 0.0f;
|
||||
}
|
||||
|
||||
public override bool MoveNext()
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
Complete();
|
||||
TrySetCanceled();
|
||||
return false;
|
||||
}
|
||||
|
||||
elapsed += Time.deltaTime;
|
||||
if (elapsed >= delayFrameTimeSpan)
|
||||
{
|
||||
Complete();
|
||||
TrySetResult();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class DelayIgnoreTimeScalePromise : PlayerLoopReusablePromiseBase
|
||||
{
|
||||
readonly float delayFrameTimeSpan;
|
||||
float elapsed;
|
||||
|
||||
public DelayIgnoreTimeScalePromise(TimeSpan delayFrameTimeSpan, PlayerLoopTiming timing, CancellationToken cancellationToken)
|
||||
: base(timing, cancellationToken, 2)
|
||||
{
|
||||
this.delayFrameTimeSpan = (float)delayFrameTimeSpan.TotalSeconds;
|
||||
}
|
||||
|
||||
protected override void OnRunningStart()
|
||||
{
|
||||
this.elapsed = 0.0f;
|
||||
}
|
||||
|
||||
public override bool MoveNext()
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
Complete();
|
||||
TrySetCanceled();
|
||||
return false;
|
||||
}
|
||||
|
||||
elapsed += Time.unscaledDeltaTime;
|
||||
|
||||
if (elapsed >= delayFrameTimeSpan)
|
||||
{
|
||||
Complete();
|
||||
TrySetResult();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO:remove
|
||||
public struct YieldAwaitable
|
||||
{
|
||||
readonly PlayerLoopTiming timing;
|
||||
|
||||
Reference in New Issue
Block a user