using System;
using UnityEngine;
using Framework.Services;
namespace Framework.State {
/// Manages the state of the game in the current scene
[ServiceScope(Scope.Session)]
public class StateManager : Service, IStateManager {
/// Triggered when the game is being paused
public event Action Paused;
/// Triggered when the game resume from pause mode
public event Action Resumed;
/// Pauses the game
public void Pause() {
if(!this.paused) {
this.previousTimeScale = Time.timeScale;
Time.timeScale = 0.0f;
OnPaused();
this.paused = true;
}
}
/// Resumes the game
public void Resume() {
if(this.paused) {
Time.timeScale = this.previousTimeScale;
OnResumed();
this.paused = false;
}
}
/// Whether the game is currently paused
public bool IsPaused {
get { return this.paused; }
}
/// Fires the event
protected virtual void OnPaused() {
if(Paused != null) {
Paused();
}
}
/// Fires the event
protected virtual void OnResumed() {
if(Resumed != null) {
Resumed();
}
}
/// Whether the game is paused
private bool paused;
/// Time scale that was present before the game was paused
private float previousTimeScale;
}
} // namespace Framework.State