public SEvent(voidEvent ev, float delay, int repeatNum) { this.callBack = ev; this.delay = delay; this.repeatNum = repeatNum; beginTime = Time.realtimeSinceStartup; }
void Awake() { Toolbox.RegisterComponent <GameMaster> (this); myAudioSource = gameObject.GetComponent <AudioSource>(); myAudioSource.Play(); InitiateStory += BeginStory; }
private IEnumerator callDelay(voidEvent ev, float t) { yield return(new WaitForSeconds(t)); if (ev != null) { ev(); _allEvents.Remove(ev); ev = null; } }
//use update, not affect by time scale public void setTimer(voidEvent ev, float delay, int repeatNum = 1, bool startNow = false) { if (startNow) { ev(); repeatNum--; } if (repeatNum > 0) { SEvent sEv = new SEvent(ev, delay, repeatNum); _allTimers.Add(sEv); } }
//use corountine, affect by time.scale public void delayCall(voidEvent ev, float t) { StartCoroutine(callDelay(ev, t)); _allEvents.Add(ev); }