public IEnumerator BeginCheckInput() { //延迟一帧再设置为true yieldreturn0; isBeginCheckInput = true; }
privatevoidInputUpdate() { //如果外部未开启检测功能,就不检测输入 if (!isCheckInput) return;
//当委托不为空时,证明想要获取到输入的消息传递给外部 if (isBeginCheckInput) { if (Input.anyKeyDown) { InputInfo inputInfo = null; Array keyCodes = Enum.GetValues(typeof(KeyCode)); foreach (KeyCode inputKey in keyCodes) { //判断到底是谁被按下了,通过这个的带对应的输入的键盘信息 if (Input.GetKeyDown(inputKey)) { inputInfo = new InputInfo(InputInfo.E_InputType.Down, inputKey); break; } } for (int i = 0; i < 3; i++) { if (Input.GetMouseButtonDown(i)) { inputInfo = new InputInfo(InputInfo.E_InputType.Down, i); break; } } //把获取到的消息传递到外部,并清空委托 getInputInfoCallBack.Invoke(inputInfo); getInputInfoCallBack = null; //检测一次后就停止检测 isBeginCheckInput = false; } }
foreach (E_EventType eventType in inputDic.Keys) { nowInputInfo = inputDic[eventType]; //如果是键盘输入 if (nowInputInfo.keyOrMouse == InputInfo.E_KeyOrMouse.Key) { //根据输入类型检测对应的输入,传入输入消息设置的键位 switch (nowInputInfo.inputType) { case InputInfo.E_InputType.Down: if (Input.GetKeyDown(nowInputInfo.key)) EventCenter.Instance.EventTrigger(eventType); break; case InputInfo.E_InputType.Up: if (Input.GetKeyUp(nowInputInfo.key)) EventCenter.Instance.EventTrigger(eventType); break; case InputInfo.E_InputType.Always: if (Input.GetKey(nowInputInfo.key)) EventCenter.Instance.EventTrigger(eventType); break; } } //如果是鼠标输入 elseif (nowInputInfo.keyOrMouse == InputInfo.E_KeyOrMouse.Mouse) { //根据输入类型检测对应的输入,传入输入消息设置的键位 switch (nowInputInfo.inputType) { case InputInfo.E_InputType.Down: if (Input.GetMouseButtonDown(nowInputInfo.mouseID)) EventCenter.Instance.EventTrigger(eventType); break; case InputInfo.E_InputType.Up: if (Input.GetMouseButtonUp(nowInputInfo.mouseID)) EventCenter.Instance.EventTrigger(eventType); break; case InputInfo.E_InputType.Always: if (Input.GetMouseButton(nowInputInfo.mouseID)) EventCenter.Instance.EventTrigger(eventType); break; } } }