Esempio n. 1
0
    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();
    }
Esempio n. 2
0
    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();
        }
    }
    void FinishLoading(bool loadedSuccessfully)
    {
        if (loadedSuccessfully)
        {
            if (spinner != null)
            {
                spinner.SetActive(false);
            }

            OnLoadingAssetSuccess?.Invoke();
        }
        else
        {
            OnLoadingAssetFail?.Invoke();
        }
    }
Esempio n. 4
0
    IEnumerator FetchNFTImage()
    {
        string jsonURL = $"{NFTDataFetchingSettings.DAR_API_URL}/{darURLRegistry}/asset/{darURLAsset}";

        UnityWebRequest www = UnityWebRequest.Get(jsonURL);

        yield return(www.SendWebRequest());

        if (!www.WebRequestSucceded())
        {
            OnLoadingAssetFail?.Invoke();

            Debug.LogError($"{www.responseCode} - {www.url}", gameObject);

            yield break;
        }

        NFTAssetData currentAssetData = JsonUtility.FromJson <NFTAssetData>(www.downloadHandler.text);

        if (currentAssetData.files == null)
        {
            Debug.LogError($"Didn't find any asset image for '{jsonURL}' for the NFTShape.");

            yield break;
        }

        if (VERBOSE)
        {
            Debug.Log("NFT fetched JSON: " + www.downloadHandler.text);

            Debug.Log("NFT Assets Found: ");
            for (int i = 0; i < currentAssetData.files.Length; i++)
            {
                Debug.Log("file url: " + currentAssetData.files[i]?.url);
            }
        }

        string thumbnailImageURL = null;
        string dclImageURL       = null;
        string previewImageURL   = null;

        for (int i = 0; i < currentAssetData.files.Length; i++)
        {
            if (currentAssetData.files[i].role == "thumbnail")
            {
                thumbnailImageURL = currentAssetData.files[i].url;
            }
            else if (currentAssetData.files[i].role == "preview")
            {
                previewImageURL = currentAssetData.files[i].url;
            }
            else if (currentAssetData.files[i].role == "dcl-picture-frame-image")
            {
                dclImageURL = currentAssetData.files[i].url;
            }
        }

        // 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(dclImageURL))
        {
            yield return(Utils.FetchWrappedTextureAsset(dclImageURL, (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(previewImageURL))
        {
            yield return(Utils.FetchWrappedTextureAsset(previewImageURL, (downloadedAsset) =>
            {
                // Dispose thumbnail
                if (nftAsset != null)
                {
                    nftAsset.Dispose();
                }
                SetFrameImage(downloadedAsset, resizeFrameMesh: true);
            }));
        }

        OnLoadingAssetSuccess?.Invoke();
    }