| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using UnityEngine; |
| | 5 | | using UnityEngine.Networking; |
| | 6 | | using DCL; |
| | 7 | |
|
| | 8 | | //In the future the AssetManager will do this |
| | 9 | | public static class ThumbnailsManager |
| | 10 | | { |
| | 11 | | #if UNITY_EDITOR |
| 1 | 12 | | public static bool bypassRequests = false; |
| | 13 | | #endif |
| 1 | 14 | | static Dictionary<string, Sprite> loadedSprites = new Dictionary<string, Sprite>(); |
| | 15 | |
|
| | 16 | | public static AssetPromise_Texture PreloadThumbnail(string url) |
| | 17 | | { |
| | 18 | | #if UNITY_EDITOR |
| 4 | 19 | | if (bypassRequests) |
| 4 | 20 | | return null; |
| | 21 | | #endif |
| 0 | 22 | | if (string.IsNullOrEmpty(url)) |
| 0 | 23 | | return null; |
| | 24 | |
|
| 0 | 25 | | var promise = new AssetPromise_Texture(url); |
| 0 | 26 | | AssetPromiseKeeper_Texture.i.Keep(promise); |
| | 27 | |
|
| 0 | 28 | | return promise; |
| | 29 | | } |
| | 30 | |
|
| | 31 | | public static void ForgetThumbnail(AssetPromise_Texture promise) |
| | 32 | | { |
| 396 | 33 | | if (promise == null) |
| 206 | 34 | | return; |
| | 35 | |
|
| | 36 | | //Debug.Log("Forget thumbnail " + promise.asset.id); |
| 190 | 37 | | AssetPromiseKeeper_Texture.i.Forget(promise); |
| 190 | 38 | | } |
| | 39 | |
|
| | 40 | | public static AssetPromise_Texture GetThumbnail(string url, Action<Asset_Texture> OnComplete) |
| | 41 | | { |
| | 42 | | #if UNITY_EDITOR |
| 198 | 43 | | if (bypassRequests) |
| 8 | 44 | | return null; |
| | 45 | | #endif |
| 190 | 46 | | if (string.IsNullOrEmpty(url)) |
| 0 | 47 | | return null; |
| | 48 | |
|
| 190 | 49 | | var promise = new AssetPromise_Texture(url); |
| | 50 | |
|
| 190 | 51 | | promise.OnSuccessEvent += OnComplete; |
| 190 | 52 | | promise.OnFailEvent += (x, error) => { Debug.Log($"Error downloading: {url}, Exception: {error}"); }; |
| | 53 | |
|
| 190 | 54 | | AssetPromiseKeeper_Texture.i.Keep(promise); |
| 190 | 55 | | return promise; |
| | 56 | | } |
| | 57 | |
|
| | 58 | | public static Sprite CreateSpriteFromTexture(Texture2D texture) |
| | 59 | | { |
| 0 | 60 | | var sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero); |
| 0 | 61 | | return sprite; |
| | 62 | | } |
| | 63 | | } |