Game.Simulation.ITimeSystem
Assembly: Assembly-CSharp (runtime game assembly)
Namespace: Game.Simulation
Type: interface
Base: None (interface)
Summary:
ITimeSystem is a simple read-only interface that exposes the game's high-level time information used by simulation and UI code. It provides the current year, the number of days per year, and two normalized values for time-of-day and date-within-year so consumers can drive animations, schedules, or time-dependent logic without needing to know internal time representation details.
Fields
- This interface declares no fields.
Implementations may store internal state (fields) but none are specified here.
Properties
-
int daysPerYear { get; }
Returns the number of in-game days that make up a single year. Use this to convert between day indices and normalizedDate or to compute calendar-based logic. -
float normalizedTime { get; }
A normalized representation of the current time-of-day, typically in the range [0, 1). 0 corresponds to the start of a day and values progress through the day; implementations usually wrap/reset after reaching 1. Use this to drive day/night cycles, lighting, or time-of-day UI elements. -
float normalizedDate { get; }
A normalized representation of the current position within the current year, typically in the range [0, 1). 0 corresponds to the start of the year and values increase through the year. Use this for season progress, yearly events, or to interpolate seasonal effects. -
int year { get; }
The current in-game year (an integer count). Use this for calendar displays, logging, or logic that depends on absolute year number.
Constructors
- Interfaces do not declare constructors.
Concrete implementations of ITimeSystem will provide constructors as appropriate.
Methods
- This interface declares no methods, only read-only properties.
Accessors for the properties above are used to query time state.
Usage Example
// Example implementation of ITimeSystem for a mod or custom simulation layer.
public class SimpleTimeSystem : ITimeSystem
{
private int m_DaysPerYear;
private int m_CurrentDayOfYear;
private int m_Year;
private float m_NormalizedTime; // 0..1 within a day
public SimpleTimeSystem(int daysPerYear)
{
m_DaysPerYear = Math.Max(1, daysPerYear);
m_CurrentDayOfYear = 0;
m_Year = 1;
m_NormalizedTime = 0f;
}
public int daysPerYear => m_DaysPerYear;
public float normalizedTime => m_NormalizedTime;
public float normalizedDate => (float)m_CurrentDayOfYear / m_DaysPerYear;
public int year => m_Year;
// Call every simulation tick to advance time (example).
public void Advance(float deltaDayFraction)
{
m_NormalizedTime += deltaDayFraction;
if (m_NormalizedTime >= 1f)
{
m_NormalizedTime -= 1f;
m_CurrentDayOfYear++;
if (m_CurrentDayOfYear >= m_DaysPerYear)
{
m_CurrentDayOfYear = 0;
m_Year++;
}
}
}
}
// Example consumer:
public void UpdateUI(ITimeSystem timeSystem)
{
// Display simple text:
string dateText = $"Year {timeSystem.year}, day {Mathf.FloorToInt(timeSystem.normalizedDate * timeSystem.daysPerYear) + 1}";
float dayProgress = timeSystem.normalizedTime;
// Use dayProgress to update sun position, lighting, or progress bars.
}
Notes: - Ranges for normalizedTime and normalizedDate are implementation-dependent but are typically 0..1 (inclusive of 0, exclusive or inclusive of 1 depending on wrap behavior). Check the concrete implementation you work with if exact bounds matter. - This interface is read-only; to change simulation time you must use or implement a mutable time system provided by the game or a mod API.