| | 1 | | using System; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | namespace DCL |
| | 5 | | { |
| | 6 | | public class AssetPromise_Gif : AssetPromise<Asset_Gif> |
| | 7 | | { |
| | 8 | | private readonly string url; |
| | 9 | | private Coroutine loadingRoutine; |
| | 10 | |
|
| 0 | 11 | | public AssetPromise_Gif(string url) { this.url = url; } |
| | 12 | |
|
| 63 | 13 | | public override object GetId() { return url; } |
| | 14 | |
|
| | 15 | | protected override void OnLoad(Action OnSuccess, Action OnFail) |
| | 16 | | { |
| 10 | 17 | | var processor = new GifProcessor(url); |
| 10 | 18 | | asset.processor = processor; |
| 10 | 19 | | loadingRoutine = CoroutineStarter.Start( |
| | 20 | | processor.Load( |
| | 21 | | frames => |
| | 22 | | { |
| 4 | 23 | | asset.frames = frames; |
| | 24 | |
|
| 368 | 25 | | foreach ( var frame in asset.frames ) |
| | 26 | | { |
| 180 | 27 | | frame.texture.Compress(false); |
| 180 | 28 | | frame.texture.Apply(true, true); |
| | 29 | | } |
| | 30 | |
|
| 4 | 31 | | OnSuccess?.Invoke(); |
| 4 | 32 | | }, OnFail)); |
| 10 | 33 | | } |
| | 34 | |
|
| 12 | 35 | | protected override void OnCancelLoading() { CoroutineStarter.Stop(loadingRoutine); } |
| | 36 | |
|
| | 37 | | protected override bool AddToLibrary() |
| | 38 | | { |
| 4 | 39 | | if (!library.Add(asset)) |
| | 40 | | { |
| 0 | 41 | | Debug.Log("add to library fail?"); |
| 0 | 42 | | return false; |
| | 43 | | } |
| | 44 | |
|
| 4 | 45 | | asset = library.Get(asset.id); |
| 4 | 46 | | return true; |
| | 47 | | } |
| | 48 | |
|
| 13 | 49 | | protected override void OnBeforeLoadOrReuse() { } |
| | 50 | |
|
| 7 | 51 | | protected override void OnAfterLoadOrReuse() { } |
| | 52 | | } |
| | 53 | | } |