コード例 #1
0
    /// <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);
            }
        }
    }