/// <summary>
 /// Checks if an hour has passed and invokes the delegate
 /// </summary>
 private void CheckAndInvokeHour()
 {
     if (GameTime.Hour != lastHour)
     {
         lastHour = GameTime.Hour;
         if (onHourChangedCallback != null)
         {
             onHourChangedCallback.Invoke();
         }
     }
 }
Exemple #2
0
        protected override void OnUpdate()
        {
            DeltaTime    = Time.DeltaTime * TimeSpeed;
            ElapsedTime += DeltaTime;

            Second += DeltaTime;
            if (Second >= TimeInHour)
            {
                Hour   += 1;
                Second -= TimeInHour;
                if (Hour < HoursInDay)
                {
                    OnHourChanged?.Invoke(Hour);
                }
            }
            if (Hour >= HoursInDay)
            {
                Day  += 1;
                Hour -= HoursInDay;
                OnHourChanged?.Invoke(Hour);

                if (Day < DaysInMonth)
                {
                    OnDayChanged?.Invoke(Day);
                }
            }
            if (Day >= DaysInMonth)
            {
                Month += 1;
                Day   -= DaysInMonth;
                OnDayChanged?.Invoke(Day);

                if (Month < MonthsInYear)
                {
                    OnMonthChanged?.Invoke(Month);
                }
            }
            if (Month >= MonthsInYear)
            {
                Year  += 1;
                Month -= MonthsInYear;
                OnMonthChanged?.Invoke(Month);
                OnYearChanged?.Invoke(Year);
            }

            Entities
            .WithName("MyTimeManager")
            .ForEach((Entity entity,
                      ref MyTimeTag timeData) =>
            {
                //timeData.ElapsedTime = ElapsedTime;
                //just have a default timetag to force update.
            }).ScheduleParallel();
        }
Exemple #3
0
 public void Update(float deltaTime)
 {
     if (_timer >= _daySettingsDatabase.HourLength)
     {
         _timer = 0f;
         _dayModel.Hours++;
         OnHourChanged?.Invoke();
     }
     else
     {
         _timer += deltaTime;
     }
 }
    IEnumerator UpdateTime(float interval)
    {
        while (true)
        {
            yield return(new WaitForSeconds(interval));

            _second += 30;

            if (_second >= 60)
            {
                _minute++;
                _minText.text = _minute.ToString("D2");
                _second       = 0;
            }

            if (_minute >= 60)
            {
                _hour++;
                _minute = 0;
                if (onHourChangedCallback != null)
                {
                    onHourChangedCallback.Invoke();
                }

                if (_hour == 24)
                {
                    _hour = 0;
                }

                if (_hour >= 12)
                {
                    _meridiem.text = "PM";
                    _hourText.text = (_hour - 12).ToString("D2") + " : ";
                }
                else
                {
                    _meridiem.text = "AM";
                    _hourText.text = _hour.ToString("D2") + " : ";
                }
            }
        }
    }