// Start is called before the first frame update
    void Start()
    {
        m_PInfo     = GameObject.Find("PersistentStorage").GetComponent <PersistentInfo_Script>();
        m_LocalUser = m_PInfo.m_UserData;
        m_LocalData = SaveGameSystem.LoadGame("LeaderboardData") as LeaderboardData;

        if (m_LocalData != null)
        {
            string top;
            if (m_LocalData.FindUser(m_LocalUser) > -1)
            {
                m_LocalUser = m_LocalData.GetUser(m_LocalUser.m_UserName);
                top         = m_LocalUser.m_UserName + " " + m_LocalUser.m_Score + " Rank: " + m_LocalUser.m_Rank;
            }
            else
            {
                top = "You have not scored yet.";
            }
            ChangeTopText(top);
            PopulateBoard();
        }
        else
        {
            string top = "No Leaderboard Available";
            ChangeTopText(top);
        }
    }
示例#2
0
    public void UpdateLeaderboard()
    {
        //Check if leaderboard exists.
        if (m_LocalData != null)
        {
            //Check if player has existing score.
            int pIndex = m_LocalData.FindUser(m_LocalUser);
            if (pIndex > -1)
            {
                //Check if Player has new highscore.
                if (m_LocalData.GetUser(pIndex).m_Score < m_LocalUser.m_Score)
                {
                    m_LocalData.GetUser(pIndex).m_Score = m_PInfo.m_UserData.m_Score;
                    //Sort Leaderboard to account for changes.
                    m_LocalData.SortLeaderboard();
                }
                //Update local stats.
                m_LocalUser = m_LocalData.GetUser(m_LocalUser.m_UserName);
            }
            else
            {
                //User doesn't exist, create new user.
                m_LocalData.AddUser(m_LocalUser);
                m_LocalData.SortLeaderboard();
                m_LocalUser = m_LocalData.GetUser(m_LocalUser.m_UserName);
            }

            //Save.
            //SaveGameSystem.DeleteSaveGame("LeaderboardData");
            SaveGameSystem.SaveGame(m_LocalData, "LeaderboardData");
        }
        else
        {
            //create new save data;
            m_LocalUser.m_Rank = 1;

            //Add player data to the leaderboard.
            LeaderboardData newLeaderboard = new LeaderboardData();
            newLeaderboard.AddUser(m_LocalUser);

            //Save Leaderboard
            SaveGameSystem.SaveGame(newLeaderboard, "LeaderboardData");
        }
    }