private async void LoadCoverImage() { var defaultTexture = new Texture2D(1, 1); defaultTexture.SetPixel(0, 0, Color.clear); if (coverImageTexture == null && level != null) { //The dimensions of the list item are 60x10, so we want to get the top 1/6th of the cover image var uncroppedTexture = (await level.GetCoverImageAsync(cancellationToken.Token)).texture; if (uncroppedTexture != null) { //GetPixels throws a texture unreadable error when trying to read OST textures //We'll just have to squash it try { var rippedColors = uncroppedTexture.GetPixels(0, 0, uncroppedTexture.width, uncroppedTexture.height / 6); coverImageTexture = new Texture2D(uncroppedTexture.width, uncroppedTexture.height / 6); coverImageTexture.SetPixels(rippedColors); coverImageTexture.Apply(); } catch { coverImageTexture = uncroppedTexture; } } } coverImage.texture = coverImageTexture ?? defaultTexture; }
public PreviewBeatmapStub(string levelHash, IPreviewBeatmapLevel preview) { this.levelID = preview.levelID; this.levelHash = levelHash; this.isDownloaded = true; this.songName = preview.songName; this.songSubName = preview.songSubName; this.songAuthorName = preview.songAuthorName; this.levelAuthorName = preview.levelAuthorName; this.beatsPerMinute = preview.beatsPerMinute; this.songDuration = preview.songDuration; _coverTask = preview.GetCoverImageAsync(CancellationToken.None); _rawCoverTask = GetCoverImageAsync(CancellationToken.None).ContinueWith <byte[]>(task => Utilities.Sprites.GetRaw(task.Result)); _audioTask = preview.GetPreviewAudioClipAsync(CancellationToken.None); }
public async Task <Sprite> GetCoverImageAsync(CancellationToken cancellationToken) { if (_localPreview != null) { return(await _localPreview.GetCoverImageAsync(cancellationToken)); } Beatmap?bm = await FetchBeatmap(); if (bm != null) { var img = await bm.FetchCoverImage(cancellationToken); return(Utilities.Utils.GetSprite(img)); } else { return(Sprite.Create(Texture2D.blackTexture, new Rect(0, 0, 2, 2), new Vector2(0, 0), 100.0f)); } }
public async Task <Sprite> GetCoverImageAsync(CancellationToken cancellationToken) { if (_localPreview != null) { return(await _localPreview.GetCoverImageAsync(cancellationToken)); } Beatmap?bm = await FetchBeatmap(); Sprite?sprite = null; if (bm != null && await bm.FetchCoverImage(cancellationToken) is byte[] img) { sprite = Utilities.Utils.GetSprite(img); } if (sprite == null) { sprite = Sprite.Create(Texture2D.blackTexture, new Rect(0, 0, 2, 2), new Vector2(0, 0), 100.0f); } return(sprite); }
private static async void LevelSelected(LevelCollectionViewController lcvc, IPreviewBeatmapLevel level) { Texture2D tex; try { tex = (await level.GetCoverImageAsync(System.Threading.CancellationToken.None)).texture; } catch { tex = GetFromUnreadable((level as CustomPreviewBeatmapLevel)?.defaultCoverImage.texture); } if (!(level is CustomPreviewBeatmapLevel) || tex == null || !tex.isReadable) { tex = GetFromUnreadable(tex); } var scheme = new ColorScheme("CoverSaber", "Cover Saber", true, "Cover Saber", false, Color.white, Color.white, Color.white, Color.white, true, Color.white, Color.white, Color.white); var colors = new List <ColorThief.QuantizedColor>(); await Task.Run(async() => { var data = await CoverColorManager.GetSchemeFromCoverImage(tex, level.levelID); scheme = CoverColorManager.Cache.GetOrAdd(level.levelID, data.Scheme); colors = data.Colors; }); Settings.Menu.instance.SongName = level.songName; Settings.Menu.instance.SetColors(colors, scheme, tex, level.levelID); }