| | 1 | | using System; |
| | 2 | | using GLTFast.Loading; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.Networking; |
| | 5 | |
|
| | 6 | | namespace DCL.GLTFast.Wrappers |
| | 7 | | { |
| | 8 | | internal class GltfTextureDownloaderWrapper : ITextureDownload |
| | 9 | | { |
| | 10 | | private readonly IWebRequestAsyncOperation asyncOp; |
| | 11 | |
|
| 0 | 12 | | public GltfTextureDownloaderWrapper(IWebRequestAsyncOperation asyncOp) |
| | 13 | | { |
| 0 | 14 | | this.asyncOp = asyncOp; |
| 0 | 15 | | } |
| | 16 | |
|
| 0 | 17 | | public bool Success => asyncOp.isSucceeded; |
| 0 | 18 | | public string Error => asyncOp.webRequest.error; |
| 0 | 19 | | public byte[] Data => asyncOp.webRequest.downloadHandler.data; |
| 0 | 20 | | public string Text => asyncOp.webRequest.downloadHandler.text; |
| 0 | 21 | | public bool? IsBinary => true; |
| | 22 | |
|
| | 23 | | public bool MoveNext() => |
| 0 | 24 | | asyncOp.MoveNext(); |
| | 25 | |
|
| | 26 | | public Texture2D Texture |
| | 27 | | { |
| | 28 | | get |
| | 29 | | { |
| | 30 | | Texture2D texture2D; |
| | 31 | |
|
| 0 | 32 | | if (asyncOp.webRequest.downloadHandler is DownloadHandlerTexture downloadHandlerTexture) { texture2D = d |
| 0 | 33 | | else { return null; } |
| | 34 | |
|
| | 35 | | #if UNITY_WEBGL |
| 0 | 36 | | texture2D.Compress(false); |
| | 37 | | #endif |
| 0 | 38 | | texture2D = TextureHelpers.ClampSize(texture2D, DataStore.i.textureConfig.gltfMaxSize.Get(), true); |
| | 39 | |
|
| 0 | 40 | | return texture2D; |
| | 41 | | } |
| | 42 | | } |
| | 43 | |
|
| | 44 | | public void Dispose() |
| | 45 | | { |
| 0 | 46 | | asyncOp.Dispose(); |
| 0 | 47 | | } |
| | 48 | | } |
| | 49 | | } |