using System; using System.Threading; using AssetBundleHub; using Cysharp.Threading.Tasks; public class MockErrorDownload : IDownloadAsyncDecorator { int count = 0; int throwCount; public Exception exception; /// /// エラー出す用クラス /// /// 何番目のリクエストでエラーを出すか public MockErrorDownload(int throwCount = 1) { this.throwCount = throwCount; } public async UniTask DownloadAsync(IDownloadRequestContext context, CancellationToken cancellationToken, Func> next) { cancellationToken.ThrowIfCancellationRequested(); count++; if (count == throwCount) { if (exception == null) { throw new Exception("test error: throw count"); } else { throw exception; } } await UniTask.DelayFrame(10, cancellationToken: cancellationToken); return new DownloadResponseContext(); } }