/// <summary> /// 启动计时器 /// </summary> /// <param name="timeListener"></param> /// <param name="tmpTimerID"></param> /// <param name="time"></param> /// <param name="isIgnoreTimeScale"></param> public void BeginTimer(TimerEnd timeListener, int tmpTimerID, float time, bool isIgnoreTimeScale) { if (null != timeListener && time > 0.0f) { this.timerEnd = timeListener; this.timerID = tmpTimerID; Invoke("EndTimer", time * GetTimeScale(isIgnoreTimeScale)); } }
// 시간에 상관없이 해당 버프 취소 // 버프 효과 해제, 디버프 효과 해제에 이용 가능 public void CancelBuff(int registeredNum) { var cancel = FindByRegisterNumber(registeredNum); if (cancel == null) { return; } cancel.Value.endCallback(cancel.Value.data.currentStack); TimerEnd?.Invoke(cancel.Value.key); observeList.Remove(cancel); }
// Update is called once per frame void Update() { if (gameStart) { if (seconds == increaseFreq && !freqCD) { // every X seconds, decrease the spawn delay enemySpawner.SetSpawnDelay(0.5f, 0.75f); Debug.Log("increasing spawn freq " + seconds); freqCD = true; } if (freqCD) { if (freqTimer < freqCooldown) { freqTimer += Time.deltaTime; } else if (freqTimer >= freqCooldown) { freqTimer = 0f; freqCD = false; } } if (timer < maxGameTime) { timer += Time.deltaTime; //minutes = Mathf.FloorToInt(timer / 60); seconds = Mathf.FloorToInt(timer % 60); } else if (timer >= maxGameTime) { // event added from Enemy.cs gameWon = true; TimerEnd?.Invoke(); gameStart = false; enemySpawner.StopEnemySpawn(); } } if (gameWon && !PlayerManager.death) { endText.SetActive(true); enemiesKilled.text = Enemy.enemiesDead.ToString(); enemiesKilled2.text = Enemy.enemiesDead.ToString(); gameWon = false; } }
protected override void TimerHandler(object sender, EventArgs e) { if (Timering != null) { Timering.Invoke(this); } if (_time == DateTime.Now) { if (TimerEnd != null) { TimerEnd.Invoke(this); } Close(); } }
IEnumerator Countdown(int ID, int sec, TimerEverySec EverySecFunction, TimerEnd EndFunction) { if ((bool)TimerList[ID] == true) { yield return(null); } TimerList[ID] = sec; while (sec > 0) { yield return(new WaitForSeconds(1)); sec--; TimerList[ID] = sec; EverySecFunction(); } EndFunction(); TimerList[ID] = true; }
/// <summary> /// Crée un nouveau Timer /// </summary> /// <param name="endTime">Temps de fin du chrono</param> /// <param name="function">Fonction déclanché à la fin du timer.</param> /// <param name="isAlreadyFinished">Le timer doit-il être fini tout de suite?</param> public Timer(float endTime, TimerEnd function, bool isAlreadyFinished) : this(endTime, isAlreadyFinished) { OnTimerEnd += function; }
/// <summary> /// Crée un nouveau Timer /// </summary> /// <param name="endTime">Temps de fin du chrono</param> /// <param name="function">Fonction déclanché à la fin du timer.</param> public Timer(float endTime, TimerEnd function) : this(endTime){ OnTimerEnd += function; }
/// <summary> /// Retire une fonction de ce timer. /// </summary> /// <param name="oldFunction">Fonction à retirer.</param> public void RemoveFunction(TimerEnd oldFunction) { OnTimerEnd -= oldFunction; }
/// <summary> /// Ajoute une fonction au timer /// </summary> /// <param name="newFunction">Nouvelle fonction à ajouter.</param> public void AddFunction(TimerEnd newFunction) { OnTimerEnd += newFunction; }
public static void UnsubscribeAllSubscriber() { if (NextPhase != null) { System.Delegate[] delegates = NextPhase.GetInvocationList(); for (int i = 0; i < delegates.Length; i++) { NextPhase -= delegates [i] as NextPhaseEvent; } } if (AllowCurrentPlayerToMove != null) { System.Delegate[] delegates = AllowCurrentPlayerToMove.GetInvocationList(); for (int i = 0; i < delegates.Length; i++) { AllowCurrentPlayerToMove -= delegates [i] as AllowCurrentPlayerToMoveEvent; } } if (DisallowCurrentPlayerToMove != null) { System.Delegate[] delegates = DisallowCurrentPlayerToMove.GetInvocationList(); for (int i = 0; i < delegates.Length; i++) { DisallowCurrentPlayerToMove -= delegates [i] as DisallowCurrentPlayerToMoveEvent; } } if (AllowCurrentPlayerToFire != null) { System.Delegate[] delegates = AllowCurrentPlayerToFire.GetInvocationList(); for (int i = 0; i < delegates.Length; i++) { AllowCurrentPlayerToFire -= delegates [i] as AllowCurrentPlayerToFireEvent; } } if (DisallowCurrentPlayerToFire != null) { System.Delegate[] delegates = DisallowCurrentPlayerToFire.GetInvocationList(); for (int i = 0; i < delegates.Length; i++) { DisallowCurrentPlayerToFire -= delegates [i] as DisallowCurrentPlayerToFireEvent; } } if (NextPlayer != null) { System.Delegate[] delegates = NextPlayer.GetInvocationList(); for (int i = 0; i < delegates.Length; i++) { NextPlayer -= delegates [i] as NextPlayerEvent; } } if (PlayerDead != null) { System.Delegate[] delegates = PlayerDead.GetInvocationList(); for (int i = 0; i < delegates.Length; i++) { PlayerDead -= delegates [i] as PlayerDeadEvent; } } if (PlayerWon != null) { System.Delegate[] delegates = PlayerWon.GetInvocationList(); for (int i = 0; i < delegates.Length; i++) { PlayerWon -= delegates [i] as PlayerWonEvent; } } if (TimerEnd != null) { System.Delegate[] delegates = TimerEnd.GetInvocationList(); for (int i = 0; i < delegates.Length; i++) { TimerEnd -= delegates [i] as TimerEndEvent; } } if (PlayerCast != null) { System.Delegate[] delegates = PlayerCast.GetInvocationList(); for (int i = 0; i < delegates.Length; i++) { PlayerCast -= delegates [i] as PlayerCastEvent; } } if (SpellEnd != null) { System.Delegate[] delegates = SpellEnd.GetInvocationList(); for (int i = 0; i < delegates.Length; i++) { SpellEnd -= delegates [i] as SpellEndEvent; } } if (NextPlayerButtonClick != null) { System.Delegate[] delegates = NextPlayerButtonClick.GetInvocationList(); for (int i = 0; i < delegates.Length; i++) { NextPlayerButtonClick -= delegates [i] as NextPlayerButtonClickEvent; } } }
/// <summary> /// 每秒执行函数的倒计时 /// </summary> /// <param name="seconds">倒计时秒数</param> /// <param name="EverySecFunction">每秒调用的函数</param> /// <param name="EndFunction">倒计时为0时 执行的函数</param> public void StartCountdown_EverysecRun(int seconds, TimerEverySec EverySecFunction, TimerEnd EndFunction) { int TimerID = TimerList.Add(false); StartCoroutine(Countdown(TimerID, seconds, EverySecFunction, EndFunction)); }
/// <summary> /// 倒计时 /// </summary> /// <param name="seconds">倒计时秒数</param> /// <param name="EndFunction">倒计时为0时 执行的函数</param> public void StartCountdown(int seconds, TimerEnd EndFunction) { int TimerID = TimerList.Add(false); StartCoroutine(Countdown(TimerID, seconds, () => { }, EndFunction)); }