JamesMakesGames

InputManager

May 27th, 2022
1,491
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. public class InputManager
  2. {
  3.     // Controls is the C# class generated by the Input System
  4.     private Controls _controls;
  5.  
  6.     private InputManager()
  7.     {
  8.         _controls = new Controls();
  9.         GameStateManager.Instance.OnGameStateChanged += OnGameStateChanged;
  10.         OnGameStateChanged(GameStateManager.Instance.CurrentGameState);
  11.     }
  12.        
  13.     ~InputManager()
  14.     {
  15.         GameStateManager.Instance.OnGameStateChanged -= OnGameStateChanged;
  16.     }
  17.  
  18.  
  19.     private void OnGameStateChanged(GameState newGameState)
  20.     {
  21.         // Disable all controls
  22.         _controls.Gameplay.Disable();
  23.         _controls.Paused.Disable();
  24.  
  25.         // Enable certain controls based on new game state
  26.         switch (newGameState)
  27.         {
  28.             case GameState.Gameplay:
  29.                 _controls.Gameplay.Enable();
  30.                 break;
  31.             case GameState.Paused:
  32.                 _controls.Paused.Enable();
  33.                 break;
  34.             default:
  35.                 break;
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment