-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInput.js
More file actions
60 lines (48 loc) · 1.79 KB
/
Input.js
File metadata and controls
60 lines (48 loc) · 1.79 KB
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
// Please carefully review the rules about academic integrity found in the academicIntegrity.md file found at the root of this project.
/**
* Static class that manages keyboard and mouse input in our engine.
*
* See https://docs.unity3d.com/ScriptReference/Input.html
*/
class Input {
static keysDown = []
static keysDownThisFrame = []
static keysUpThisFrame = []
static mousePosition
static mousePositionLastFrame
static mousePositionDelta
static mouseButtonsDown = []
static mouseButtonsDownThisFrame = []
static mouseButtonsUpThisFrame = []
static keyDown(event) {
if (!Input.keysDown.includes(event.code)) {
Input.keysDown.push(event.code)
Input.keysDownThisFrame.push(event.code)
}
}
static keyUp(event) {
Input.keysDown = Input.keysDown.filter(key => key != event.code)
Input.keysUpThisFrame.push(event.code)
}
static mouseDown(event) {
Input.mouseButtonsDown.push(event.button)
Input.mouseButtonsDownThisFrame.push(event.button)
}
static mouseUp(event) {
Input.mouseButtonsDown = Input.mouseButtonsDown.filter(button => button != event.button)
Input.mouseButtonsUpThisFrame.push(event.button)
}
static mouseMove(event) {
Input.mousePosition = new Vector2(event.clientX, event.clientY)
}
static update() {
Input.keysDownThisFrame = []
Input.keysUpThisFrame = []
Input.mouseButtonsDownThisFrame = []
Input.mouseButtonsUpThisFrame = []
if (Input.mousePosition && Input.mousePositionLastFrame)
Input.mousePositionDelta = Input.mousePosition.minus(Input.mousePositionLastFrame)
if (Input.mousePosition)
Input.mousePositionLastFrame = Input.mousePosition.clone()
}
}