コガネブログ

平日更新を目標に Unity や C#、Visual Studio、ReSharper などのゲーム開発アレコレを書いていきます

【Unity】UniTask で指定秒待機する関数

ソースコード

using System;
using System.Threading;

namespace Cysharp.Threading.Tasks
{
    public partial struct UniTask
    {
        public static UniTask DelaySeconds
        (
            double            seconds,
            bool              ignoreTimeScale   = false,
            PlayerLoopTiming  delayTiming       = PlayerLoopTiming.Update,
            CancellationToken cancellationToken = default( CancellationToken )
        )
        {
            return Delay
            (
                delayTimeSpan: TimeSpan.FromSeconds( seconds ),
                ignoreTimeScale: ignoreTimeScale,
                delayTiming: delayTiming,
                cancellationToken: cancellationToken
            );
        }

        public static UniTask DelaySeconds
        (
            double            seconds,
            DelayType         delayType,
            PlayerLoopTiming  delayTiming       = PlayerLoopTiming.Update,
            CancellationToken cancellationToken = default( CancellationToken )
        )
        {
            return Delay
            (
                delayTimeSpan: TimeSpan.FromSeconds( seconds ),
                delayType: delayType,
                delayTiming: delayTiming,
                cancellationToken: cancellationToken
            );
        }
    }
}