コード例 #1
0
        public static UniTask Delay(TimeSpan delayTimeSpan, DelayType delayType, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (delayTimeSpan < TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException("Delay does not allow minus delayTimeSpan. delayTimeSpan:" + delayTimeSpan);
            }

            switch (delayType)
            {
            case DelayType.UnscaledDeltaTime:
            {
                return(new UniTask(DelayIgnoreTimeScalePromise.Create(delayTimeSpan, delayTiming, cancellationToken, out var token), token));
            }

            case DelayType.Realtime:
            {
                return(new UniTask(DelayRealtimePromise.Create(delayTimeSpan, delayTiming, cancellationToken, out var token), token));
            }

            case DelayType.DeltaTime:
            default:
            {
                return(new UniTask(DelayPromise.Create(delayTimeSpan, delayTiming, cancellationToken, out var token), token));
            }
            }
        }
コード例 #2
0
        public static UniTask Delay(TimeSpan delayTimeSpan, DelayType delayType, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (delayTimeSpan < TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException("Delay does not allow minus delayTimeSpan. delayTimeSpan:" + delayTimeSpan);
            }

#if UNITY_EDITOR
            // force use Realtime.
            if (PlayerLoopHelper.IsMainThread && !UnityEditor.EditorApplication.isPlaying)
            {
                delayType = DelayType.Realtime;
            }
#endif

            switch (delayType)
            {
            case DelayType.UnscaledDeltaTime:
            {
                return(new UniTask(DelayIgnoreTimeScalePromise.Create(delayTimeSpan, delayTiming, cancellationToken, out var token), token));
            }

            case DelayType.Realtime:
            {
                return(new UniTask(DelayRealtimePromise.Create(delayTimeSpan, delayTiming, cancellationToken, out var token), token));
            }

            case DelayType.DeltaTime:
            default:
            {
                return(new UniTask(DelayPromise.Create(delayTimeSpan, delayTiming, cancellationToken, out var token), token));
            }
            }
        }
コード例 #3
0
        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 delayTimeSpan. delayTimeSpan:" + delayTimeSpan);
            }

            return((ignoreTimeScale)
                ? new UniTask(DelayIgnoreTimeScalePromise.Create(delayTimeSpan, delayTiming, cancellationToken, out var token), token)
                : new UniTask(DelayPromise.Create(delayTimeSpan, delayTiming, cancellationToken, out token), token));
        }
コード例 #4
0
        public static UniTask <int> Delay(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 DelayPromise(delayFrameCount, cancellationToken);

            PlayerLoopHelper.AddAction(delayTiming, source);
            return(source.Task);
        }
コード例 #5
0
        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 millisecondsDelay. millisecondsDelay:" + millisecondsDelay);
            }

            return((ignoreTimeScale)
                ? new UniTask(DelayIgnoreTimeScalePromise.Create(delayTimeSpan, delayTiming, cancellationToken, out var token), token)
                : new UniTask(DelayPromise.Create(delayTimeSpan, delayTiming, cancellationToken, out token), token));
        }
コード例 #6
0
        private static Task Delay(Dispatcher dispatcher, TimeSpan delay, CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return(Task.FromCanceled(cancellationToken));
            }
            if (delay == TimeSpan.Zero)
            {
                return(Task.CompletedTask);
            }

            var promise = new DelayPromise(dispatcher, cancellationToken, delay);

            return(promise.Task);
        }
コード例 #7
0
ファイル: UniTask.Delay.cs プロジェクト: ryo0ka/MinAR
        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);
            }

            if (ignoreTimeScale)
            {
                var source = new DelayIgnoreTimeScalePromise(delayTimeSpan, delayTiming, cancellationToken);
                return(source.Task);
            }
            else
            {
                var source = new DelayPromise(delayTimeSpan, delayTiming, cancellationToken);
                return(source.Task);
            }
        }