| | 1 | | using System; |
| | 2 | | using System.Threading; |
| | 3 | | using Cysharp.Threading.Tasks; |
| | 4 | |
|
| | 5 | | namespace DCL |
| | 6 | | { |
| | 7 | | public class JSGifProcessor : IGifProcessor |
| | 8 | | { |
| | 9 | | private readonly string url; |
| | 10 | | private Action<GifFrameData[]> successCallback; |
| | 11 | | private Action<Exception> failCallback; |
| | 12 | |
|
| 0 | 13 | | public JSGifProcessor(string url) { this.url = url; } |
| | 14 | |
|
| | 15 | | public async UniTask Load(Action<GifFrameData[]> OnSuccess, Action<Exception> OnFail, CancellationToken cancella |
| | 16 | | { |
| | 17 | | try |
| | 18 | | { |
| 0 | 19 | | await Internal_Load(OnSuccess, OnFail, cancellationToken); |
| 0 | 20 | | } |
| 0 | 21 | | catch (Exception e) |
| | 22 | | { |
| 0 | 23 | | if (!(e is OperationCanceledException)) |
| | 24 | | { |
| 0 | 25 | | OnFail(e); |
| | 26 | | } |
| 0 | 27 | | } |
| 0 | 28 | | } |
| | 29 | |
|
| | 30 | | private async UniTask Internal_Load(Action<GifFrameData[]> OnSuccess, Action<Exception> OnFail, CancellationToke |
| | 31 | | { |
| 0 | 32 | | successCallback = OnSuccess; |
| 0 | 33 | | failCallback = OnFail; |
| | 34 | |
|
| 0 | 35 | | token.ThrowIfCancellationRequested(); |
| 0 | 36 | | await GIFProcessingBridge.i.RequestGIFProcessor(url, OnComplete, this.OnFail).ToUniTask(cancellationToken: t |
| 0 | 37 | | } |
| | 38 | |
|
| | 39 | | private void OnComplete(GifFrameData[] newTextures) |
| | 40 | | { |
| 0 | 41 | | if (newTextures == null || newTextures.Length == 0) |
| | 42 | | { |
| 0 | 43 | | OnFail(); |
| 0 | 44 | | return; |
| | 45 | | } |
| | 46 | |
|
| 0 | 47 | | successCallback?.Invoke(newTextures); |
| 0 | 48 | | } |
| | 49 | |
|
| 0 | 50 | | private void OnFail() { failCallback?.Invoke( new Exception("JS Gif fetch failed")); } |
| | 51 | |
|
| 0 | 52 | | public void DisposeGif() { GIFProcessingBridge.i.DeleteGIF(url); } |
| | 53 | | } |
| | 54 | | } |