-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUIController.cs
111 lines (95 loc) · 2.77 KB
/
UIController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using TMPro;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// Controls a very simple UI. Doesn't do anything on its own.
/// </summary>
public class UIController : MonoBehaviour
{
[Tooltip("The ice progress bar for the player")]
public Slider playerIceBar;
[Tooltip("The ice progress bar for the opponent")]
public Slider opponentIceBar;
[Tooltip("The timer text")]
public TextMeshProUGUI timerText;
[Tooltip("The banner text")]
public TextMeshProUGUI bannerText;
[Tooltip("The button")]
public Button button;
[Tooltip("The button text")]
public TextMeshProUGUI buttonText;
/// <summary>
/// Delegate for a button click
/// </summary>
public delegate void ButtonClick();
/// <summary>
/// Called when the button is clicked
/// </summary>
public ButtonClick OnButtonClicked;
/// <summary>
/// Responds to button clicks
/// </summary>
public void ButtonClicked()
{
if (OnButtonClicked != null) OnButtonClicked();
}
/// <summary>
/// Shows the button
/// </summary>
/// <param name="text">The text string on the button</param>
public void ShowButton(string text)
{
buttonText.text = text;
button.gameObject.SetActive(true);
}
/// <summary>
/// Hides the button
/// </summary>
public void HideButton()
{
button.gameObject.SetActive(false);
}
/// <summary>
/// Shows banner text
/// </summary>
/// <param name="text">The text string to show</param>
public void ShowBanner(string text)
{
bannerText.text = text;
bannerText.gameObject.SetActive(true);
}
/// <summary>
/// Hides the banner text
/// </summary>
public void HideBanner()
{
bannerText.gameObject.SetActive(false);
}
/// <summary>
/// Sets the timer, if timeRemaining is negative, hides the text
/// </summary>
/// <param name="timeRemaining">The time remaining in seconds</param>
public void SetTimer(float timeRemaining)
{
if (timeRemaining > 0f)
timerText.text = timeRemaining.ToString("00");
else
timerText.text = "";
}
/// <summary>
/// Sets the player's ice amount
/// </summary>
/// <param name="iceAmount">An amount between 0 and 1</param>
public void SetPlayerIce(float iceAmount)
{
playerIceBar.value = iceAmount;
}
/// <summary>
/// Sets the opponent's ice amount
/// </summary>
/// <param name="iceAmount">An amount between 0 and 1</param>
public void SetOpponentIce(float iceAmount)
{
opponentIceBar.value = iceAmount;
}
}