-
Notifications
You must be signed in to change notification settings - Fork 341
Expand file tree
/
Copy pathGlobalInputEvent.cs
More file actions
70 lines (64 loc) · 2.29 KB
/
GlobalInputEvent.cs
File metadata and controls
70 lines (64 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEditor;
using UnityEngine;
namespace ToolKits
{
public class GlobalInputEvent
{
private static bool isSpaceDown = false;
[InitializeOnLoadMethod]
public static void EditorInitialize()
{
// globalEventHandler
FieldInfo info = typeof(EditorApplication).GetField("globalEventHandler",
BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic);
EditorApplication.CallbackFunction functions = (EditorApplication.CallbackFunction) info.GetValue(null);
functions -= OnGlobalEventHandler;
if (EditorPrefs.GetBool(Constants.GLOBAL_INPUT_ENEVT_ENABLE, false))
{
functions += OnGlobalEventHandler;
info.SetValue(null, (object) functions);
}
info.SetValue(null, (object) functions);
}
private static void OnGlobalEventHandler()
{
var e = Event.current;
if (null != e)
{
if (e.isKey)
{
if (e.keyCode == KeyCode.Space)
{
isSpaceDown = e.type != EventType.KeyUp;
}
if (e.type == EventType.KeyUp)
{
if (e.keyCode == KeyCode.A && isSpaceDown)
{
Debug.LogError("组合键:空格 + A");
}
else if (e.keyCode == KeyCode.S && isSpaceDown)
{
Debug.LogError("组合键:空格 + S");
}
}
else if (e.type == EventType.KeyDown)
{
if (e.keyCode == KeyCode.UpArrow)
{
Debug.LogError("组合键:空格+上箭头");
}
else if (e.keyCode == KeyCode.DownArrow)
{
Debug.LogError("组合键:空格+下箭头");
}
}
}
}
}
}
}