Пример #1
0
    void FillList()
    {
        foreach (var level in levelList)
        {
            GameObject newButton = Instantiate(levelButton) as GameObject;

            LevelSelectButton button = newButton.GetComponent <LevelSelectButton> ();

            button.levelText.text = level.levelText;

            if (PlayerPrefs.GetInt("Level_" + button.levelText.text) == 1)
            {
                level.unLocked       = 1;
                level.isInteractable = true;
            }

            button.unlocked = level.unLocked;
            button.GetComponent <Button> ().interactable = level.isInteractable;
            button.GetComponent <Button> ().onClick.AddListener(() => LoadLevels("Level_" + button.levelText.text));

            if (PlayerPrefs.GetInt("Level_" + button.levelText.text + "_done") == 1)
            {
                button.Star1.SetActive(true);
            }
            if (PlayerPrefs.GetInt("Level_" + button.levelText.text + "_target") == 1)
            {
                button.Star2.SetActive(true);
            }
            if (PlayerPrefs.GetInt("Level_" + button.levelText.text + "_fullhealth") == 1)
            {
                button.Star3.SetActive(true);
            }

            newButton.transform.SetParent(spacer);
            numberOfLevels = numberOfLevels + 1;
        }
        SaveAll();
    }
    void Start()
    {
        DontDestroyOnLoad(gameObject);

        foreach (LevelData levelData in levels)
        {
            LevelSelectButton button = Instantiate(levelSelectButton, levelSelectButton.transform.parent);
            button.levelImage.sprite   = levelData.levelimage;
            button.levelNameText.text  = levelData.uiName;
            button.difficultyText.text = levelData.difficulty.ToString();

            button.GetComponent <Button>().onClick.AddListener(delegate { SelectLevel(levelData); });
        }

        levelSelectButton.gameObject.SetActive(false);
    }
    /// <summary>
    /// Instantiate the buttons
    /// </summary>
    protected virtual void Start()
    {
        if (GameManager.instance == null)
        {
            return;
        }

        m_LevelList = GameManager.instance.LevelList;

        if (LayoutGroup == null || SelectionPrefab == null || m_LevelList == null)
        {
            return;
        }

        int amount = m_LevelList.Count;

        for (int i = 0; i < amount; i++)
        {
            LevelSelectButton button = CreateButton(m_LevelList[i]);
            button.transform.SetParent(LayoutGroup.transform);
            button.transform.localScale = Vector3.one;
            m_Buttons.Add(button.GetComponent <Button>());
        }

        if (RightBuffer != null)
        {
            RightBuffer.SetAsLastSibling();
        }

        for (int k = 1; k < m_Buttons.Count - 1; k++)
        {
            Button button = m_Buttons[k];
            SetupNavigation(button, m_Buttons[k - 1], m_Buttons[k + 1]);
        }

        SetupNavigation(m_Buttons[0], BackButton, m_Buttons[1]);
        SetupNavigation(m_Buttons[m_Buttons.Count - 1], m_Buttons[m_Buttons.Count - 2], null);
        // Scrolling to do
    }