Leaderboard holdtime updates properly now

This commit is contained in:
djkellerman
2025-03-28 20:34:09 -04:00
parent a098e8c053
commit 0bf6ab0da7
4 changed files with 57 additions and 9 deletions

View File

@@ -25,7 +25,7 @@ RectTransform:
m_GameObject: {fileID: 367874778634194597}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_LocalScale: {x: 0.5, y: 0.5, z: 0.5}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 1907008449299828318}
@@ -222,7 +222,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 83.2, y: -51.3}
m_AnchoredPosition: {x: 33.5, y: -1.4}
m_SizeDelta: {x: 200, y: 50}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &2723348749531219125
@@ -253,7 +253,7 @@ MonoBehaviour:
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_text: 3:00
m_text: 0:00
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: f4b6d771d01664138b2f3db447b45695, type: 2}
m_sharedMaterial: {fileID: 560944918044722035, guid: f4b6d771d01664138b2f3db447b45695, type: 2}

View File

@@ -4811,7 +4811,31 @@ PrefabInstance:
m_Modifications:
- target: {fileID: 2396754106601062846, guid: e3c570bb90d434e809aca2a339dadf5d, type: 3}
propertyPath: time
value: 10
value: 180
objectReference: {fileID: 0}
- target: {fileID: 3636379526195672734, guid: e3c570bb90d434e809aca2a339dadf5d, type: 3}
propertyPath: m_fontAsset
value:
objectReference: {fileID: 11400000, guid: f4b6d771d01664138b2f3db447b45695, type: 2}
- target: {fileID: 3636379526195672734, guid: e3c570bb90d434e809aca2a339dadf5d, type: 3}
propertyPath: m_sharedMaterial
value:
objectReference: {fileID: 560944918044722035, guid: f4b6d771d01664138b2f3db447b45695, type: 2}
- target: {fileID: 3636379526195672734, guid: e3c570bb90d434e809aca2a339dadf5d, type: 3}
propertyPath: m_hasFontAssetChanged
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4185538254637364967, guid: e3c570bb90d434e809aca2a339dadf5d, type: 3}
propertyPath: m_AnchorMin.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4185538254637364967, guid: e3c570bb90d434e809aca2a339dadf5d, type: 3}
propertyPath: m_SizeDelta.x
value: -0.5
objectReference: {fileID: 0}
- target: {fileID: 4185538254637364967, guid: e3c570bb90d434e809aca2a339dadf5d, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0.25
objectReference: {fileID: 0}
- target: {fileID: 4832072825095962115, guid: e3c570bb90d434e809aca2a339dadf5d, type: 3}
propertyPath: timer
@@ -4833,6 +4857,14 @@ PrefabInstance:
propertyPath: m_Name
value: Game Manager
objectReference: {fileID: 0}
- target: {fileID: 7577461774610221307, guid: e3c570bb90d434e809aca2a339dadf5d, type: 3}
propertyPath: m_Spacing.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7577461774610221307, guid: e3c570bb90d434e809aca2a339dadf5d, type: 3}
propertyPath: m_CellSize.y
value: 50
objectReference: {fileID: 0}
- target: {fileID: 7676803003410367555, guid: e3c570bb90d434e809aca2a339dadf5d, type: 3}
propertyPath: m_LocalPosition.x
value: 29

View File

@@ -165,7 +165,7 @@ public class GameManager : MonoBehaviour
return alivePlayers;
}
public void UpdatePlayerHoldTime(GameObject player, float holdTime) // Finds each players hold time and updates the leaderboard
public void UpdatePlayerHoldTime(GameObject player, float holdTime)
{
if (playerHoldTimes.ContainsKey(player))
{

View File

@@ -1,5 +1,6 @@
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.UI;
public class LeaderboardManager : MonoBehaviour
@@ -31,6 +32,9 @@ public class LeaderboardManager : MonoBehaviour
private void InitializeLeaderboard() // Creates the leaderboard icons for each player
{
RectTransform parentRectTransform = playersParent.GetComponent<RectTransform>();
parentRectTransform.anchoredPosition = new Vector2(-20f, 10f);
foreach (GameObject player in GameManager.players)
{
Transform parent = Instantiate(playerPrefab, playersParent.transform).transform;
@@ -45,12 +49,24 @@ public class LeaderboardManager : MonoBehaviour
List<KeyValuePair<GameObject, float>> sortedList = new List<KeyValuePair<GameObject, float>>(GameManager.playerHoldTimes);
sortedList.Sort((pair1, pair2) => pair2.Value.CompareTo(pair1.Value));
foreach (var player in sortedList)
{
Debug.Log(player.Key.name + " : " + player.Value);
}
foreach (var player in sortedList)
{
playerIcons[player.Key].transform.SetSiblingIndex(sortedList.IndexOf(player));
UpdatePlayerHoldTimeText(player.Key, player.Value);
}
}
private void UpdatePlayerHoldTimeText(GameObject player, float holdTime) // Updates the hold times of each player shown on the leaderboard
{
if (playerIcons.ContainsKey(player))
{
TextMeshProUGUI holdTimeText = playerIcons[player].GetComponentInChildren<TextMeshProUGUI>();
if (holdTimeText != null)
{
int minutes = Mathf.FloorToInt(holdTime / 60F);
int seconds = Mathf.FloorToInt(holdTime % 60F);
holdTimeText.text = string.Format("{0:0}:{1:00}", minutes, seconds);
}
}
}
}