using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; namespace uc { public class HotKeyManager : MonoBehaviour { [Serializable] public class HotKey { public enum HotKeyCallState { StandaloneOnly, EditorOnly, EditorAndStandalone } public bool enable = true; public HotKeyCallState m_CallState = HotKeyCallState.EditorAndStandalone; public KeyCode _keyCode = KeyCode.Space; public UnityEvent _keyDownEvent = new UnityEvent(); } public HotKey[] hotkeys; void Update() { foreach (var h in hotkeys) { bool isEditor = false; #if UNITY_EDITOR isEditor = true; #endif switch (h.m_CallState) { case HotKey.HotKeyCallState.StandaloneOnly: if (isEditor == true) continue; break; case HotKey.HotKeyCallState.EditorOnly: if (isEditor == false) continue; break; case HotKey.HotKeyCallState.EditorAndStandalone: break; } if (h.enable && Input.GetKeyDown(h._keyCode)) { h._keyDownEvent.Invoke(); } } } public void ExitApplication() { Application.Quit(); } } }