IEnumerator FetchNFTImage() { string thumbnailImageURL = null; string previewImageURL = null; string originalImageURL = null; yield return(NFTHelper.FetchNFTInfo(darURLRegistry, darURLAsset, (nftInfo) => { thumbnailImageURL = nftInfo.thumbnailUrl; previewImageURL = nftInfo.previewImageUrl; originalImageURL = nftInfo.originalImageUrl; }, (error) => { Debug.LogError($"Didn't find any asset image for '{darURLRegistry}/{darURLAsset}' for the NFTShape.\n{error}"); })); // We fetch and show the thumbnail image first if (!string.IsNullOrEmpty(thumbnailImageURL)) { yield return(Utils.FetchWrappedTextureAsset(thumbnailImageURL, (downloadedAsset) => { SetFrameImage(downloadedAsset); })); } // We fetch the final image bool foundDCLImage = false; if (!string.IsNullOrEmpty(previewImageURL)) { yield return(Utils.FetchWrappedTextureAsset(previewImageURL, (downloadedAsset) => { // Dispose thumbnail if (nftAsset != null) { nftAsset.Dispose(); } foundDCLImage = true; SetFrameImage(downloadedAsset, resizeFrameMesh: true); })); } // We fall back to a common "preview" image if no "dcl image" was found if (!foundDCLImage && !string.IsNullOrEmpty(originalImageURL)) { yield return(Utils.FetchWrappedTextureAsset(originalImageURL, (downloadedAsset) => { // Dispose thumbnail if (nftAsset != null) { nftAsset.Dispose(); } SetFrameImage(downloadedAsset, resizeFrameMesh: true); })); } OnLoadingAssetSuccess?.Invoke(); }
IEnumerator FetchNFTImage() { if (spinner != null) { spinner.SetActive(true); } string thumbnailImageURL = null; string previewImageURL = null; string originalImageURL = null; yield return(NFTHelper.FetchNFTInfo(darURLRegistry, darURLAsset, (nftInfo) => { thumbnailImageURL = nftInfo.thumbnailUrl; previewImageURL = nftInfo.previewImageUrl; originalImageURL = nftInfo.originalImageUrl; }, (error) => { Debug.LogError($"Didn't find any asset image for '{darURLRegistry}/{darURLAsset}' for the NFTShape.\n{error}"); OnLoadingAssetFail?.Invoke(); })); yield return(new DCL.WaitUntil(() => (CommonScriptableObjects.playerUnityPosition - transform.position).sqrMagnitude < 900f)); // We download the "preview" 256px image bool foundDCLImage = false; if (!string.IsNullOrEmpty(previewImageURL)) { lastURLUsed = previewImageURL; yield return(WrappedTextureUtils.Fetch(previewImageURL, (downloadedTex, texturePromise) => { foundDCLImage = true; this.texturePromise = texturePromise; SetFrameImage(downloadedTex, resizeFrameMesh: true); }, Asset_Gif.MaxSize.DONT_RESIZE)); } //We fall back to the nft original image which can have a really big size if (!foundDCLImage && !string.IsNullOrEmpty(originalImageURL)) { lastURLUsed = originalImageURL; yield return(WrappedTextureUtils.Fetch(originalImageURL, (downloadedTex, texturePromise) => { foundDCLImage = true; this.texturePromise = texturePromise; SetFrameImage(downloadedTex, resizeFrameMesh: true); }, Asset_Gif.MaxSize._256)); } FinishLoading(foundDCLImage); }
IEnumerator FetchNFTImage() { spinner?.SetActive(true); string thumbnailImageURL = null; string previewImageURL = null; string originalImageURL = null; yield return(NFTHelper.FetchNFTInfo(darURLRegistry, darURLAsset, (nftInfo) => { thumbnailImageURL = nftInfo.thumbnailUrl; previewImageURL = nftInfo.previewImageUrl; originalImageURL = nftInfo.originalImageUrl; }, (error) => { Debug.LogError($"Didn't find any asset image for '{darURLRegistry}/{darURLAsset}' for the NFTShape.\n{error}"); OnLoadingAssetFail?.Invoke(); })); // We the "preview" 256px image bool foundDCLImage = false; if (!string.IsNullOrEmpty(previewImageURL)) { yield return(Utils.FetchWrappedTextureAsset(previewImageURL, (downloadedAsset) => { foundDCLImage = true; SetFrameImage(downloadedAsset, resizeFrameMesh: true); })); } // We fall back to the nft original image which can have a really big size if (!foundDCLImage && !string.IsNullOrEmpty(originalImageURL)) { yield return(Utils.FetchWrappedTextureAsset(originalImageURL, (downloadedAsset) => { foundDCLImage = true; SetFrameImage(downloadedAsset, resizeFrameMesh: true); }, DCL.WrappedTextureMaxSize._256)); } if (foundDCLImage) { spinner?.SetActive(false); OnLoadingAssetSuccess?.Invoke(); } else { OnLoadingAssetFail?.Invoke(); } }
internal void ShowNFT(string assetContractAddress, string tokenId, string comment) { content.SetActive(true); Utils.UnlockCursor(); if (fetchNFTRoutine != null) { StopCoroutine(fetchNFTRoutine); } if (fetchNFTImageRoutine != null) { StopCoroutine(fetchNFTImageRoutine); } SetLoading(); fetchNFTRoutine = StartCoroutine(NFTHelper.FetchNFTInfo(assetContractAddress, tokenId, (nftInfo) => SetNFTInfo(nftInfo, comment), (error) => OnError(error) )); }
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); }