-
-
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.
Merge pull request #10 from eviltwo/use-inputplayer
Change to use PlayerInput for character and camera.
- Loading branch information
Showing
11 changed files
with
138 additions
and
161 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
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
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
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
56 changes: 22 additions & 34 deletions
56
src/ActionGameCore/Assets/CharacterControls/Scripts/Runtime/Inputs/CharacterMoveInput.cs
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,72 +1,60 @@ | ||
#if ENABLE_INPUT_SYSTEM | ||
using CharacterControls.Movements; | ||
using UnityEngine; | ||
|
||
#if SUPPORT_INPUTSYSTEM | ||
using UnityEngine.InputSystem; | ||
#endif | ||
|
||
namespace CharacterControls.Inputs | ||
{ | ||
public class CharacterMoveInput : MonoBehaviour | ||
{ | ||
#if SUPPORT_INPUTSYSTEM | ||
[Header("InputSystem")] | ||
[SerializeField] | ||
private PlayerInput _playerInput = null; | ||
|
||
[SerializeField] | ||
private InputActionReference _moveActionReference = null; | ||
|
||
[SerializeField] | ||
private InputActionReference _jumpActionReference = null; | ||
#endif | ||
|
||
public IMoveController MoveController { get; set; } | ||
|
||
private void Start() | ||
private void Awake() | ||
{ | ||
#if SUPPORT_INPUTSYSTEM | ||
_moveActionReference?.action.Enable(); | ||
_jumpActionReference?.action.Enable(); | ||
MoveController = GetComponent<IMoveController>(); | ||
#endif | ||
_playerInput.onActionTriggered += OnActionTriggerd; | ||
} | ||
|
||
private void Update() | ||
private void OnDestroy() | ||
{ | ||
if (MoveController == null) | ||
{ | ||
return; | ||
} | ||
|
||
UpdateMoveInput(); | ||
UpdateJumpInput(); | ||
_playerInput.onActionTriggered -= OnActionTriggerd; | ||
} | ||
|
||
private void UpdateMoveInput() | ||
private void OnActionTriggerd(InputAction.CallbackContext context) | ||
{ | ||
var value = Vector2.zero; | ||
if (_moveActionReference != null && context.action.name == _moveActionReference.action.name) | ||
{ | ||
OnMove(context); | ||
} | ||
|
||
#if SUPPORT_INPUTSYSTEM | ||
if (_moveActionReference != null) | ||
if (_jumpActionReference != null && context.action.name == _jumpActionReference.action.name) | ||
{ | ||
var v = _moveActionReference.action.ReadValue<Vector2>(); | ||
value = v.sqrMagnitude > value.sqrMagnitude ? v : value; | ||
OnJump(context); | ||
} | ||
#endif | ||
} | ||
|
||
private void OnMove(InputAction.CallbackContext context) | ||
{ | ||
var value = context.ReadValue<Vector2>(); | ||
MoveController.SetMoveInput(value); | ||
} | ||
|
||
private void UpdateJumpInput() | ||
private void OnJump(InputAction.CallbackContext context) | ||
{ | ||
var value = false; | ||
|
||
#if SUPPORT_INPUTSYSTEM | ||
value |= _jumpActionReference != null && _jumpActionReference.action.WasPressedThisFrame(); | ||
#endif | ||
|
||
if (value) | ||
if (context.performed && context.startTime > Time.realtimeSinceStartup - 0.5f) | ||
{ | ||
MoveController.SetJumpInput(1); | ||
} | ||
} | ||
} | ||
} | ||
#endif |
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
Oops, something went wrong.