85 lines
2.1 KiB
C#
85 lines
2.1 KiB
C#
using System.Collections;
|
|||
|
|
using System.Collections.Generic;
|
||
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
public class InputMgr : Singleton<InputMgr>
|
||
|
|
{
|
||
|
|
private bool isStart = false;
|
||
|
|
public InputMgr()
|
||
|
|
{
|
||
|
|
MonoMgr.Instance.AddUpdateListener(MyUpdate);
|
||
|
|
}
|
||
|
|
public void StartOrEndCheck(bool isOpen)
|
||
|
|
{
|
||
|
|
isStart = isOpen;
|
||
|
|
}
|
||
|
|
private void MyUpdate()
|
||
|
|
{
|
||
|
|
if (!isStart)
|
||
|
|
return;
|
||
|
|
CheckKeyCode(KeyCode.J);
|
||
|
|
CheckKeyCode(KeyCode.K);
|
||
|
|
}
|
||
|
|
private void CheckKeyCode(KeyCode key)
|
||
|
|
{
|
||
|
|
if(Input.GetKeyDown(key))
|
||
|
|
{
|
||
|
|
EventCenter.Instance.EventTrigger("KeyisDown", key);
|
||
|
|
}
|
||
|
|
if (Input.GetKeyUp(key))
|
||
|
|
{
|
||
|
|
EventCenter.Instance.EventTrigger("KeyisUp", key);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
#region 用法
|
||
|
|
//public class Inputtest : MonoBehaviour
|
||
|
|
//{
|
||
|
|
// void Start()
|
||
|
|
// {
|
||
|
|
// //开启输入检测
|
||
|
|
// InputMgr.GetInstance().StartOrEndCheck(true);
|
||
|
|
// //添加事件监听
|
||
|
|
// EventCenter.GetInstance().AddEventListener<KeyCode>("KeyisDown", CheckInputDown);
|
||
|
|
// EventCenter.GetInstance().AddEventListener<KeyCode>("KeyisUp", CheckInputUp);
|
||
|
|
// }
|
||
|
|
// private void CheckInputDown(KeyCode obj)
|
||
|
|
// {
|
||
|
|
// switch (obj)
|
||
|
|
// {
|
||
|
|
// case KeyCode.W:
|
||
|
|
// Debug.Log("前进");
|
||
|
|
// break;
|
||
|
|
// case KeyCode.A:
|
||
|
|
// break;
|
||
|
|
// case KeyCode.S:
|
||
|
|
// break;
|
||
|
|
// case KeyCode.D:
|
||
|
|
// break;
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
// private void CheckInputUp(KeyCode obj)
|
||
|
|
// {
|
||
|
|
// switch (obj)
|
||
|
|
// {
|
||
|
|
// case KeyCode.W:
|
||
|
|
// Debug.Log("不再前进");
|
||
|
|
// break;
|
||
|
|
// case KeyCode.A:
|
||
|
|
// break;
|
||
|
|
// case KeyCode.S:
|
||
|
|
// break;
|
||
|
|
// case KeyCode.D:
|
||
|
|
// break;
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
// private void OnDestroy()
|
||
|
|
// {
|
||
|
|
// EventCenter.GetInstance().RemoveEventListener<KeyCode>("KeyisDown", CheckInputDown);
|
||
|
|
// EventCenter.GetInstance().RemoveEventListener<KeyCode>("KeyisUp", CheckInputUp);
|
||
|
|
// }
|
||
|
|
//}
|
||
|
|
|
||
|
|
#endregion
|