private IEnumerator Populate(ScoreResponse response, float fadeDuration) { waitingForScoresText.DOFade(0, fadeDuration); entriesCanvasGroup.DOFade(1, fadeDuration); List <ScoreEntryData> orderedEntries = response.entries.OrderBy(x => x.rank).ToList(); for (int i = 0; i < orderedEntries.Count; i++) { ScoreEntryData entryData = orderedEntries[i]; entries[i].SetScoreEntryData(entryData, i == response.senderIndex, fadeDuration); yield return(new WaitForSeconds(fadeDuration / 2f)); } yield return(new WaitForSeconds(fadeDuration * 10f)); menuManager.Hide(); }
public void AddEntry(ScoreEntryData entryData) { //Get the saved scores ScoreboardSaveData savedScores = GetSavedScores(); bool scoreAdded = false; //Loop through all saved scores for (int i = 0; i < savedScores.highScores.Count; i++) { //Check if the entry score is greater than this score if (entryData.entryScore >= savedScores.highScores[i].entryScore) { //Add the score to that point in the list savedScores.highScores.Insert(i, entryData); //Score has now been added scoreAdded = true; //Break out of the loop break; } } //Check if the score has not been added and the saved scores is lower than the max scores if (!scoreAdded && savedScores.highScores.Count < maxEntries) { //Add the entry data as a new item on the list savedScores.highScores.Add(entryData); } //If the number of saved scores is higher than the max entries if (savedScores.highScores.Count > maxEntries) { //Remove a range of entries until the number is equal to the max entries savedScores.highScores.RemoveRange(maxEntries, savedScores.highScores.Count - maxEntries); } //Save the scores SaveScores(savedScores); //Update the UI UpdateUI(savedScores, entryData); }
public void SetScoreEntryData(ScoreEntryData data, bool isLocal, float fadeDuration) { canvasGroup.DOFade(1, fadeDuration); rank.text = data.rank.ToString(); username.text = data.username; score.text = data.score.ToString(); if (isLocal == true) { background.gameObject.SetActive(true); rank.color = darkColor; username.color = darkColor; score.color = darkColor; } else { background.gameObject.SetActive(false); rank.color = lightColor; username.color = lightColor; score.color = lightColor; } }
private void UpdateUI(ScoreboardSaveData savedScores, ScoreEntryData newData) { if (savedScores.highScores.Count == 0) { //Disable the highscores holder scoreHolder.gameObject.SetActive(false); return; } //If the holder game object is disabled if (scoreHolder.gameObject.activeSelf == false) { //Activate the game object scoreHolder.gameObject.SetActive(true); } //Loop through all child objects in scoreHoler foreach (Transform child in scoreHolder) { //Destroy the child object Destroy(child.gameObject); } //Loop through all the entries in savedScores foreach (ScoreEntryData highScore in savedScores.highScores) { //Spawn the entry UI ScoreEntryUI scoreListing = Instantiate(scoreEntryObject, scoreHolder).GetComponent <ScoreEntryUI>(); //Initalise the UI scoreListing.Initialize(highScore); //check if the new data matches the current highscore if (newData.Equals(highScore)) { scoreListing.HighlightUI(); } } }
[SerializeField] private Color highlightColor; //Color to highlight the background image public void Initialize(ScoreEntryData entryData) { //Set the entry text based on the data entryNameText.text = entryData.entryName; entryScoreText.text = $"{entryData.entryScore}"; }