-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInputManager.cs
129 lines (124 loc) · 3.73 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;
public class InputManager : MonoBehaviour
{
private PlayerInput playerInput;
public PlayerInput.OnFootActions onFoot;
public PlayerInput.UIActions UI;
private PlayerMotor motor;
private PlayerLook look;
private GameObject inventoryUI;
private bool inventoryOpen;
WeaponManager weaponManager;
[SerializeField] InventoryManager inventoryManager;
// private CameraSwitch cameraSwitch;
void Awake()
{
inventoryOpen = false;
inventoryUI = GameObject.FindWithTag("InventoryUI");
inventoryUI.SetActive(false);
inventoryManager.Init();
inventoryManager.GetComponent<EquipmentManager>().Init();
// InventoryManager.instance.gameObject.SetActive(false);
playerInput = new PlayerInput();
onFoot = playerInput.OnFoot;
UI = playerInput.UI;
motor = GetComponent<PlayerMotor>();
look = GetComponent<PlayerLook>();
weaponManager = GetComponent<WeaponManager>();
// cameraSwitch = GetComponent<CameraSwitch>();
// inventoryManager = GameObject.FindWithTag("InventoryUI").GetComponent<InventoryManager>();
// inventoryManager.gameObject.GetComponent<Image>().enabled = false;
// inventoryManager.gameObject.SetActive(false);
onFoot.Movement.performed += ctx =>
{
motor.walking = true;
// motor.Walk(ctx.ReadValue<Vector2>());
};
onFoot.Movement.canceled += ctx =>
{
motor.walking = false;
// motor.Walk(Vector2.zero);
};
onFoot.Jump.performed += ctx =>
{
if (!inventoryOpen)
motor.Jump();
};
onFoot.Crouch.performed += ctx =>
{
if (!inventoryOpen)
motor.Crouch();
};
onFoot.Sprint.performed += ctx =>
{
if (!inventoryOpen)
motor.Sprint();
};
onFoot.Fire.performed += ctx =>
{
if (!inventoryOpen && WeaponEquipped())
motor.Fire();
};
onFoot.FireHold.performed += ctx =>
{
if (!inventoryOpen && WeaponEquipped())
motor.Fire();
};
onFoot.FireHold.canceled += ctx =>
{
if (!inventoryOpen && WeaponEquipped())
motor.StopFire();
};
onFoot.Reload.performed += ctx =>
{
// Debug.Log($"Input for reload");
if (!inventoryOpen && WeaponEquipped())
motor.Reload();
};
UI.OpenInventory.performed += ctx =>
{
if (!inventoryOpen)
{
look.enabled = false;
// cameraSwitch.SwitchCameras();
inventoryManager.OpenInventory();
inventoryOpen = true;
}
else
{
look.enabled = true;
// cameraSwitch.SwitchCameras();
inventoryManager.CloseInventory();
inventoryOpen = false;
}
};
}
void FixedUpdate()
{
if (!inventoryOpen)
motor.ProcessMove(onFoot.Movement.ReadValue<Vector2>());
}
void LateUpdate()
{
if (!inventoryOpen)
look.ProcessLook(onFoot.Look.ReadValue<Vector2>());
}
private void OnEnable()
{
onFoot.Enable();
UI.Enable();
}
private void OnDisable()
{
onFoot.Disable();
UI.Disable();
}
private bool WeaponEquipped()
{
return (weaponManager.GetCurrentWeapon() != null) ? true : false;
}
}