using System; using System.Collections.Generic; using System.IO; using UnityEngine; namespace Ether { public class EtherInputManager : SingletonAutoMono { private Dictionary> inputKeysDic; public override void Init() { LoadInputKeys(); } private void LoadInputKeys() { if (FileTools.FileExists(PathTools.EtherInputCfgPersistentPath)) { FileTools.ReadFileForJson(PathTools.EtherInputCfgPersistentPath, out inputKeysDic); } else { FileTools.ReadFileForJson(PathTools.EtherInputCfgDefaultPath, out inputKeysDic); } } private void Update() { if (inputKeysDic == null) { return; } foreach (var keyPair in inputKeysDic) { foreach (var keyCfg in keyPair.Value) { if (Input.GetKeyDown(keyCfg.KeyCode)) { Debug.Log("按下:" + keyCfg.KeyCode); foreach (var eventValue in keyCfg.EventList) { EventCenter.BroadCast(eventValue, true); } } if (Input.GetKeyUp(keyCfg.KeyCode)) { Debug.Log("抬起:" + keyCfg.KeyCode); foreach (var eventValue in keyCfg.EventList) { EventCenter.BroadCast(eventValue, false); } } } } } } }