void OnDestroy() { isDestroyed = true; if (hqTextureHandler != null) { hqTextureHandler.Dispose(); hqTextureHandler = null; } if (gifPlayer != null) { gifPlayer.OnFrameTextureChanged -= UpdateTexture; gifPlayer.Dispose(); } if (assetPromise != null) { assetPromise.Forget(); assetPromise = null; } if (backgroundMaterial != null) { Object.Destroy(backgroundMaterial); } if (imageMaterial != null) { Object.Destroy(imageMaterial); } }
private IEnumerator FetchNFTImage(NFTInfo nftInfo) { spinnerNftImage.SetActive(true); bool imageFound = false; yield return(WrappedTextureUtils.Fetch(nftInfo.previewImageUrl, promise => { imagePromise = promise; imageFound = true; })); if (!imageFound) { yield return(WrappedTextureUtils.Fetch(nftInfo.originalImageUrl, promise => { imagePromise = promise; imageFound = true; })); } if (imageFound && imagePromise?.asset != null) { Texture2D texture = imagePromise.asset.texture; imageNft.texture = texture; if ((imagePromise.asset is Asset_Gif gif)) { SetupGifPlayer(gif); } else if (!backgroundColorSet) { SetSmartBackgroundColor(texture); } SetNFTImageSize(texture); imageNft.gameObject.SetActive(true); spinnerNftImage.SetActive(false); }
IEnumerator FetchNFTImage() { if (spinner != null) { spinner.SetActive(true); } NFTInfo nftInfo = new NFTInfo(); bool isError = false; yield return(NFTHelper.FetchNFTInfo(darURLRegistry, darURLAsset, (info) => { nftInfo = info; }, (error) => { Debug.LogError($"Couldn't fetch NFT: '{darURLRegistry}/{darURLAsset}' {error}"); OnLoadingAssetFail?.Invoke(); isError = true; })); if (isError) { yield break; } yield return(new DCL.WaitUntil(() => (CommonScriptableObjects.playerUnityPosition - transform.position).sqrMagnitude < (config.loadingMinDistance * config.loadingMinDistance))); // We download the "preview" 256px image bool foundDCLImage = false; if (!string.IsNullOrEmpty(nftInfo.previewImageUrl)) { yield return(WrappedTextureUtils.Fetch(nftInfo.previewImageUrl, (promise) => { foundDCLImage = true; this.assetPromise = promise; SetFrameImage(promise.asset, resizeFrameMesh: true); SetupGifPlayer(promise.asset); var hqImageHandlerConfig = new NFTShapeHQImageConfig() { controller = this, nftConfig = config, nftInfo = nftInfo, asset = NFTAssetFactory.CreateAsset(promise.asset, config, UpdateTexture, gifPlayer) }; hqTextureHandler = NFTShapeHQImageHandler.Create(hqImageHandlerConfig); })); } //We fall back to the nft original image which can have a really big size if (!foundDCLImage && !string.IsNullOrEmpty(nftInfo.originalImageUrl)) { yield return(WrappedTextureUtils.Fetch(nftInfo.originalImageUrl, (promise) => { foundDCLImage = true; this.assetPromise = promise; SetFrameImage(promise.asset, resizeFrameMesh: true); SetupGifPlayer(promise.asset); }, () => isError = true)); } if (isError) { Debug.LogError($"Couldn't fetch NFT image for: '{darURLRegistry}/{darURLAsset}' {nftInfo.originalImageUrl}"); OnLoadingAssetFail?.Invoke(); yield break; } FinishLoading(foundDCLImage); }