From 41def44651b5a7c9e917395fad5e7b480640a3a2 Mon Sep 17 00:00:00 2001 From: SmallFox <2806143047@qq.com> Date: Thu, 14 May 2026 21:17:29 +0800 Subject: Movement完工 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 写完了移动,准备开工相机视角 --- Assets/Scripts/InputHandler.cs | 54 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Assets/Scripts/InputHandler.cs (limited to 'Assets/Scripts/InputHandler.cs') diff --git a/Assets/Scripts/InputHandler.cs b/Assets/Scripts/InputHandler.cs new file mode 100644 index 0000000..ec72656 --- /dev/null +++ b/Assets/Scripts/InputHandler.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace DS +{ + public class InputHandler : MonoBehaviour + { + public float horizontal; + public float vertical; + public float moveAmount; + public float mouseX; + public float mouseY; + + private PlayerControls _inputActions; + + private Vector2 _movementInput; + private Vector2 _cameraInput; + + public void OnEnable() + { + if (_inputActions == null) + { + _inputActions = new PlayerControls(); + _inputActions.PlayerMovement.Movement.performed += + ctx => _movementInput = ctx.ReadValue(); + _inputActions.PlayerMovement.Camera.performed += ctx => _cameraInput = ctx.ReadValue(); + } + + _inputActions.Enable(); + } + + private void OnDisable() + { + _inputActions.Disable(); + } + + public void TickInput(float delta) + { + MoveInput(delta); + } + + private void MoveInput(float delta) + { + horizontal = _movementInput.x; + vertical = _movementInput.y; + moveAmount = Mathf.Clamp01(Mathf.Abs((horizontal)) + Mathf.Abs(vertical)); + mouseX = _cameraInput.x; + mouseY = _cameraInput.y; + } + } +} + -- cgit