RealTime
Coding Style wiki
RealTime is a static utility that records the application startup time. The main program (a Main MonoBehaviour Awake) calls InitStartupTime() to initialize it (only the first call takes effect); afterwards the startup time can be read from timeSinceStartup, serving as a global game startup time base.
| Namespace | OxGKit.TimeSystem |
| Type | public static class RealTime |
| Source | RealTime.cs |
using OxGKit.TimeSystem;
Quick Start
using OxGKit.TimeSystem;
using UnityEngine;
public class Main : MonoBehaviour
{
private void Awake()
{
// Initialized by the main program at startup (first call only)
RealTime.InitStartupTime();
}
private void Start()
{
if (RealTime.IsInitStartupTime())
{
// Read the game startup time
System.DateTime startup = RealTime.timeSinceStartup;
}
}
}
Reminder Call InitStartupTime() at main program startup so the recorded value is the actual game startup time.
Members
| Member | Description |
|---|---|
public static DateTime timeSinceStartup { get; } | The application startup time (system time recorded by InitStartupTime). |
Methods
Method Overview
| Method | Description |
|---|---|
| InitStartupTime | Initializes the startup time (first call only). |
| IsInitStartupTime | Checks whether the startup time has been initialized. |
InitStartupTime
public static void InitStartupTime()
Records the current system time (DateTime.Now) as the startup time; only the first call takes effect — subsequent calls are ignored.
IsInitStartupTime
public static bool IsInitStartupTime()
Checks whether the startup time has been initialized; if not, a log hint is printed (Please call RealTime.InitStartupTime() in main program first) and false is returned.