ScoreboardElementGO
Scoreboard UI element.unknown
csharp
2 years ago
3.4 kB
6
Indexable
using TMPro; using Photon.Pun; using UnityEngine; using UnityEngine.UI; public class ScoreboardElementGO : MonoBehaviour { public bool endOfGameElement; [Header("Images")] [SerializeField] Image background_image; [SerializeField] Image humanPlayer_image; [Header("Colors")] [SerializeField] Color localClient_color; [SerializeField] Color ally_color; [SerializeField] Color enemy_color; [SerializeField] Color goodPing_color; [SerializeField] Color mediumPing_color; [SerializeField] Color badPing_color; [Header("Text")] [SerializeField] TMP_Text Nickname_text; [SerializeField] TMP_Text Kills_text; [SerializeField] TMP_Text Deaths_text; [SerializeField] TMP_Text Level_text; [SerializeField] TMP_Text Ping_text; [Header("Buttons")] public Button ban_button; public bool setup; // PRIVATE VARS PlayerBotScoreboardData _playerBotStatistics; // PRIVATE VARS public void Reset() { name = "Null"; _playerBotStatistics = null; setup = false; if (!endOfGameElement) ban_button.onClick.RemoveAllListeners(); } public void SetupSlot(PlayerBotScoreboardData p_playerBotStatistics) { _playerBotStatistics = p_playerBotStatistics; name = _playerBotStatistics.nickname; Nickname_text.text = _playerBotStatistics.nickname; Kills_text.text = _playerBotStatistics.kills.ToString(); Deaths_text.text = _playerBotStatistics.deaths.ToString(); Level_text.text = _playerBotStatistics.level.ToString(); if (!endOfGameElement) Ping_text.text = _playerBotStatistics.ping + "ms"; if (_playerBotStatistics.localClient) { Nickname_text.fontStyle = FontStyles.Bold; SetAllTextsColor(Color.black); background_image.color = localClient_color; humanPlayer_image.color = Color.black; } else { Nickname_text.fontStyle = FontStyles.Normal; SetAllTextsColor(Color.white); humanPlayer_image.color = Color.white; if (_playerBotStatistics.team == LocalClient.team) background_image.color = ally_color; else background_image.color = enemy_color; } humanPlayer_image.gameObject.SetActive(!_playerBotStatistics.AI); if (!endOfGameElement) { ban_button.gameObject.SetActive(!_playerBotStatistics.AI); ban_button.interactable = !_playerBotStatistics.AI && !_playerBotStatistics.localClient; ban_button.targetGraphic.color = ban_button.interactable ? Color.white : new Color(1, 1, 1, 0); } if (!gameObject.activeSelf) gameObject.SetActive(true); setup = true; } void SetAllTextsColor(Color p_color) { Nickname_text.color = p_color; Kills_text.color = p_color; Deaths_text.color = p_color; Level_text.color = p_color; SetPingTextColor(); } void SetPingTextColor() { if (endOfGameElement) return; if (_playerBotStatistics.ping >= 300) Ping_text.color = badPing_color; else if (_playerBotStatistics.ping >= 100) Ping_text.color = mediumPing_color; else if (_playerBotStatistics.ping < 100) Ping_text.color = _playerBotStatistics.localClient ? Color.black : Color.white; } }
Editor is loading...