编辑代码

using System;

//Player 角色数据,状态
//NPC 敌人数据,状态
//EasyTouch 
//InputController  与输入相关
//MotionController 与运动相关
//AnimationParam 动画参数类
//AnimationEventBehaiour 动画行为类

namespace TripMax.Character
{
    public class CharacterMotion : MonoBehaviour
    {
        private CharacterController controller;
        
        [Tooltip("旋转速度")]
        public float roateSpeed = 20f;
        [Tooltip("移动速度")]
        public float moveSpeed = 2f;


        private void Start()
        {
            controller = GetComponent<CharacterController>();
        }

        // 注视方向旋转
        public void LookAtDir(Vector3 direction)
        {
            if(direction == Vector3.zero) return;
            Quaternion lookDir = Quaternion.LookRotation(direction);
            transform.rotation = Quaternion.Lerp(transform.rotation, lookDir, roateSpeed * Time.deltaTime);
        }

        public void Movement(Vector3 direction)
        {
            LookAtDir(direction);

            Vector3 forward = transform.foward;
            forward.y = -1;
            controller.Move(forward * Time.deltaTime * moveSpeed);
        }
    }

    public class InputController : MonoBeahviour
    {
        private ETCJoystick joys;
        private CharacterMotion motion; 
        private Animator animator;
        private PlayerStatus status;
        private ETCButton[] skillButtons;

        private void Awake()
        {
            joys = FindObjectOfType<ETCJoystick>();
            motion = GetComponent<CharacterMotion>();
            animator = GetComponentInChildren<Animator>();
            status = GetComponent<PlayerStatus>();
            skillButtons = FindObjectsOfType<ETCButton>();
        } //查找组件

        private void OnEnable()
        {
            joys.onMove.AddListener(OnJoystickMove);
            joys.onMoveStart.AddListener(onJoysStart);
            joys.onMoveEnd.AddListener(onJoysEnd);

            for(int i=0; i<skillButtons.Length; i++)
            {
                skillButtons[i].onDown.AddListnener(onSkillButtonDown);
            }
        } //注册事件

        private void OnDisable()
        {
            joys.onMove.RemoveListener(OnJoystickMove);
            joys.onMoveStart.RemoveListener(onJoysStart);
            joys.onMoveEnd.RemoveListener(onJoysEnd);
            
            for(int i=0; i<skillButtons.Length; i++)
            {
                skillButtons[i].onDown.RemoveListnener(onSkillButtonDown);
            }
        } //注销事件

        private void OnJoystickMove(Vector2 dir)
        {
            motion.Movement(new Vector3(dir.x, 0, dir.y));
        }

        private void OnJoysStart()
        {
            animator.SetBool(status.animationParam.run, true);
        }

        private void onJoysEnd()
        {
            animator.SetBool(status.animationParam.run, false);
        }

        private void OnSkillButtonDown()
        {
            print("打死你");
        }
    }


}