欢迎加入Unity业内qq交流群:956187480
qq扫描二维码加群
Event是基于GUI的事件检测,所以我们的组合键逻辑要在OnGUI里面编写
private void OnGUI()
{
//获取当前事件的类型
if (Event.current.rawType == EventType.KeyDown)
{
EventCallBack(Event.current);
}
}
private void EventCallBack(Event current)
{
if (current.modifiers == EventModifiers.Control)
{
if (current.keyCode== KeyCode.Q)
{
Debug.Log("按下组合键:Control+" + current.keyCode);
}
}
if (current.modifiers == EventModifiers.Shift)
{
if (current.keyCode == KeyCode.W)
{
Debug.Log("按下组合键:Shift+" + current.keyCode);
}
}
if (current.modifiers == EventModifiers.Alt)
{
if (current.keyCode == KeyCode.E)
{
Debug.Log("按下组合键:Alt+" + current.keyCode);
}
}
}