You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.6 KiB

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();
}
}
}