A 2D Farming RPG
This is just a simple 2D farming RPG game
Loading...
Searching...
No Matches
GameClock.cs
Go to the documentation of this file.
1using TMPro;
2using UnityEngine;
3
4public class GameClock : MonoBehaviour
5{
6 [SerializeField] private TextMeshProUGUI m_TimeText = null;
7 [SerializeField] private TextMeshProUGUI m_DateText = null;
8 [SerializeField] private TextMeshProUGUI m_SeasonText = null;
9 [SerializeField] private TextMeshProUGUI m_YearText = null;
10
14 private void OnEnable()
15 {
16 EventHandler.AdvanceGameMinuteEvent += UpdateGameTime;
17 }
18
22 private void OnDisable()
23 {
24 EventHandler.AdvanceGameMinuteEvent -= UpdateGameTime;
25 }
26
37 private void UpdateGameTime( int gameYear, Season gameSeason, int gameDay, string gameDayOfWeek, int gameHour, int gameMinute, int gameSecond )
38 {
39 // Update Time
40
41 gameMinute = gameMinute - ( gameMinute % 10 );
42
43 string ampm = "";
44 string minute;
45
46 if( gameHour >= 12 )
47 {
48 ampm = " pm";
49 }
50 else
51 {
52 ampm = " am";
53 }
54
55 if( gameHour >= 13 )
56 {
57 gameHour -= 12;
58 }
59
60 if( gameMinute < 10 )
61 {
62 minute = "0" + gameMinute.ToString();
63 }
64 else
65 {
66 minute = gameMinute.ToString();
67 }
68
69 string time = gameHour.ToString() + " : " + minute + ampm;
70
71 m_TimeText.SetText( time );
72 m_DateText.SetText( gameDayOfWeek + ". " + gameDay.ToString());
73 m_SeasonText.SetText( gameSeason.ToString() );
74 m_YearText.SetText( "Year " + gameYear );
75 }
76}
Season
Used for time mechanism
Definition: Enums.cs:128
void OnDisable()
Unsubscribe from the AdvanceGameMinuteEvent
Definition: GameClock.cs:22
TextMeshProUGUI m_TimeText
Definition: GameClock.cs:6
void UpdateGameTime(int gameYear, Season gameSeason, int gameDay, string gameDayOfWeek, int gameHour, int gameMinute, int gameSecond)
Update UI game time
Definition: GameClock.cs:37
void OnEnable()
Subscribe to the AdvanceGameMinuteEvent
Definition: GameClock.cs:14
TextMeshProUGUI m_SeasonText
Definition: GameClock.cs:8
TextMeshProUGUI m_YearText
Definition: GameClock.cs:9
TextMeshProUGUI m_DateText
Definition: GameClock.cs:7