using System.Collections; using System.Collections.Generic; using UnityEngine; namespace YKMoon { public class SecondsUpdater : IUpdater { private event System.Action updateEvent; private int lastSeconds = 0; /// /// Register update event to this updater. /// /// float deltaTime (newSeconds - lastSeconds). Maybe greater than 1. public void Reg(System.Action updateEvent) { this.updateEvent += updateEvent; } /// /// Unregister update event in this updater. /// /// public void UnReg(System.Action updateEvent) { this.updateEvent -= updateEvent; } public void Update(float deltaTime, float unscaledDeltaTime) { int sec = GerCurrentSeconds(); if(lastSeconds != sec) { updateEvent?.Invoke(sec - lastSeconds); lastSeconds = sec; } } public void Clear() { updateEvent = null; } private int GerCurrentSeconds() { return (int)Time.unscaledTime; } } }