private void SetState(OrbiterState state) { var oldState = State; State = state; WaitTime = state == OrbiterState.Idle ? 0 : GetTime(state); OnState(state); OnStateChange(oldState); }
protected override void OnStateChange(OrbiterState _) { bool firing = State == OrbiterState.Firing; if (fireBeam.enabled != firing) { fireBeam.enabled = firing; } ParticleState(chargeParticles, OrbiterState.Charging); ParticleState(fireParticles, OrbiterState.Firing); }
private void OnState(OrbiterState state) { switch (state) { case OrbiterState.Cooldown: OnCooldown(); return; case OrbiterState.Charging: OnCharge(ChargeTime); return; case OrbiterState.Firing: OnFire(FireDuration); return; case OrbiterState.Idle: OnIdle(); return; } }
private void ParticleState(ParticleSystem ps, OrbiterState playState) { bool plays = State == playState; if (plays && !ps.isPlaying) { ps.Play(); } else if (!plays && ps.isPlaying) { ps.Stop(); } }
private float GetTime(OrbiterState state) { #pragma warning disable // Convert switch statement to expression switch (state) { case OrbiterState.Cooldown: return(CooldownTime); case OrbiterState.Charging: return(ChargeTime); case OrbiterState.Firing: return(FireDuration); default: return(1); } ; #pragma warning restore }
protected virtual void OnStateChange(OrbiterState oldState) { }