using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.InputSystem; /// /// 玩家类,代表屏幕外的玩家,用来处理输入、传达信息、记录状态 /// public class Player : UnitySingleton { private PlayerC playerC; private Horse horse; void Start() { //找到必要的物体和组件 FindSth(); //绑定输入 InputBinding(); } private void FindSth() { try{ horse = transform.Find("马").GetComponent(); }catch(System.Exception) {Debug.LogError("要么子物体中没有马、要么马的名字不是马、要么马身上没有Horse组件");} } private void InputBinding() { //新建了一个操控类的实例,小心多个操控类实例的坑!这个东西不会自动销毁 playerC = new PlayerC(); //绑定基本移动相关的事件 playerC.GamePlay.MoveFrontFoot.performed += ctx => horse.SetInputFrontVector(ctx.ReadValue()); playerC.GamePlay.MoveBackFoot.performed += ctx => horse.SetInputBackVector(ctx.ReadValue()); playerC.GamePlay.MoveFrontFoot.canceled += ctx => horse.SetInputFrontVector(Vector2.zero); playerC.GamePlay.MoveBackFoot.canceled += ctx => horse.SetInputBackVector(Vector2.zero); //绑定并拢腿的相关事件 playerC.GamePlay.MergeBackFoot.started += ctx => horse.MergeFoot(Horse.FootType.Back); playerC.GamePlay.MergeBackFoot.canceled += ctx => horse.RecoverFoot(Horse.FootType.Back); playerC.GamePlay.MergeFrontFoot.started += ctx => horse.MergeFoot(Horse.FootType.Front); playerC.GamePlay.MergeFrontFoot.canceled += ctx => horse.RecoverFoot(Horse.FootType.Front); playerC.GamePlay.Enable(); } public void ToNullMap() => playerC.GamePlay.Disable(); public void ToMap() => playerC.GamePlay.Enable(); }