Exemple #1
0
    IEnumerator DownloadWordPictures(string word)
    {
        Debug.Log("starting picture download for " + word);
        string[] urls =
        {
            "https://matthewriddett.com/static/mludlc/pictures/" + word + "/" + word + "1.png",
            "https://matthewriddett.com/static/mludlc/pictures/" + word + "/" + word + "2.png",
            "https://matthewriddett.com/static/mludlc/pictures/" + word + "/" + word + "3.png",
            "https://matthewriddett.com/static/mludlc/pictures/" + word + "/" + word + "4.png",
            "https://matthewriddett.com/static/mludlc/pictures/" + word + "/" + word + "5.png"
        };

        foreach (string url in urls)
        {
            using (UnityWebRequest www = UnityWebRequestTexture.GetTexture(url))
            {
                yield return(www.SendWebRequest());

                if (www.isNetworkError || www.isHttpError)
                {
                    Debug.Log(www.error);
                }
                else
                {
                    Texture2D myTexture = ((DownloadHandlerTexture)www.downloadHandler).texture;


                    controller.SetCurrentTexture(myTexture);
                    if (controller.IsTextureSet())
                    {
                        controller.AddNewTexture();
                    }
                    myTexture = null;
                }
            }
        }

        controller.SaveNewWord(tempWordName, tempWordTags);
        Debug.Log("Done downloading word: " + tempWordName);
        controller.ClearTextureList();
        doneImageDownload = true;
    }
    /// <summary>
    /// Recovers a list of Texture2D objects and loops through the collection
    /// applying each texture to a cloned toggle object. If any new textures are
    /// set they are added to the collection.
    /// </summary>
    private void DisplayGallery()
    {
        CleanUpScroll();
        // Check if there is a new stored texture and add if so.
        if (controller.IsTextureSet())
        {
            controller.AddNewTexture();
        }

        Debug.Log("Past the first check in DISPLAY GALLERY");

        bool texturesLoaded = false;

        if (!controller.AreTexturesPresent())
        {
            if (controller.IsEditSettings)
            {
                Debug.Log("IS EDIT WORD IS " + wordText.GetComponent <Text>().text);
                texturesLoaded = controller.RetrievePictures(wordText.GetComponent <Text>().text);
            }
            else
            {
                if (string.Equals(placeHolderText.text, ""))
                {
                    return;
                }
                else
                {
                    Debug.Log("ADDING NEW WORD IS " + wordFieldText.text);
                    texturesLoaded = controller.RetrievePictures(placeHolderText.text);
                }
            }
        }

        if (texturesLoaded || controller.AreTexturesPresent())
        {
            GameObject tempToggle;
            RawImage   tempImage;
            customList = new List <Texture2D>(controller.GetImages());
            Debug.Log("customList count is: " + customList.Count.ToString());

            // Check if the customList entry count is greater than zero before trying the loop.
            if (customList.Count > 0)
            {
                Debug.Log("Passed the IF statement");

                foreach (Texture2D tex in customList)
                {
                    tempToggle        = GameObject.Instantiate(imageToggleCopy, imagesPanel.transform, false);
                    tempImage         = tempToggle.transform.GetChild(0).Find("RawImage").GetComponent <RawImage>();
                    tempImage.texture = tex;
                    tempToggle.SetActive(true);
                }
            }
        }

        GameObject tempStockToggle;
        RawImage   tempStockImage;

        stockList = new List <Texture2D>(controller.GetStockImages());

        if (stockList.Count > 0)
        {
            foreach (Texture2D tex in stockList)
            {
                tempStockToggle        = GameObject.Instantiate(stockImageToggleCopy, imagesPanel.transform, false);
                tempStockImage         = tempStockToggle.transform.GetChild(0).Find("RawImage").GetComponent <RawImage>();
                tempStockImage.texture = tex;
                tempStockToggle.SetActive(true);
            }
        }
    }