Exemple #1
0
    public void LoadList(string category)
    {
        SpawnList spawnList = spawner.GetComponent <SpawnList>();

        currentCategory = category;
        // set title
        titleLabel.GetComponent <Text>().text = spawnList.getCategoryTitle(currentCategory);

        furnitures = spawnList.findBundle(category);

        int currentIndex = 0;

        if (pageHistory.ContainsKey(category))
        {
            currentIndex = pageHistory[category];
        }
        else
        {
            pageHistory[category] = 0;
        }

        int i = currentIndex * pageSize;

        foreach (GameObject furnitureBtn in furniturePage)
        {
            if (i < Math.Min(furnitures.Count, (currentIndex + 1) * pageSize))
            {
                furnitureBtn.SetActive(true);
                GameObject        f          = furnitures[i];
                FurnitureProperty properties = spawnList.findAssetProperties(category, f.name);
                furnitureBtn.GetComponent <FurnitureMenuItemProperty>().furnitureProperty = properties;
                furnitureBtn.GetComponent <FurnitureMenuItemProperty>().index             = i;
                if (!category.Contains("paint"))
                {
                    furnitureBtn.GetComponent <Image>().sprite   = spawnList.findAssetIcon(category, i);
                    furnitureBtn.GetComponent <Image>().material = null;
                }
                else
                {
                    furnitureBtn.GetComponent <Image>().sprite   = null;
                    furnitureBtn.GetComponent <Image>().material = spawnList.findPaintIcon(i);
                }
                i++;
            }
            else
            {
                furnitureBtn.SetActive(false);
            }
        }

        if (furnitures.Count <= pageSize)
        {
            forward.SetActive(false);
            backward.SetActive(false);
        }
        else if (currentIndex == 0)
        {
            forward.SetActive(true);
            backward.SetActive(false);
        }
        else if ((furnitures.Count - currentIndex * pageSize) <= pageSize)
        {
            forward.SetActive(false);
            backward.SetActive(true);
        }
        else
        {
            backward.SetActive(true);
            forward.SetActive(true);
        }
    }