Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
gadig
Birb
Commits
66003e68
Commit
66003e68
authored
Feb 09, 2017
by
Tanner Grehawick
Browse files
add GetButtonPressed and GetButtonReleased
parent
8d13b79d
Changes
4
Show whitespace changes
Inline
Side-by-side
Assets/Scripts/Birb.meta
0 → 100644
View file @
66003e68
fileFormatVersion: 2
guid: 2057902e730664aacbc88367b9c3b892
folderAsset: yes
timeCreated: 1486687237
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
Assets/Scripts/Player/InputManager.cs
View file @
66003e68
...
@@ -41,7 +41,7 @@ public class InputAxisState{
...
@@ -41,7 +41,7 @@ public class InputAxisState{
}
}
}
}
public
class
InputManager
:
MonoBehaviour
{
public
class
InputManager
:
SingletonBehaviour
<
InputManager
>
{
public
InputAxisState
[]
inputs
;
public
InputAxisState
[]
inputs
;
public
InputState
inputState
;
public
InputState
inputState
;
...
...
Assets/Scripts/Player/InputState.cs
View file @
66003e68
...
@@ -10,12 +10,14 @@ using System.Collections.Generic;
...
@@ -10,12 +10,14 @@ using System.Collections.Generic;
*/
*/
public
class
ButtonState
{
public
class
ButtonState
{
public
bool
last
;
public
bool
value
;
public
bool
value
;
public
float
holdTime
=
0
;
public
float
holdTime
=
0
;
}
}
public
class
InputState
:
MonoBehaviour
{
public
class
InputState
:
MonoBehaviour
{
[
HideInInspector
]
public
Directions
direction
=
Directions
.
Right
;
public
Directions
direction
=
Directions
.
Right
;
private
Dictionary
<
Buttons
,
ButtonState
>
buttonStates
=
new
Dictionary
<
Buttons
,
ButtonState
>();
private
Dictionary
<
Buttons
,
ButtonState
>
buttonStates
=
new
Dictionary
<
Buttons
,
ButtonState
>();
...
@@ -25,7 +27,7 @@ public class InputState : MonoBehaviour {
...
@@ -25,7 +27,7 @@ public class InputState : MonoBehaviour {
buttonStates
.
Add
(
key
,
new
ButtonState
());
buttonStates
.
Add
(
key
,
new
ButtonState
());
}
}
var
state
=
buttonStates
[
key
];
var
state
=
buttonStates
[
key
];
state
.
last
=
state
.
value
;
if
(
state
.
value
&&
!
value
){
//key has been released
if
(
state
.
value
&&
!
value
){
//key has been released
state
.
holdTime
=
0
;
state
.
holdTime
=
0
;
}
else
if
(
state
.
value
&&
value
){
//key is being held down
}
else
if
(
state
.
value
&&
value
){
//key is being held down
...
@@ -34,6 +36,26 @@ public class InputState : MonoBehaviour {
...
@@ -34,6 +36,26 @@ public class InputState : MonoBehaviour {
state
.
value
=
value
;
state
.
value
=
value
;
}
}
public
bool
GetButtonPressed
(
Buttons
button
)
{
if
(
buttonStates
.
ContainsKey
(
button
))
{
ButtonState
state
=
buttonStates
[
button
];
return
state
.
value
&&
!
state
.
last
;
}
else
{
return
false
;
}
}
public
bool
GetButtonReleased
(
Buttons
button
)
{
if
(
buttonStates
.
ContainsKey
(
button
))
{
ButtonState
state
=
buttonStates
[
button
];
return
!
state
.
value
&&
state
.
last
;
}
else
{
return
false
;
}
}
public
bool
GetButtonValue
(
Buttons
key
){
public
bool
GetButtonValue
(
Buttons
key
){
if
(
buttonStates
.
ContainsKey
(
key
))
{
if
(
buttonStates
.
ContainsKey
(
key
))
{
return
buttonStates
[
key
].
value
;
return
buttonStates
[
key
].
value
;
...
...
ProjectSettings/ProjectVersion.txt
View file @
66003e68
m_EditorVersion: 5.3.5f1
m_EditorVersion: 5.5.0xf3Linux
m_StandardAssetsVersion: 0
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment