From 6ce8b9e22fc13be34b442c7b6af48b42cd44275a Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Wed, 13 Mar 2024 11:00:58 +0800 Subject: +init --- InputHandler.cs | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 InputHandler.cs (limited to 'InputHandler.cs') diff --git a/InputHandler.cs b/InputHandler.cs new file mode 100644 index 0000000..27adc82 --- /dev/null +++ b/InputHandler.cs @@ -0,0 +1,120 @@ +using UnityEngine; + +public class InputHandler : MonoBehaviour +{ + public Vector3 inputMovementDirection; + + public Vector3 lastInputDirection; + + public bool isSpringting; + + private WeaponHandler wepaonHandler; + + private MovementDataHandler movementData; + + private WeaponHandler weaponHandler; + + private CameraMovement cameraMovement; + + private PlayerDeath death; + + private HasControl hasControl; + + private MovementHandler movement; + + public bool allowStrafe = true; + + private void Start() + { + death = GetComponent(); + movement = GetComponent(); + wepaonHandler = GetComponent(); + hasControl = GetComponent(); + movementData = GetComponent(); + weaponHandler = GetComponent(); + cameraMovement = GetComponentInChildren(); + } + + private void Update() + { + if ((bool)death && death.dead) + { + return; + } + if (!hasControl || hasControl.hasControl) + { + isSpringting = false; + inputMovementDirection = Vector3.zero; + if (Input.GetKey(KeyCode.W)) + { + inputMovementDirection += movementData.groundedForward; + } + if (Input.GetKey(KeyCode.S)) + { + inputMovementDirection += movementData.groundedBack; + } + if (Input.GetKey(KeyCode.D) && allowStrafe) + { + inputMovementDirection += movementData.right; + } + if (Input.GetKey(KeyCode.A) && allowStrafe) + { + inputMovementDirection += movementData.left; + } + if (Input.GetKey(KeyCode.LeftShift) && (!cameraMovement || !cameraMovement.ADS)) + { + isSpringting = true; + } + inputMovementDirection = inputMovementDirection.normalized; + if ((bool)movement && Input.GetKeyDown(KeyCode.Space)) + { + movement.Jump(); + } + if ((bool)weaponHandler) + { + if (weaponHandler.isDualWeilding) + { + if (Input.GetKey(KeyCode.Mouse1)) + { + weaponHandler.HoldAttack(shootWithRightGun: true, ADS: false); + } + if (Input.GetKeyDown(KeyCode.Mouse1)) + { + weaponHandler.PressAttack(shootWithRightGun: true, ADS: false); + } + if (Input.GetKey(KeyCode.Mouse0)) + { + weaponHandler.HoldAttack(shootWithRightGun: false, ADS: false); + } + if (Input.GetKeyDown(KeyCode.Mouse0)) + { + weaponHandler.PressAttack(shootWithRightGun: false, ADS: false); + } + } + else + { + if (Input.GetKey(KeyCode.Mouse1)) + { + cameraMovement.ADS = true; + } + else + { + cameraMovement.ADS = false; + } + if (Input.GetKey(KeyCode.Mouse0)) + { + weaponHandler.HoldAttack(shootWithRightGun: true, cameraMovement.ADS); + } + if (Input.GetKeyDown(KeyCode.Mouse0)) + { + weaponHandler.PressAttack(shootWithRightGun: true, cameraMovement.ADS); + } + } + } + } + if (inputMovementDirection != Vector3.zero) + { + lastInputDirection = inputMovementDirection; + } + } +} -- cgit v1.1-26-g67d0