using System; using System.Collections.Generic; using System.Linq; using System.Threading; using Cysharp.Threading.Tasks; namespace AssetBundleHub { public interface ILinkedDecorator { IDownloadAsyncDecorator GetNextDecorator(); } // 個別にダウンロードする用のインタフェース public interface IDownloadRequestContext : ILinkedDecorator { public string URL { get; } public string SavePath { get; } public TimeSpan Timeout { get; } IProgress Progress { get; } } public class DownloadRequestContext : IDownloadRequestContext { int decoratorIndex; readonly IDownloadAsyncDecorator[] decorators; public string URL { get; } public string SavePath { get; } public TimeSpan Timeout { get; } public IProgress Progress { get; } public IDownloadAsyncDecorator GetNextDecorator() => decorators[++decoratorIndex]; public DownloadRequestContext(string url, string savePath, TimeSpan timeout, IProgress progress, IDownloadAsyncDecorator[] decorators) { this.decoratorIndex = -1; this.decorators = decorators; this.URL = url; this.SavePath = savePath; this.Progress = progress; this.Timeout = timeout; } public static DownloadRequestContext Create(string url, string savePath, TimeSpan timeout, IProgress progress = null, params IDownloadAsyncDecorator[] decorators) { return new DownloadRequestContext( url, savePath, timeout, progress, decorators.Length != 0 ? decorators : DefaultDecorators() ); } static IDownloadAsyncDecorator[] DefaultDecorators() { return ServiceLocator.Instance.Resolve().Create(); } } public interface IDownloadResponseContext { } // ダウンロードの結果でほしいものがあればここに入れる。特に思いつくものはないが、後で追加するの大変なのでいれておく。 public class DownloadResponseContext : IDownloadResponseContext { } public interface IDownloadAsyncDecorator { UniTask DownloadAsync(TRequestContext context, CancellationToken cancellationToken, Func> next); } }