From 7f493f682503f5186308de7b8f74b5b49233cfe4 Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Thu, 2 Nov 2023 11:51:31 +0800 Subject: +init --- GameCode/HighscoreTable.cs | 99 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 GameCode/HighscoreTable.cs (limited to 'GameCode/HighscoreTable.cs') diff --git a/GameCode/HighscoreTable.cs b/GameCode/HighscoreTable.cs new file mode 100644 index 0000000..fbfdc4c --- /dev/null +++ b/GameCode/HighscoreTable.cs @@ -0,0 +1,99 @@ +using System.Collections.Generic; +using Steamworks; +using UnityEngine; + +public class HighscoreTable : MonoBehaviour +{ + private ScoreTag[] scoreTags = new ScoreTag[0]; + + private string currentHighscoreTableToCall = ""; + + public Transform scoreTagParent; + + public GameObject loading; + + public GameObject notConnectedToSteam; + + public GameObject noScore; + + public GameObject noFriends; + + private bool subscribedToSteamManager; + + public void SetAndDownloadHighscoreTable(string _highscoreTableName) + { + noScore.SetActive(value: false); + noFriends.SetActive(value: false); + currentHighscoreTableToCall = _highscoreTableName; + scoreTags = new ScoreTag[scoreTagParent.childCount]; + for (int i = 0; i < scoreTagParent.childCount; i++) + { + scoreTags[i] = scoreTagParent.GetChild(i).GetComponent(); + scoreTagParent.GetChild(i).gameObject.SetActive(value: false); + } + if (SteamManager.Initialized) + { + SubscribeToSteamManger(); + SteamManager.Instance.DownloadFriendsHighscores(currentHighscoreTableToCall); + loading.SetActive(value: true); + notConnectedToSteam.SetActive(value: false); + } + else + { + loading.SetActive(value: false); + notConnectedToSteam.SetActive(value: true); + } + } + + private void OnEnable() + { + SetAndDownloadHighscoreTable(LevelInteractor.lastActivatedLevelInteractor.sceneName); + } + + private void SubscribeToSteamManger() + { + if (!subscribedToSteamManager) + { + SteamManager.Instance.OnLeaderboardDownloadCallbackComplete.AddListener(RefreshUI); + subscribedToSteamManager = true; + } + } + + private void RefreshUI() + { + for (int i = 0; i < scoreTags.Length; i++) + { + scoreTags[i].gameObject.SetActive(value: false); + } + List lastDownloadedLeaderboardEntires = SteamManager.Instance.lastDownloadedLeaderboardEntires; + if (lastDownloadedLeaderboardEntires.Count > 0) + { + loading.SetActive(value: false); + notConnectedToSteam.SetActive(value: false); + bool flag = false; + foreach (SteamManager.LeaderboardEntry item in lastDownloadedLeaderboardEntires) + { + if (item.username == SteamFriends.GetPersonaName()) + { + flag = true; + break; + } + } + noScore.SetActive(!flag); + noFriends.SetActive(lastDownloadedLeaderboardEntires.Count == 1 && flag); + } + else + { + loading.SetActive(value: false); + notConnectedToSteam.SetActive(value: false); + noScore.SetActive(value: true); + noFriends.SetActive(value: true); + } + for (int j = 0; j < lastDownloadedLeaderboardEntires.Count && j <= scoreTags.Length - 1; j++) + { + bool isPlayer = lastDownloadedLeaderboardEntires[j].username == SteamFriends.GetPersonaName(); + scoreTags[j].gameObject.SetActive(value: true); + scoreTags[j].SetNameAndScore(lastDownloadedLeaderboardEntires[j].username, lastDownloadedLeaderboardEntires[j].score, j + 1, isPlayer); + } + } +} -- cgit v1.1-26-g67d0