/// <summary> /// plays an Audioclip if it was not played in PROGRESS_UNTIL_NEXT_PLAY of duration /// </summary> /// <param name="clip"></param> public void PlayOnce(AudioClip clip, float volume = 1.0f) { if (clip == null) return; string type = clip.name; if (!_playedList.ContainsKey(type)) { _playedList[type] = new Timer(clip.length * PROGRESS_UNTIL_NEXT_PLAY); } else { if (_playedList[type].hasEnded) { _playedList[type].Reset(); } else { return; } } PlayWithVariation(clip, volume); }
public void Stop(Timer timer) { if (_timersInRunning.Contains(timer)) _timersInRunning.Remove(timer); if (_timersInRunningAndSequence.Contains(timer)) _timersInRunningAndSequence.Remove(timer); if (_timersForAllStates.Contains(timer)) _timersForAllStates.Remove(timer); }
void Update() { if (source != null && !source.isPlaying) { if (_timer == null) StartNewTimer(); else _timer.Update(); if (_timer.hasEnded) { _timer = null; source.Play(); } } }
// ================================================================================ // public methods // -------------------------------------------------------------------------------- public Timer GetTimer(float duration, System.Action hasEndedCallback, TimerActiveInStates activeInStates = TimerActiveInStates.RunningAndSequence) { Timer timer = new Timer(duration); callbacks[timer] = hasEndedCallback; switch (activeInStates) { case TimerActiveInStates.Running: _timersInRunning.Add(timer); break; case TimerActiveInStates.RunningAndSequence: _timersInRunningAndSequence.Add(timer); break; default: _timersForAllStates.Add(timer); break; } return timer; }
private void HideDamageDisplay() { if (_hitTimer != null) { _hitTimer = null; if (_animationController != null) _animationController.SetMaterialColor(_originalColor); } }
private void ShowDamageDisplay(float time, Color color) { _hitTimer = new Timer(time); if (_animationController != null) _animationController.SetMaterialColor(color); }
public void TakeAction(Actor2D targetActor) { if (!isAlive) return; _actionTimer = new Timer(action.cooldown); isMoving = false; // update look direction SetLookDirectionToTarget(targetActor.position2D); state = ActorState.TakingAction; action.Execute(); }
void FixedUpdate() { // do nothing when game is not running if (MainBase.Instance == null || (MainBase.Instance.state != GameState.Running && MainBase.Instance.state != GameState.Sequence)) return; // slow movement if (_rigidbody2D != null) { if (_rigidbody2D.velocity.magnitude < 0.005f) { _rigidbody2D.velocity = Vector2.zero; lookDirection = Vector2.zero; } else { _rigidbody2D.velocity = Vector2.Lerp(_rigidbody2D.velocity, Vector2.zero, Time.fixedDeltaTime * 5.0f); } } // do nothing when dead if (state == ActorState.Disabled || state == ActorState.Dead) return; // timer for hit visuals if (_hitTimer != null && isAlive) { _hitTimer.Update(); if (_hitTimer.hasEnded) { HideDamageDisplay(); } } // update target target.Update(); // update movement if (state == ActorState.Moving) { if (!target.hasTarget) { if (_lastDirectMovement != Vector2.zero && movementSpeed > 0) { Move(_lastDirectMovement); } else { isMoving = false; state = ActorState.Idle; return; } } else { MoveTowardsTarget(); } } // update action if (_actionTimer != null) { _actionTimer.Update(); if (_actionTimer.hasEnded) { state = ActorState.Idle; _actionTimer = null; } else { return; // wait for actions to finish } } // resume actions when idle if (state == ActorState.Idle && target.hasTarget //&& !(weapon.type == WeaponType.Healing && target.otherActor != null && target.otherActor.health >= target.otherActor.maxHealth) ) { state = ActorState.Moving; return; } }
public void OnStart() { _timer = new Timer(_duration); }
public void SetLoadingTimer() { _loadingTimer = new Timer(0.1f); }
protected virtual void Update() { if (state == GameState.Loading) { if (_loadingTimer != null) { _loadingTimer.Update(); } if (loadingOperation != null) { if (loadingOperation.isDone) loadingOperation = null; } if (loadingOperation == null) { loadingOperation = null; if (_loadingTimer != null) { if (_loadingTimer.hasEnded) { _loadingTimer = null; } } else { InitLevel(); } } } else { timers.Update(); } }
void StartNewTimer() { _timer = new Timer(Random.Range(pauseIntervalMin, pauseIntervalMax)); }