using System; using UnityEngine; using UnityEngine.InputSystem; public abstract class InputBase : MonoBehaviour { public Action AttackCallback; public abstract float GetMovementDirection(); } public class Input : InputBase { // Will want to create an "Input Actions" asset, this should allow the user to set their bindings in a menu and I'll be able to load that during the game. // The above is super important for this prototype, but could be used for all other prototypes. public InputActionAsset controlScheme; private InputActionMap _inputActionMap; private InputAction _movementAction; //private InputAction _jumpAction; //private InputAction _crouchAction; private InputAction _lightPunch; private InputAction _mediumPunch; private InputAction _heavyPunch; // This looks dumb, but I think will make the AI setup better. public override float GetMovementDirection() { return _movementAction.ReadValue(); } private void Start() { _inputActionMap = controlScheme.FindActionMap("P1"); _movementAction = _inputActionMap["MovementAction"]; _movementAction.Enable(); _lightPunch = _inputActionMap["LightPunch"]; _lightPunch.Enable(); _lightPunch.performed += LightPunchPerformed; _mediumPunch = _inputActionMap["MediumPunch"]; _mediumPunch.Enable(); _mediumPunch.performed += MediumPunchPerformed; _heavyPunch = _inputActionMap["HeavyPunch"]; _heavyPunch.Enable(); _heavyPunch.performed += HeavyPunchPerformed; } // TODO: probably need to handle input better. // In terms of performance this is good, 0 latency from when the program gets the input and the animation starting. // Obviously this will change as I think buffered input is good, but it's nice to know that I'm starting at 0ms. // Also as combos and buffered input become a thing I'll want to handle this differently, maybe a flag/bitmask? private void HeavyPunchPerformed(InputAction.CallbackContext obj) { AttackCallback(AttackState.Heavy); } private void MediumPunchPerformed(InputAction.CallbackContext obj) { AttackCallback(AttackState.Medium); } private void LightPunchPerformed(InputAction.CallbackContext obj) { AttackCallback(AttackState.Light); } }