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);
    }
示例#2
0
    private IEnumerator FetchNFTImage(NFTInfo nftInfo)
    {
        spinnerNftImage.SetActive(true);

        ITexture nftImageAsset = null;

        yield return(WrappedTextureUtils.Fetch(nftInfo.previewImageUrl,
                                               (downloadedTex, texturePromise) =>
        {
            nftImageAsset = downloadedTex;
            this.texturePromise = texturePromise;
        }));

        if (nftImageAsset == null)
        {
            yield return(WrappedTextureUtils.Fetch(nftInfo.originalImageUrl,
                                                   (downloadedTex, texturePromise) =>
            {
                nftImageAsset = downloadedTex;
                this.texturePromise = texturePromise;
            }, Asset_Gif.MaxSize._256));
        }

        if (nftImageAsset != null)
        {
            imageAsset       = nftImageAsset;
            imageNft.texture = nftImageAsset.texture;

            if (nftImageAsset is Asset_Gif gifAsset)
            {
                gifAsset.OnFrameTextureChanged += (texture) => { imageNft.texture = texture; };
                gifAsset.Play();
            }
            else
            {
                if (!backgroundColorSet)
                {
                    SetSmartBackgroundColor(nftImageAsset.texture);
                }
            }

            SetNFTImageSize(nftImageAsset.texture);

            imageNft.gameObject.SetActive(true);
            spinnerNftImage.SetActive(false);
        }
    }
    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);
    }