Gametime

v3.0
Gametime is a fairly simple module intended to help you set up custom calendars, keep track of time, and display times.

_gametime Value

The private int _gametime keeps track of each minute in the game, starting from the first minute of the first hour of the first day of the first month. The startingYear value is added when displaying FullDate() strings.
The first time the script is run, the starting values for minutes, hours, days, and months will be computed so that _gametime is set properly.

Setup

Add Gametime to one of your existing classes which gets serialized when saving if applicable.
using InfinityPBR.Modules.Gametime;
​
public class GametimeDemo : MonoBehaviour
{
public Gametime gametime;
void Update()
{
gametime.Tick(); // Call this from Update to ensure time increases
}
void OnValidate()
{
gametime.OnValidate();
}
}
Tick() must be called from your Update() loop or time will not progress!

Inspector

There are a variety of setup and other options you can adjust in the Inspector.
PauseLevel refers to various levels for various types of pause, as you may wish to have a time-pause that doesn't pause everything in the game. See the note about this in the gametime.cs script.
Time options has display settings, and control settings for how many minutes per hour, etc. "Seconds per Game Minute" is important, as this determines how fast the clock in the game runs. Set to 3, it means that one in-game minute will pass every 3 real-world seconds. Beyond this, all values refer to in-game time.
Starting Time lets you set the start date for the calendar, and Calendar Names will let you name the days of the week, months, and the seasons.
The number of days per week and the number of months per year, which determines the number of days per year, is based on the number of names added to these lists.

Methods

Now(bool includeSubtime = true) This will return the current gametime, optionally excluding the subtime, which is the time counter between in-game minutes. GameTime() is the same as calling Now(false).
GameTimePerYear() GameTimePerMonth() GameTimePerDay() GameTimePerHour() will return the number of in-game minutes for each of these time periods.
DayName(int gameTime = -1) will return the day of the week on the provided gameTime value.
MonthName(int gameTime = -1) will return the month name for the provided gameTime value.
SeasonName(int gameTime = -1) will return the season name for the provided gameTime value.
Minute() Hour() Day() Month() Year() will return the current values for these time selections.
FullDate() is the method used to display the full date, given a provided gameTime. If no gameTime is provided, it will use the current gameTime. There are other optional parameters to customize how the date is displayed. Check the script for more details.
// ADD METHODS
AddMinutes(15); // Adds 15 in-game minutes
AddHours(8); // Adds 8 in-game hours
AddDays(3); // Adds 3 in-game days
AddWeeks(1); // Adds 1 in-game week
AddMonths(2); // Adds 2 in-game months
AddYears(10); // Adds 10 in-game years
AddSeasons(1); // Adds the number of in-game days in one in-game season