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