コード例 #1
0
    private void DisplayScrollViewWords()
    {
        isTagsView = false;
        Debug.Log("Begin DisplayScrollViewWords method");
        foreach (Transform child in contentRect.transform)
        {
            Destroy(child.gameObject);
        }

        GameObject tempPanel;

        contentTransform = contentRect.GetComponent <RectTransform>();
        float entryNum = 0;

        // Create a sorted word list to use when spawning word panels
        SortedDictionary <string, WordDO> sortedWordList = new SortedDictionary <string, WordDO>(controller.GetListCopy());

        List <string> tempScrollviewList = new List <string>();

        foreach (var entry in sortedWordList)
        {
            List <string> wordTagsList   = new List <string>();
            List <string> filterTagsList = new List <string>();

            if (entry.Value.WordTags != null)
            {
                wordTagsList   = entry.Value.WordTags.Split(',').ToList();
                filterTagsList = filterTags.Split(',').ToList();
            }

            if (filterTags == "" || filterTags == null)
            {
                //Debug.Log("No filter tags detected");
                tempPanel = GameObject.Instantiate(wordCopyPanel, contentRect.transform, false);
                tempPanel.transform.GetChild(0).GetComponent <Text>().text = TidyCase(entry.Key);

                if (entry.Value.WordTags != null)
                {
                    tempPanel.transform.GetChild(1).GetComponent <Text>().text = TidyCase(entry.Value.WordTags);
                }


                //Disable the delete button for stock words
                if (!entry.Value.StockCustom.Equals("custom"))
                {
                    tempPanel.transform.GetChild(4).GetComponent <Button>().interactable = false;
                }

                //enable the stats button
                tempPanel.transform.GetChild(3).GetComponent <Button>().interactable = true;

                tempPanel.name = entry.Key;
                tempPanel.SetActive(true);
                entryNum += 1;
            }
            else
            {
                Debug.Log("Filter tags detected");

                foreach (string tag in filterTagsList)
                {
                    //Debug.Log("tag = " + tag);
                    if (!tempScrollviewList.Contains(entry.Value.Word_name))
                    {
                        //Debug.Log(entry.Value.Word_name + " is not yet in the tempscrollviewlist");

                        if ((entry.Value.WordTags.Contains(tag)) || (entry.Value.WordTags.Contains(" " + tag)))
                        {
                            Debug.Log("wordtaglist contains = " + tag + " for word " + entry.Value.Word_name);
                            tempPanel = GameObject.Instantiate(wordCopyPanel, contentRect.transform, false);
                            tempPanel.transform.GetChild(0).GetComponent <Text>().text = TidyCase(entry.Key);

                            if (entry.Value.WordTags != null)
                            {
                                tempPanel.transform.GetChild(1).GetComponent <Text>().text = TidyCase(entry.Value.WordTags);
                            }

                            if (!entry.Value.StockCustom.Equals("custom"))
                            {
                                tempPanel.transform.GetChild(4).GetComponent <Button>().interactable = false;
                            }

                            tempPanel.transform.GetChild(3).GetComponent <Button>().interactable = true;

                            tempPanel.name = entry.Key;
                            tempPanel.SetActive(true);
                            entryNum += 1;
                            tempScrollviewList.Add(entry.Value.Word_name);
                        }
                    }
                }
            }
        }

        tempScrollviewList.Clear();
        tempScrollviewList = null;
        sortedWordList.Clear();

        contentTransform.sizeDelta = new Vector2(contentTransform.rect.width, entryNum * yOffSet);
    }