-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathInputManager.cs
53 lines (43 loc) · 1.67 KB
/
InputManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using UnityEngine;
public class InputManager : MonoBehaviour
{
private GameplayInputHandler gameplayHandler;
private UIInputHandler uiHandler;
private CutsceneInputHandler cutsceneHandler;
private DialogInputHandler dialogHandler;
private InputState currentState = InputState.Gameplay;
void Start()
{
// Initialize handlers
gameplayHandler = gameObject.AddComponent<GameplayInputHandler>();
uiHandler = gameObject.AddComponent<UIInputHandler>();
cutsceneHandler = gameObject.AddComponent<CutsceneInputHandler>();
dialogHandler = gameObject.AddComponent<DialogInputHandler>();
// Set up the chain
gameplayHandler.SetNextHandler(uiHandler);
uiHandler.SetNextHandler(cutsceneHandler);
cutsceneHandler.SetNextHandler(dialogHandler);
// Set initial state
SetGameState(InputState.Gameplay);
}
void Update()
{
// Gather input
Vector2 movement = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
bool jumpPressed = Input.GetButtonDown("Jump");
bool interactPressed = Input.GetButtonDown("Interact");
// Create input data
var inputData = new InputData(movement, jumpPressed, interactPressed);
// Process input through chain
gameplayHandler.HandleInput(inputData);
}
public void SetGameState(InputState newState)
{
currentState = newState;
// Update all handlers with new state
gameplayHandler.SetState(newState);
uiHandler.SetState(newState);
cutsceneHandler.SetState(newState);
dialogHandler.SetState(newState);
}
}