-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathWorldClock.cs
More file actions
35 lines (32 loc) · 1.28 KB
/
WorldClock.cs
File metadata and controls
35 lines (32 loc) · 1.28 KB
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
using UnityEngine;
namespace AlweStats {
public static class WorldClock {
private static Block clockBlock = null;
public static Block Start() {
clockBlock = new Block(
"WorldClock",
Main.worldClockColor.Value,
Main.worldClockSize.Value,
Main.worldClockPosition.Value,
Main.worldClockMargin.Value
);
return clockBlock;
}
public static void Update() {
EnvMan envMan = EnvMan.instance;
if (clockBlock != null && envMan) {
string format12h = "";
float minuteFraction = Mathf.Lerp(0f, 24f, envMan.GetDayFraction());
float floor24h = Mathf.Floor(minuteFraction);
int hours = Mathf.FloorToInt(floor24h);
int minutes = Mathf.FloorToInt(Mathf.Lerp(0f, 60f, minuteFraction - floor24h));
if (Main.worldClockFormat.Value) {
format12h = hours < 12 ? "AM" : "PM";
if (hours > 12) hours -= 12;
}
string gameClock = $"{(hours < 10 ? "0" : "")}{hours}:{(minutes < 10 ? "0" : "")}{minutes} {format12h}";
clockBlock.SetText(gameClock);
}
}
}
}