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/AnimatorHandler.cs | 92 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 Assets/Scripts/AnimatorHandler.cs (limited to 'Assets/Scripts/AnimatorHandler.cs') diff --git a/Assets/Scripts/AnimatorHandler.cs b/Assets/Scripts/AnimatorHandler.cs new file mode 100644 index 0000000..d95d12b --- /dev/null +++ b/Assets/Scripts/AnimatorHandler.cs @@ -0,0 +1,92 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace DS +{ + public class AnimatorHandler : MonoBehaviour + { + public Animator animator; + private int _vertical; + private int _horizontal; + public bool canRotate; + + public void Initialize() + { + animator = GetComponent(); + _vertical = Animator.StringToHash("Vertical"); + _horizontal = Animator.StringToHash("Horizontal"); + } + + public void UpdateAnimatorValues(float verticalMovement, float horizontalMovement) + { + #region Vertical + + float v = 0; + + if (verticalMovement > 0 && verticalMovement < 0.55f) + { + v = 0.5f; + } + else if(verticalMovement > 0.55f) + { + v = 1; + } + else if (verticalMovement < 0 && verticalMovement > -0.55f) + { + v = -0.5f; + } + else if(verticalMovement < -0.55f) + { + v = -1; + } + else + { + v = 0; + } + + #endregion + + #region Horizontal + + float h = 0; + + if (horizontalMovement > 0 && horizontalMovement < 0.55f) + { + h = 0.5f; + } + else if(horizontalMovement > 0.55f) + { + h = 1; + } + else if (horizontalMovement < 0 && horizontalMovement > -0.55f) + { + h = -0.5f; + } + else if(horizontalMovement < -0.55f) + { + h = -1; + } + else + { + h = 0; + } + + #endregion + + animator.SetFloat(_vertical,v,0.1f,Time.deltaTime); + animator.SetFloat(_horizontal,h,0.1f,Time.deltaTime); + } + + public void CanRotate() + { + canRotate = true; + } + + public void StopRotation() + { + canRotate = false; + } + } + +} -- cgit