You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using SiegeSong;
namespace SiegeSong
{
public class Calendar : MonoBehaviour
{
public int Minute;
public int Hour;
public int Day;
public int WeekDay;
public int Month;
public int Year;
private int daysInWeek = 7;
private int daysInMonth = 28;
public void SetDateTime(Calendar newDateTime)
{
EnviroSky.instance.GameTime.Minutes = newDateTime.Minute;
EnviroSky.instance.GameTime.Hours = newDateTime.Hour;
EnviroSky.instance.GameTime.Days = newDateTime.Day;
EnviroSky.instance.GameTime.Years = newDateTime.Year;
}
public void SetDateTime(int minute, int hour, int day, int year)
{
EnviroSky.instance.GameTime.Minutes = minute;
EnviroSky.instance.GameTime.Hours = hour;
EnviroSky.instance.GameTime.Days = day;
EnviroSky.instance.GameTime.Years = year;
}
// Logic to be executed at the start of every hour
public void HourlyUpdate()
{
if (EnviroSky.instance.GameTime.Hours < Hour)
DailyUpdate();
Hour = EnviroSky.instance.GameTime.Hours;
}
// Logic to be executed at the start of every day
public void DailyUpdate()
{
Day = EnviroSky.instance.GameTime.Days;
if (WeekDay < daysInWeek)
WeekDay++;
else
WeekDay = 0;
if (Day % daysInMonth == 0)
Month++;
if (Year != EnviroSky.instance.GameTime.Years)
YearlyUpdate();
}
// Logic to be executed at the start of every year
public void YearlyUpdate()
{
Month = 0;
Year = EnviroSky.instance.GameTime.Years;
}
void Start()
{
}
void Update()
{
Minute = EnviroSky.instance.GameTime.Minutes;
if (EnviroSky.instance.GameTime.Hours != Hour)
HourlyUpdate();
}
}
}