Advertisement
Mikilo

Unity Tips - Editor keyboard input catch

Mar 28th, 2019
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 KB | None | 0 0
  1. using System;
  2. using System.Reflection;
  3. using UnityEditor;
  4. using UnityEngine;
  5.  
  6. public static class Test
  7. {
  8.     static Test()
  9.     {
  10.         FieldInfo globalEventHandler = typeof(EditorApplication).GetField("globalEventHandler", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
  11.  
  12.         if (globalEventHandler != null)
  13.         {
  14.             MethodInfo method = typeof(Test).GetMethod("HandleKeyboardInput", BindingFlags.Static | BindingFlags.NonPublic);
  15.             if (method != null)
  16.                 globalEventHandler.SetValue(null, Delegate.Combine((Delegate)globalEventHandler.GetValue(null), Delegate.CreateDelegate(globalEventHandler.FieldType, null, method)));
  17.         }
  18.     }
  19.  
  20.     private static void HandleKeyboardInput()
  21.     {
  22.         Debug.Log(Event.current);
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement