diff --git a/Assets/Goldenwere/GWSU/Controller/Character/InputSystemModule/Runtime/InputModule.cs b/Assets/Goldenwere/GWSU/Controller/Character/InputSystemModule/Runtime/InputModule.cs index e39c10f..e72f829 100644 --- a/Assets/Goldenwere/GWSU/Controller/Character/InputSystemModule/Runtime/InputModule.cs +++ b/Assets/Goldenwere/GWSU/Controller/Character/InputSystemModule/Runtime/InputModule.cs @@ -15,6 +15,8 @@ namespace Goldenwere.GWSU.CTRL.CHAR.InputSystemModule public Action started; } + public bool preferToggledInputs; + private Dictionary registeredCallbacks; private Dictionary RegisteredCallbacks @@ -33,16 +35,35 @@ namespace Goldenwere.GWSU.CTRL.CHAR.InputSystemModule { if (TryGetReference(_action.Emitter, out InputActionReference _reference)) { + Action canceled = (InputAction.CallbackContext ctx) => + { + switch (_action.Type) + { + case ModuleActionType.HeldOrPressed: + if (!preferToggledInputs) + { + _action.Listener.Invoke(); + } + break; + case ModuleActionType.Held: + _action.Listener.Invoke(); + break; + } + }; + Action performed = (InputAction.CallbackContext ctx) => { _action.Listener.Invoke(); }; + + _reference.action.canceled += canceled; _reference.action.performed += performed; RegisteredCallbacks.Add ( _action.GUID, new Callbacks { + canceled = canceled, performed = performed, } ); @@ -102,7 +123,9 @@ namespace Goldenwere.GWSU.CTRL.CHAR.InputSystemModule { if (CheckForCallback(_id)) { + _reference.action.canceled -= RegisteredCallbacks[_id].canceled; _reference.action.performed -= RegisteredCallbacks[_id].performed; + _reference.action.started -= RegisteredCallbacks[_id].started; RegisteredCallbacks.Remove(_id); } } diff --git a/Assets/Goldenwere/GWSU/Controller/Character/InputSystemModule/Samples/SampleProject/Runtime/FakeControllerModule.cs b/Assets/Goldenwere/GWSU/Controller/Character/InputSystemModule/Samples/SampleProject/Runtime/FakeControllerModule.cs index 81e239b..4840ea6 100644 --- a/Assets/Goldenwere/GWSU/Controller/Character/InputSystemModule/Samples/SampleProject/Runtime/FakeControllerModule.cs +++ b/Assets/Goldenwere/GWSU/Controller/Character/InputSystemModule/Samples/SampleProject/Runtime/FakeControllerModule.cs @@ -10,34 +10,34 @@ namespace Goldenwere.GWSU.CTRL.CHAR.InputSystemModule.SampleProject [SerializeField] private ScriptableObject emitterOnJump; [SerializeField] private ScriptableObject emitterOnMovement; - private BaseModuleAction actionOnCrouch; + private BaseModuleAction actionOnCrouch; private BaseModuleAction actionOnJump; private BaseModuleAction actionOnMovement; private void Awake() { - actionOnCrouch = new BaseModuleAction(OnCrouch, emitterOnCrouch, ModuleActionType.HeldOrPressed); + actionOnCrouch = new BaseModuleAction(OnCrouch, emitterOnCrouch, ModuleActionType.HeldOrPressed); actionOnJump = new BaseModuleAction(OnJump, emitterOnJump, ModuleActionType.Pressed); actionOnMovement = new BaseModuleAction(OnMovement, emitterOnJump, ModuleActionType.Held); } private void OnEnable() { - //module.RegisterModuleAction(actionOnCrouch); + module.RegisterModuleAction(actionOnCrouch); module.RegisterModuleAction(actionOnJump); //module.RegisterModuleAction(actionOnMovement); } private void OnDisable() { - //module.UnregisterModuleAction(actionOnCrouch); + module.UnregisterModuleAction(actionOnCrouch); module.UnregisterModuleAction(actionOnJump); //module.UnregisterModuleAction(actionOnMovement); } - private void OnCrouch(bool pressed) + private void OnCrouch() { - Debug.Log($"Crouch was {(pressed ? "pressed" : "released")}"); + Debug.Log($"Crouched"); } private void OnJump()