diff --git a/Assets/Input/PlayerInput.cs b/Assets/Input/PlayerInput.cs index 826dc3a4766df5b6c0792cddcd1b710607a4338a..66b3e589f06add0d765d37d4b3d21f48e032b4bf 100644 --- a/Assets/Input/PlayerInput.cs +++ b/Assets/Input/PlayerInput.cs @@ -36,6 +36,24 @@ public partial class @PlayerInput: IInputActionCollection2, IDisposable ""interactions"": """", ""initialStateCheck"": true }, + { + ""name"": ""Reload"", + ""type"": ""Button"", + ""id"": ""bdf299d4-51bb-492c-b276-c7c97f7db46a"", + ""expectedControlType"": ""Button"", + ""processors"": """", + ""interactions"": """", + ""initialStateCheck"": false + }, + { + ""name"": ""Shoot"", + ""type"": ""Button"", + ""id"": ""3c4532d3-a95e-4d7d-a35e-fa5a9c426fca"", + ""expectedControlType"": ""Button"", + ""processors"": """", + ""interactions"": """", + ""initialStateCheck"": false + }, { ""name"": ""Jump"", ""type"": ""Button"", @@ -291,6 +309,50 @@ public partial class @PlayerInput: IInputActionCollection2, IDisposable ""action"": ""Sprint"", ""isComposite"": false, ""isPartOfComposite"": false + }, + { + ""name"": """", + ""id"": ""2789497d-68da-4de8-9389-ab64254945ba"", + ""path"": ""<Mouse>/leftButton"", + ""interactions"": """", + ""processors"": """", + ""groups"": """", + ""action"": ""Shoot"", + ""isComposite"": false, + ""isPartOfComposite"": false + }, + { + ""name"": """", + ""id"": ""01ca45ca-8cab-417b-9cfb-cb11b9f101a8"", + ""path"": ""<Gamepad>/rightTrigger"", + ""interactions"": """", + ""processors"": """", + ""groups"": """", + ""action"": ""Shoot"", + ""isComposite"": false, + ""isPartOfComposite"": false + }, + { + ""name"": """", + ""id"": ""5d2e31f1-01e8-4b46-9e50-696e7562d3a2"", + ""path"": ""<Keyboard>/r"", + ""interactions"": """", + ""processors"": """", + ""groups"": """", + ""action"": ""Reload"", + ""isComposite"": false, + ""isPartOfComposite"": false + }, + { + ""name"": """", + ""id"": ""8f639a28-7027-4b11-aef0-1f39352fd379"", + ""path"": ""<Gamepad>/buttonWest"", + ""interactions"": """", + ""processors"": """", + ""groups"": """", + ""action"": ""Reload"", + ""isComposite"": false, + ""isPartOfComposite"": false } ] }, @@ -809,54 +871,6 @@ public partial class @PlayerInput: IInputActionCollection2, IDisposable ""isPartOfComposite"": false } ] - }, - { - ""name"": ""Weapon"", - ""id"": ""776c71f5-0fc4-4d1a-b6f7-57338ff8edd4"", - ""actions"": [ - { - ""name"": ""Shoot"", - ""type"": ""Button"", - ""id"": ""e0d19276-edea-4a7f-abe4-a0ae1a59cef1"", - ""expectedControlType"": ""Button"", - ""processors"": """", - ""interactions"": """", - ""initialStateCheck"": false - }, - { - ""name"": ""Reload"", - ""type"": ""Button"", - ""id"": ""de7dfd3f-21b0-4c00-8129-d5edd8f63489"", - ""expectedControlType"": ""Button"", - ""processors"": """", - ""interactions"": """", - ""initialStateCheck"": false - } - ], - ""bindings"": [ - { - ""name"": """", - ""id"": ""faaef20b-720d-4c61-97d0-70c1af6d33a5"", - ""path"": ""<Mouse>/leftButton"", - ""interactions"": """", - ""processors"": """", - ""groups"": """", - ""action"": ""Shoot"", - ""isComposite"": false, - ""isPartOfComposite"": false - }, - { - ""name"": """", - ""id"": ""fe2ea0d8-d159-4bfb-b630-b238a8e9c891"", - ""path"": ""<Keyboard>/r"", - ""interactions"": """", - ""processors"": """", - ""groups"": """", - ""action"": ""Reload"", - ""isComposite"": false, - ""isPartOfComposite"": false - } - ] } ], ""controlSchemes"": [] @@ -864,6 +878,8 @@ public partial class @PlayerInput: IInputActionCollection2, IDisposable // OnFoot m_OnFoot = asset.FindActionMap("OnFoot", throwIfNotFound: true); m_OnFoot_Movement = m_OnFoot.FindAction("Movement", throwIfNotFound: true); + m_OnFoot_Reload = m_OnFoot.FindAction("Reload", throwIfNotFound: true); + m_OnFoot_Shoot = m_OnFoot.FindAction("Shoot", throwIfNotFound: true); m_OnFoot_Jump = m_OnFoot.FindAction("Jump", throwIfNotFound: true); m_OnFoot_Look = m_OnFoot.FindAction("Look", throwIfNotFound: true); m_OnFoot_Interact = m_OnFoot.FindAction("Interact", throwIfNotFound: true); @@ -881,10 +897,6 @@ public partial class @PlayerInput: IInputActionCollection2, IDisposable m_UI_RightClick = m_UI.FindAction("RightClick", throwIfNotFound: true); m_UI_TrackedDevicePosition = m_UI.FindAction("TrackedDevicePosition", throwIfNotFound: true); m_UI_TrackedDeviceOrientation = m_UI.FindAction("TrackedDeviceOrientation", throwIfNotFound: true); - // Weapon - m_Weapon = asset.FindActionMap("Weapon", throwIfNotFound: true); - m_Weapon_Shoot = m_Weapon.FindAction("Shoot", throwIfNotFound: true); - m_Weapon_Reload = m_Weapon.FindAction("Reload", throwIfNotFound: true); } public void Dispose() @@ -947,6 +959,8 @@ public partial class @PlayerInput: IInputActionCollection2, IDisposable private readonly InputActionMap m_OnFoot; private List<IOnFootActions> m_OnFootActionsCallbackInterfaces = new List<IOnFootActions>(); private readonly InputAction m_OnFoot_Movement; + private readonly InputAction m_OnFoot_Reload; + private readonly InputAction m_OnFoot_Shoot; private readonly InputAction m_OnFoot_Jump; private readonly InputAction m_OnFoot_Look; private readonly InputAction m_OnFoot_Interact; @@ -957,6 +971,8 @@ public partial class @PlayerInput: IInputActionCollection2, IDisposable private @PlayerInput m_Wrapper; public OnFootActions(@PlayerInput wrapper) { m_Wrapper = wrapper; } public InputAction @Movement => m_Wrapper.m_OnFoot_Movement; + public InputAction @Reload => m_Wrapper.m_OnFoot_Reload; + public InputAction @Shoot => m_Wrapper.m_OnFoot_Shoot; public InputAction @Jump => m_Wrapper.m_OnFoot_Jump; public InputAction @Look => m_Wrapper.m_OnFoot_Look; public InputAction @Interact => m_Wrapper.m_OnFoot_Interact; @@ -974,6 +990,12 @@ public partial class @PlayerInput: IInputActionCollection2, IDisposable @Movement.started += instance.OnMovement; @Movement.performed += instance.OnMovement; @Movement.canceled += instance.OnMovement; + @Reload.started += instance.OnReload; + @Reload.performed += instance.OnReload; + @Reload.canceled += instance.OnReload; + @Shoot.started += instance.OnShoot; + @Shoot.performed += instance.OnShoot; + @Shoot.canceled += instance.OnShoot; @Jump.started += instance.OnJump; @Jump.performed += instance.OnJump; @Jump.canceled += instance.OnJump; @@ -996,6 +1018,12 @@ public partial class @PlayerInput: IInputActionCollection2, IDisposable @Movement.started -= instance.OnMovement; @Movement.performed -= instance.OnMovement; @Movement.canceled -= instance.OnMovement; + @Reload.started -= instance.OnReload; + @Reload.performed -= instance.OnReload; + @Reload.canceled -= instance.OnReload; + @Shoot.started -= instance.OnShoot; + @Shoot.performed -= instance.OnShoot; + @Shoot.canceled -= instance.OnShoot; @Jump.started -= instance.OnJump; @Jump.performed -= instance.OnJump; @Jump.canceled -= instance.OnJump; @@ -1146,63 +1174,11 @@ public partial class @PlayerInput: IInputActionCollection2, IDisposable } } public UIActions @UI => new UIActions(this); - - // Weapon - private readonly InputActionMap m_Weapon; - private List<IWeaponActions> m_WeaponActionsCallbackInterfaces = new List<IWeaponActions>(); - private readonly InputAction m_Weapon_Shoot; - private readonly InputAction m_Weapon_Reload; - public struct WeaponActions - { - private @PlayerInput m_Wrapper; - public WeaponActions(@PlayerInput wrapper) { m_Wrapper = wrapper; } - public InputAction @Shoot => m_Wrapper.m_Weapon_Shoot; - public InputAction @Reload => m_Wrapper.m_Weapon_Reload; - public InputActionMap Get() { return m_Wrapper.m_Weapon; } - public void Enable() { Get().Enable(); } - public void Disable() { Get().Disable(); } - public bool enabled => Get().enabled; - public static implicit operator InputActionMap(WeaponActions set) { return set.Get(); } - public void AddCallbacks(IWeaponActions instance) - { - if (instance == null || m_Wrapper.m_WeaponActionsCallbackInterfaces.Contains(instance)) return; - m_Wrapper.m_WeaponActionsCallbackInterfaces.Add(instance); - @Shoot.started += instance.OnShoot; - @Shoot.performed += instance.OnShoot; - @Shoot.canceled += instance.OnShoot; - @Reload.started += instance.OnReload; - @Reload.performed += instance.OnReload; - @Reload.canceled += instance.OnReload; - } - - private void UnregisterCallbacks(IWeaponActions instance) - { - @Shoot.started -= instance.OnShoot; - @Shoot.performed -= instance.OnShoot; - @Shoot.canceled -= instance.OnShoot; - @Reload.started -= instance.OnReload; - @Reload.performed -= instance.OnReload; - @Reload.canceled -= instance.OnReload; - } - - public void RemoveCallbacks(IWeaponActions instance) - { - if (m_Wrapper.m_WeaponActionsCallbackInterfaces.Remove(instance)) - UnregisterCallbacks(instance); - } - - public void SetCallbacks(IWeaponActions instance) - { - foreach (var item in m_Wrapper.m_WeaponActionsCallbackInterfaces) - UnregisterCallbacks(item); - m_Wrapper.m_WeaponActionsCallbackInterfaces.Clear(); - AddCallbacks(instance); - } - } - public WeaponActions @Weapon => new WeaponActions(this); public interface IOnFootActions { void OnMovement(InputAction.CallbackContext context); + void OnReload(InputAction.CallbackContext context); + void OnShoot(InputAction.CallbackContext context); void OnJump(InputAction.CallbackContext context); void OnLook(InputAction.CallbackContext context); void OnInteract(InputAction.CallbackContext context); @@ -1222,9 +1198,4 @@ public partial class @PlayerInput: IInputActionCollection2, IDisposable void OnTrackedDevicePosition(InputAction.CallbackContext context); void OnTrackedDeviceOrientation(InputAction.CallbackContext context); } - public interface IWeaponActions - { - void OnShoot(InputAction.CallbackContext context); - void OnReload(InputAction.CallbackContext context); - } } diff --git a/Assets/Input/PlayerInput.inputactions b/Assets/Input/PlayerInput.inputactions index 6cb32aed4c3f50044a57ef83c5ea55032cd73484..d83268867c81cc029ab9a1b5004bc3dbe22f4464 100644 --- a/Assets/Input/PlayerInput.inputactions +++ b/Assets/Input/PlayerInput.inputactions @@ -14,6 +14,24 @@ "interactions": "", "initialStateCheck": true }, + { + "name": "Reload", + "type": "Button", + "id": "bdf299d4-51bb-492c-b276-c7c97f7db46a", + "expectedControlType": "Button", + "processors": "", + "interactions": "", + "initialStateCheck": false + }, + { + "name": "Shoot", + "type": "Button", + "id": "3c4532d3-a95e-4d7d-a35e-fa5a9c426fca", + "expectedControlType": "Button", + "processors": "", + "interactions": "", + "initialStateCheck": false + }, { "name": "Jump", "type": "Button", @@ -269,6 +287,50 @@ "action": "Sprint", "isComposite": false, "isPartOfComposite": false + }, + { + "name": "", + "id": "2789497d-68da-4de8-9389-ab64254945ba", + "path": "<Mouse>/leftButton", + "interactions": "", + "processors": "", + "groups": "", + "action": "Shoot", + "isComposite": false, + "isPartOfComposite": false + }, + { + "name": "", + "id": "01ca45ca-8cab-417b-9cfb-cb11b9f101a8", + "path": "<Gamepad>/rightTrigger", + "interactions": "", + "processors": "", + "groups": "", + "action": "Shoot", + "isComposite": false, + "isPartOfComposite": false + }, + { + "name": "", + "id": "5d2e31f1-01e8-4b46-9e50-696e7562d3a2", + "path": "<Keyboard>/r", + "interactions": "", + "processors": "", + "groups": "", + "action": "Reload", + "isComposite": false, + "isPartOfComposite": false + }, + { + "name": "", + "id": "8f639a28-7027-4b11-aef0-1f39352fd379", + "path": "<Gamepad>/buttonWest", + "interactions": "", + "processors": "", + "groups": "", + "action": "Reload", + "isComposite": false, + "isPartOfComposite": false } ] }, @@ -787,54 +849,6 @@ "isPartOfComposite": false } ] - }, - { - "name": "Weapon", - "id": "776c71f5-0fc4-4d1a-b6f7-57338ff8edd4", - "actions": [ - { - "name": "Shoot", - "type": "Button", - "id": "e0d19276-edea-4a7f-abe4-a0ae1a59cef1", - "expectedControlType": "Button", - "processors": "", - "interactions": "", - "initialStateCheck": false - }, - { - "name": "Reload", - "type": "Button", - "id": "de7dfd3f-21b0-4c00-8129-d5edd8f63489", - "expectedControlType": "Button", - "processors": "", - "interactions": "", - "initialStateCheck": false - } - ], - "bindings": [ - { - "name": "", - "id": "faaef20b-720d-4c61-97d0-70c1af6d33a5", - "path": "<Mouse>/leftButton", - "interactions": "", - "processors": "", - "groups": "", - "action": "Shoot", - "isComposite": false, - "isPartOfComposite": false - }, - { - "name": "", - "id": "fe2ea0d8-d159-4bfb-b630-b238a8e9c891", - "path": "<Keyboard>/r", - "interactions": "", - "processors": "", - "groups": "", - "action": "Reload", - "isComposite": false, - "isPartOfComposite": false - } - ] } ], "controlSchemes": [] diff --git a/Assets/Script/Player/InputManager.cs b/Assets/Script/Player/InputManager.cs index 2b19d09d1b8f96d08666d17396e00289d2c174a6..a9cf54c7709111dc5f07b8ff67b015d190f1170c 100644 --- a/Assets/Script/Player/InputManager.cs +++ b/Assets/Script/Player/InputManager.cs @@ -8,7 +8,6 @@ public class InputManager : MonoBehaviour { private PlayerInput playerInput; public PlayerInput.OnFootActions onFoot; - public PlayerInput.WeaponActions weaponActions; private PlayerMotor motor; private PlayerLook look; @@ -20,7 +19,6 @@ public class InputManager : MonoBehaviour { playerInput = new PlayerInput(); onFoot = playerInput.OnFoot; - weaponActions = playerInput.Weapon; motor = GetComponent<PlayerMotor>(); look = GetComponent<PlayerLook>(); onFoot.Jump.performed += ctx => motor.Jump(); @@ -29,6 +27,7 @@ public class InputManager : MonoBehaviour // Update is called once per frame void FixedUpdate() { + Debug.Log(onFoot.Shoot.ReadValue<float>()); if (!isPaused) { motor.ProcessMove(onFoot.Movement.ReadValue<Vector2>()); diff --git a/Assets/Script/Weapon/GunSystem.cs b/Assets/Script/Weapon/GunSystem.cs index 56d6dd85c89653b09948966dc26c3c5e25cd9bcf..4c218052e417c4aea525af1fe1bd9bdb4bd528f5 100644 --- a/Assets/Script/Weapon/GunSystem.cs +++ b/Assets/Script/Weapon/GunSystem.cs @@ -38,10 +38,10 @@ public class GunSystem : MonoBehaviour private void Start() { player = GameObject.FindGameObjectWithTag("Player"); - inputManager = GetComponent<InputManager>(); bulletsLeft = magSize; readyToShoot = true; reloading = false; + inputManager = player.GetComponent<InputManager>(); } private void Update() @@ -70,10 +70,10 @@ public class GunSystem : MonoBehaviour crossHair.SetActive(true); cam.GetComponentInParent<Animator>().SetTrigger("exitAim"); } - if (allowButtonHold) shooting = Input.GetKey(KeyCode.Mouse0); - else shooting = Input.GetKeyDown(KeyCode.Mouse0); + if (allowButtonHold) shooting = inputManager.onFoot.Shoot.IsPressed(); + else shooting = inputManager.onFoot.Shoot.WasPressedThisFrame(); - if (Input.GetKeyDown(KeyCode.R) && bulletsLeft < magSize && !reloading) Reload(); + if (inputManager.onFoot.Reload.triggered && bulletsLeft < magSize && !reloading) Reload(); //Shoot if (readyToShoot && shooting && !reloading && bulletsLeft > 0)