public void SetScore(Score score, int level)
    {
        ButtonNext.SetActive(false);
        gameObject.SetActive(true);
        int stars = 0;

        switch (score)
        {
        case Score.Bad:
            TextResult.text  = BadResultText;
            TextResult.color = BadResult;
            FindObjectOfType <SoundManager>().PlaySFXLoose();
            break;

        case Score.Ok:
            stars            = 1;
            TextResult.text  = OKResultText;
            TextResult.color = OKResult;
            FindObjectOfType <SoundManager>().PlaySFXVictory();
            break;

        case Score.Good:
            stars            = 2;
            TextResult.text  = GoodResultText;
            TextResult.color = GoodResult;
            FindObjectOfType <SoundManager>().PlaySFXVictory();
            break;

        case Score.Awesome:
            stars            = 3;
            TextResult.text  = AwesomeResultText;
            TextResult.color = AwesomeResult;
            FindObjectOfType <SoundManager>().PlaySFXAwesomeVictory();
            FindObjectOfType <SoundManager>().PlaySFXVictory();
            break;
        }

        SetStarsEnabled(stars);

        if (stars > 0 || LevelSelector.LastLevelEnabled > level)
        {
            if (LevelSelector.Levels.Count >= level + 1)
            {
                ButtonNext.SetActive(true);
            }
        }

        int starsHighScore = PlayerPrefsService.GetStarsHighScoreFromLevel(level);

        if (stars > starsHighScore)
        {
            PlayerPrefsService.SetStarsHighScoreFromLevel(stars, level);
        }
    }
Beispiel #2
0
    private void BuildUILevels(XmlNodeList nodes)
    {
        bool nextLevelEnabled = true;

        for (int i = 0; i < nodes.Count; i++)
        {
            XmlNode node   = nodes[i];
            Button  button = Instantiate(ButtonLevelSelector, ContainerLevels.transform);

            int level = i + 1;

            int starHighScore = PlayerPrefsService.GetStarsHighScoreFromLevel(level);
            button.interactable = (nextLevelEnabled)?true:false;

            if (button.interactable)
            {
                LastLevelEnabled = level;
            }

            if (starHighScore > 0)
            {
                nextLevelEnabled = true;
            }
            else
            {
                nextLevelEnabled = false;
            }

            int tracks = Convert.ToInt32(node.SelectSingleNode("tracks").InnerText);
            int total  = Convert.ToInt32(node.SelectSingleNode("total").InnerText);
            int good   = Convert.ToInt32(node.SelectSingleNode("good").InnerText);
            int speed  = Convert.ToInt32(node.SelectSingleNode("speed").InnerText);

            LevelInfo levelInfo = new LevelInfo()
            {
                Level          = level,
                TotalFoods     = total,
                TotalFoodsGood = good,
                Speed          = speed,
                Tracks         = tracks,
                Stars          = starHighScore
            };

            Levels.Add(levelInfo);

            button.GetComponent <ButtonLevel>().Info = levelInfo;
        }
    }