using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.InputSystem; using Sirenix.OdinInspector; /// /// 玩家的控制器部分,玩家主类必须继承这个类才能对控制做出反应 /// public class PlayerControl : MonoBehaviour { private PlayerC playerC; /// /// 此帧输入方向,-1为左,1为右,0此帧不输入 /// [SerializeField][ReadOnly][Header("此帧输入方向,-1为左,1为右,0表示此帧不输入")] protected int inputDir; protected virtual void Start() { playerC = new PlayerC(); //playerC.Enable(); playerC.Normal.Enable(); //为事件订阅方法 //为移动操作订阅方法 playerC.Normal.Move.performed += ctx => OnMove(ctx); playerC.Normal.Move.canceled += ctx => { inputDir = 0; }; //为攻击操作订阅方法 playerC.Normal.Atk.performed += ctx => OnAtk(); //为跳跃操作订阅方法 playerC.Normal.Jump.performed += ctx => OnJump(); //为交互操作订阅方法 playerC.Normal.Interact.performed += ctx => OnInteract(); } /// /// 当有移动输入的时候触发,因为涉及读值,重些的时候记得必须Base /// protected virtual void OnMove(InputAction.CallbackContext ctx){ //根据读值设置记录的输入方向 if(ctx.ReadValue() > 0){ inputDir = 1; }else if(ctx.ReadValue() < 0){ inputDir = -1; } if(ctx.ReadValue().Equals(0f)){ inputDir = 0; } } /// /// 按下攻击时触发 /// protected virtual void OnAtk(){} /// /// 按下跳跃时触发 /// protected virtual void OnJump(){} /// /// 按下交互时触发 /// protected virtual void OnInteract(){} }