-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
439 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,84 @@ | ||
using UnityEngine; | ||
#if ENABLE_INPUT_SYSTEM | ||
using UnityEngine.InputSystem; | ||
#endif | ||
|
||
namespace StarterAssets | ||
namespace InputSystem | ||
{ | ||
public class StarterAssetsInputs : MonoBehaviour | ||
{ | ||
[Header("Character Input Values")] | ||
public Vector2 move; | ||
public Vector2 look; | ||
public bool jump; | ||
public bool sprint; | ||
public class StarterAssetsInputs : MonoBehaviour | ||
{ | ||
[Header("Character Input Values")] public Vector2 move; | ||
|
||
public Vector2 look; | ||
public bool jump; | ||
public bool sprint; | ||
public bool crouch; | ||
|
||
[Header("Movement Settings")] public bool analogMovement; | ||
|
||
[Header("Mouse Cursor Settings")] public bool cursorLocked = true; | ||
|
||
public bool cursorInputForLook = true; | ||
|
||
private void OnApplicationFocus(bool hasFocus) | ||
{ | ||
SetCursorState(cursorLocked); | ||
} | ||
|
||
|
||
[Header("Movement Settings")] | ||
public bool analogMovement; | ||
public void MoveInput(Vector2 newMoveDirection) | ||
{ | ||
move = newMoveDirection; | ||
} | ||
|
||
[Header("Mouse Cursor Settings")] | ||
public bool cursorLocked = true; | ||
public bool cursorInputForLook = true; | ||
public void LookInput(Vector2 newLookDirection) | ||
{ | ||
look = newLookDirection; | ||
} | ||
|
||
public void JumpInput(bool newJumpState) | ||
{ | ||
jump = newJumpState; | ||
} | ||
|
||
public void SprintInput(bool newSprintState) | ||
{ | ||
sprint = newSprintState; | ||
} | ||
|
||
public void CrouchInput(bool newCrouchState) | ||
{ | ||
crouch = newCrouchState; | ||
} | ||
|
||
private void SetCursorState(bool newState) | ||
{ | ||
Cursor.lockState = newState ? CursorLockMode.Locked : CursorLockMode.None; | ||
} | ||
|
||
#if ENABLE_INPUT_SYSTEM | ||
public void OnMove(InputValue value) | ||
{ | ||
MoveInput(value.Get<Vector2>()); | ||
} | ||
|
||
public void OnLook(InputValue value) | ||
{ | ||
if(cursorInputForLook) | ||
{ | ||
LookInput(value.Get<Vector2>()); | ||
} | ||
} | ||
|
||
public void OnJump(InputValue value) | ||
{ | ||
JumpInput(value.isPressed); | ||
} | ||
|
||
public void OnSprint(InputValue value) | ||
{ | ||
SprintInput(value.isPressed); | ||
} | ||
#endif | ||
public void OnMove(InputValue value) | ||
{ | ||
MoveInput(value.Get<Vector2>()); | ||
} | ||
|
||
public void OnLook(InputValue value) | ||
{ | ||
if (cursorInputForLook) LookInput(value.Get<Vector2>()); | ||
} | ||
|
||
public void OnJump(InputValue value) | ||
{ | ||
JumpInput(value.isPressed); | ||
} | ||
|
||
public void MoveInput(Vector2 newMoveDirection) | ||
{ | ||
move = newMoveDirection; | ||
} | ||
|
||
public void LookInput(Vector2 newLookDirection) | ||
{ | ||
look = newLookDirection; | ||
} | ||
|
||
public void JumpInput(bool newJumpState) | ||
{ | ||
jump = newJumpState; | ||
} | ||
|
||
public void SprintInput(bool newSprintState) | ||
{ | ||
sprint = newSprintState; | ||
} | ||
|
||
private void OnApplicationFocus(bool hasFocus) | ||
{ | ||
SetCursorState(cursorLocked); | ||
} | ||
|
||
private void SetCursorState(bool newState) | ||
{ | ||
Cursor.lockState = newState ? CursorLockMode.Locked : CursorLockMode.None; | ||
} | ||
} | ||
|
||
public void OnSprint(InputValue value) | ||
{ | ||
SprintInput(value.isPressed); | ||
} | ||
|
||
public void OnCrouch(InputValue value) | ||
{ | ||
CrouchInput(value.isPressed); | ||
} | ||
#endif | ||
} | ||
} |
Oops, something went wrong.