public virtual void DownloadBeatmap() { if (Plugin.Instance.CurrentContinuousDownloadCount >= Plugin.Instance.MaxContinuousDownloadCount) { return; } Plugin.Instance.CurrentContinuousDownloadCount++; if (IsDownloadingBeatmap || Plugin.Instance.IsDownloadingBeatmap) { return; } IsDownloadingBeatmap = true; Plugin.Instance.IsDownloadingBeatmap = true; Logger.IPALogger.Info($"DownloadBeatmap() : {Source.MapKey} {Source.Title}"); var context = new DownloadContext($"{BeatserverDownloadUrl}{Source.MapKey}") { OnProgress = this.OnProgressDownloadingBeatmap, OnSuccess = this.OnSuccessDownloadBeatmap, OnError = this.OnErrorDownloadBeatmap, OnCancelling = this.OnCancellingDownloadBeatmap, }; WebRequestClient.Instance.EnqueueRequest(context); }
public async Task <Texture2D> GetCoverImageTexture2DAsync(CancellationToken cancellationToken) { // Logger.Debug($"GetCoverImageTextre2DAsync() : {Source.Title}"); try { var cachePath = Path.Combine(CoverFolder, $"{Source.Hash}.jpg"); // キャッシュ利用 if (File.Exists(cachePath)) { return(await Utils.GetTextureFromFileAsync(cachePath, cancellationToken)); } if (!IsDownloadingCover) { IsDownloadingCover = true; var context = new DownloadContext($"{CoverUrlBase}{Source.Hash}.webp") { OnSuccess = (status, data) => { // WebPはUnityで使えないので変換する var decoder = new SimpleDecoder(); var bitmap = decoder.DecodeFromBytes(data, data.Length); // キャッシュ作成 bitmap.Save(cachePath, ImageFormat.Jpeg); /* * // Texture2Dを作成 * using (var stream = new MemoryStream()) * { * bitmap.Save(stream, bitmap.RawFormat); * var texture = new Texture2D(2, 2); * texture.LoadImage(stream.ToArray()); * } */ }, OnError = (_, __) => IsDownloadingCover = false, OnCancelling = () => IsDownloadingCover = false, }; WebRequestClient.Instance.EnqueueRequest(context); } return(await Utils.GetTextureFromResourceAsync(DefaultCoverResourceName, cancellationToken)); } catch (Exception ex) { Logger.Debug("in GetCoverImageTexture2DAsync"); Logger.Debug(ex); return(null); } }
public void GetDataAsync() { Logger.Debug($"GetDataFromWeb() : {CreateGetURL()}"); if (!IsInitialLoaded) { IsInitialLoading = true; } var context = new DownloadContext(CreateGetURL()) { OnSuccess = OnSuccess, OnError = OnError, }; WebRequestClient.Instance.EnqueueRequest(context); }