using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; [Serializable] public struct KeyPressAction { [SerializeField] private KeyCode keyCode; [SerializeField] private UnityEvent action; public KeyCode KeyCode => keyCode; public UnityEvent Action => action; } public class UnityKeyPressHandler : MonoBehaviour { #region Inspector Properties [Header("Config Values")] [SerializeField] private List keyPressActions; #endregion #region Public Properties #endregion #region Private Properties #endregion #region Framework Functions void Update() { if (Application.isEditor) { this.checkForUnityKeyPress(); } } #endregion #region Events #endregion #region Public Functions #endregion #region Private Functions private void checkForUnityKeyPress() { foreach (KeyPressAction action in this.keyPressActions) { if (Input.GetKeyDown(action.KeyCode)) { action.Action.Invoke(); } } } #endregion }