/
PInput.cs
95 lines (75 loc) · 2.06 KB
/
PInput.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
using UnityEngine;
using System;
using System.Collections;
using Gamekit3D;
public class PInput : MonoBehaviour
{
public static PInput Instance
{
get { return s_Instance; }
}
protected static PInput s_Instance;
[HideInInspector]
public bool playerControllerInputBlocked;
protected Vector2 m_Movement;
protected Vector2 m_Camera;
protected bool m_Jump;
protected bool m_Pause;
protected bool m_ExternalInputBlocked;
public Vector2 MoveInput
{
get
{
if (playerControllerInputBlocked || m_ExternalInputBlocked)
return Vector2.zero;
return m_Movement;
}
}
public Vector2 CameraInput
{
get
{
if (playerControllerInputBlocked || m_ExternalInputBlocked)
return Vector2.zero;
return m_Camera;
}
}
public bool JumpInput
{
get { return m_Jump && !playerControllerInputBlocked && !m_ExternalInputBlocked; }
}
public bool Pause
{
get { return m_Pause; }
}
WaitForSeconds m_AttackInputWait;
Coroutine m_AttackWaitCoroutine;
const float k_AttackInputDuration = 0.03f;
void Awake()
{
m_AttackInputWait = new WaitForSeconds(k_AttackInputDuration);
if (s_Instance == null)
s_Instance = this;
else if (s_Instance != this)
throw new UnityException("There cannot be more than one PlayerInput script. The instances are " + s_Instance.name + " and " + name + ".");
}
void Update()
{
m_Movement.Set(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
m_Camera.Set(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
m_Jump = Input.GetButton("Jump");
m_Pause = Input.GetButtonDown("Pause");
}
public bool HaveControl()
{
return !m_ExternalInputBlocked;
}
public void ReleaseControl()
{
m_ExternalInputBlocked = true;
}
public void GainControl()
{
m_ExternalInputBlocked = false;
}
}