VladimirPirozhenko 6999e84b65 Added pause and pause view, added restriction of input while in paused state
Upgraded Input system to fit demands of paused game (no movement inputs allowed!)
2022-08-12 05:38:17 +03:00

58 lines
1.6 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class GameSession : MonoBehaviour,IResettable
{
private InputTranslator<KeyBinding> InputTranslator;
public static GameSession Instance { get; private set; }
[SerializeField] private Player currentPlayer;
private void Awake()
{
Instance = this;
Init();
}
private void Update()
{
InputTranslator.Tick();
}
private void Init()
{
InputTranslator = new InputTranslator<KeyBinding>();
IBindingHolder<KeyBinding> holder = new KeyBindingHolder();
InputTranslator.Init(holder);
}
public void AddCommandTranslator(ICommandTranslator translator)
{
InputTranslator.AddCommandTranslator(translator);
}
public void PauseSession(bool isPaused)
{
Time.timeScale = isPaused ? 0 : 1;
List<ECommand> commands = new List<ECommand>();
ECommand[] commandRange = { ECommand.LEFT,ECommand.RIGHT,ECommand.UP,ECommand.DOWN,ECommand.SHOOT};
commands.AddRange(commandRange);
InputTranslator.RestictTranslation(commands,isPaused);
}
public void RestartSession()
{
SceneManager.LoadScene("GameScene", LoadSceneMode.Single);
ResetToDefault();
}
public void GoToMainMenu()
{
SceneManager.LoadScene("MainMenu", LoadSceneMode.Single);
ResetToDefault();
}
public void ResetToDefault()
{
PauseSession(false);
currentPlayer.ResetToDefault();
}
}