示例#1
0
    /// <summary>
    /// This function is used to increase the players xp and update various UI elements.
    /// </summary>
    /// <param name="xp"></param>
    private void IncreaseXP(int xp)
    {
        int prevLevel = info.GetLevel();

        info.AddXp(xp);
        _xpSlider.fillAmount = info.GetPercentageToNextLevel();
        int currentLevel = info.GetLevel();

        tempLevel.text = "" + currentLevel;

        if (powers.Count > 0 && prevLevel < currentLevel)
        {
            UpdatePowers(currentLevel);
        }
    }
示例#2
0
    // Start is called before the first frame update
    void Start()
    {
        info = PlayerInfoScript.instance;

        if (info == null)
        {
            Debug.LogError("PlayerInfoScript not found");
        }

        //Update the achievement list and get the index of completion
        int levelIndex = UpdateAchievements(info.GetLevelAchievementIndex(), info.GetLevel(), _levelAchievements, 0);
        int killIndex  = UpdateAchievements(info.GetKillAchievementIndex(), info.GetTotalKills(), _killAchivements, 1);

        _achievementScroller.GetComponent <ScrollRect>().verticalNormalizedPosition = 1; //Automatically scroll to the top

        //If the game hasn't be loaded before, then set the achievement index for each achievement.
        if (!info.HasAchievementBeenLoaded())
        {
            info.SetAchievementLevel(levelIndex);
            info.SetAchievementKillLevel(killIndex);
        }

        //Update the UI for coins and the xp bar
        _levelUIManager.UpdateUIStats();
        OrderAchievements();
    }
示例#3
0
    /// <summary>
    /// This fucntion is used to update the coins and xp bars on the stats panel.
    /// </summary>
    public void UpdateUIStats()
    {
        PlayerInfoScript play = PlayerInfoScript.instance;

        tempCoins.text = play.GetCoinCount().ToString("00000000");//change the innital coin display here
        tempLevel.transform.parent.transform.Find("Fill").GetChild(0).GetComponent <Image>().fillAmount = play.GetPercentageToNextLevel();
        tempLevel.text = "" + play.GetLevel();
    }
示例#4
0
    private PlayerInfoScript info;                                      // A reference to the PlayerInfoScript singleton
    #endregion

    private void Start()
    {
        //Get all of the references in the game
        _buttonPanel      = GameObject.Find("Buttons");
        _allPanels        = GameObject.Find("SugarPanels");
        _backButton       = GameObject.Find("BackButton");
        _selectionPanel   = GameObject.Find("Selection");
        _skillsPanel      = GameObject.Find("SkillsPanel");
        _mainMenuPanel    = GameObject.Find("MainMenu");
        _achievementPanel = GameObject.Find("AchievementsPanel");
        _leftArrow.SetActive(false);

        _xpSlider = tempLevel.transform.parent.transform.Find("Fill").GetChild(0).GetComponent <Image>();

        _allPanels.SetActive(false);
        _selectionPanel.SetActive(false);
        _skillsPanel.SetActive(false);
        _achievementPanel.SetActive(false);

        info                 = PlayerInfoScript.instance;
        tempCoins.text       = info.GetCoinCount().ToString("00000000");
        _xpSlider.fillAmount = info.GetPercentageToNextLevel();
        tempLevel.text       = "" + info.GetLevel();
        UpdatePowers(info.GetLevel());

        _currentLevels = _mainMenuPanel;

        int size = _allPanels.transform.childCount;

        //Loop through the sugar groups panels
        for (int i = 0; i < size; i++)
        {
            SugarButton group = new SugarButton();
            Transform   panel = _allPanels.transform.GetChild(i).GetChild(0);

            _allPanels.transform.GetChild(i).GetComponent <ScrollRect>().verticalNormalizedPosition = 1; //Automatically scroll to the top
            group.init(panel.gameObject, PlayerInfoScript.instance.GetLevelInSugarGroup(i));             //Init the sugar group

            buttonGroups.Add(group);

            //Update the titles
            Transform child = panel.parent.Find("Text");

            if (group._currentButton)
            {
                group._currentButton.onClick.AddListener(() => PlayLevel(_currentSelection)); //Set the current button to be active
                group._currentButton.interactable = true;
                child.GetComponent <Text>().text  = buttonGroups[i]._name + " - " + (buttonGroups[i]._currentButtonIndex) + "/" + buttonGroups[i]._buttonCount;
            }
            else
            {
                child.GetComponent <Text>().text = buttonGroups[i]._name + " - " + (buttonGroups[i]._buttonCount) + "/" + buttonGroups[i]._buttonCount;
            }

            //Update the buttons to be at the location last saved (Future: From the save file)
            UpdateButtons(buttonGroups[i]);



            panel.parent.gameObject.SetActive(false);
        }

        //Settings for the "map" selection animations
        _selectionOffset = -_selectionPanel.transform.GetChild(0).GetComponent <RectTransform>().sizeDelta.x / buttonGroups.Count;
        _targetLocation  = -_selectionPanel.transform.GetChild(0).GetChild(0).GetComponent <RectTransform>().anchoredPosition.x;
    }
示例#5
0
    /// <summary>
    /// This functon is used to update the achievement list. Upon completion, the text will turn green
    /// and the achievement will be placed in the completed list.
    /// </summary>
    /// <param name="completedIndex"></param>
    /// <param name="value"></param>
    /// <param name="achievement"></param>
    /// <param name="key"></param>
    /// <returns></returns>
    private int UpdateAchievements(int completedIndex, int value, List <Achieve> achievement, int key = 0)
    {
        int xpToAdd = 0;
        int index   = 0;

        for (int i = 0; i < achievement.Count; i++)
        {
            //If a UI element hasnt been made for the achievement, then create onne
            if (achievement[i]._UIElement == null)
            {
                GameObject achieve = Instantiate(_achievementPrefab, _achievementScroller.transform.GetChild(0));
                achievement[i]._UIElement = achieve;
                if (achievement[i].isHidden)
                {
                    achieve.GetComponent <TextMeshProUGUI>().text = " HIDDEN";
                }
                else
                {
                    achieve.GetComponent <TextMeshProUGUI>().text = " " + achievement[i].wording;
                }
            }


            //If the value is create than the achievement value, then set this achievement as complete
            if (value >= achievement[i]._value)
            {
                _completed.Add(achievement[i]);

                if (index > completedIndex - 1)
                {
                    print(achievement[i].wording);
                    info.AddCoins(achievement[i]._coinReward);
                    xpToAdd += achievement[i]._xpReward;
                }

                achievement[i]._UIElement.GetComponent <TextMeshProUGUI>().color = Color.green;
                achievement.RemoveAt(i);
                i--;
                index++;
            }
        }

        //If an achievement has been made and you need the rewards, gain the rewards and make sure that another achievement hasn't been achieved
        if (xpToAdd > 0)
        {
            info.AddXp(xpToAdd);
            switch (key)
            {
            case 0:
                break;

            case 1:
                UpdateAchievements(info.GetKillAchievementIndex(), info.GetTotalKills(), _killAchivements, 1);
                break;

            default:
                Debug.Log("KEY NOT FOUND");
                break;
            }
            ;
            UpdateAchievements(info.GetLevelAchievementIndex(), info.GetLevel(), _levelAchievements, 0);
        }
        return(index);
    }