Машина, камера, мотор
This commit is contained in:
1 parent
b54083521f
commit
a45223d0e7
48 files changed
+5507
-3735
No files matched your search
@@ -9,6 +9,7 @@ namespace Code.Example.Race.Racer.Player
|
||||
{
|
||||
private IInputService _inputService;
|
||||
public Vector2 MovementInput { get; private set; }
|
||||
public bool Brake { get; private set; }
|
||||
|
||||
[Inject]
|
||||
public void Construct(IInputService inputService)
|
||||
@@ -16,17 +17,25 @@ namespace Code.Example.Race.Racer.Player
|
||||
_inputService = inputService;
|
||||
_inputService.BindActionPerformed((int)ActionMappings.Gameplay, (int)GameplayActions.Move, MovementPerformed);
|
||||
_inputService.BindActionCancel((int)ActionMappings.Gameplay, (int)GameplayActions.Move, MovementEnded);
|
||||
_inputService.BindActionPerformed((int)ActionMappings.Gameplay, (int)GameplayActions.Brake, BrakePerformed);
|
||||
_inputService.BindActionCancel((int)ActionMappings.Gameplay, (int)GameplayActions.Brake, BrakeEnded);
|
||||
}
|
||||
|
||||
private void MovementPerformed(InputAction.CallbackContext context) => MovementInput = context.ReadValue<Vector2>();
|
||||
|
||||
private void MovementEnded(InputAction.CallbackContext context) => MovementInput = Vector2.zero;
|
||||
|
||||
private void BrakePerformed(InputAction.CallbackContext context) => Brake = context.ReadValue<bool>();
|
||||
|
||||
private void BrakeEnded(InputAction.CallbackContext context) => Brake = false;
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (_inputService == null) return;
|
||||
_inputService.UnbindActionPerformed((int)ActionMappings.Gameplay, (int)GameplayActions.Move, MovementPerformed);
|
||||
_inputService.UnbindActionCanceled((int)ActionMappings.Gameplay, (int)GameplayActions.Move, MovementEnded);
|
||||
_inputService.UnbindActionPerformed((int)ActionMappings.Gameplay, (int)GameplayActions.Brake, BrakePerformed);
|
||||
_inputService.UnbindActionCanceled((int)ActionMappings.Gameplay, (int)GameplayActions.Brake, BrakeEnded);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user