Created
September 16, 2015 10:28
-
-
Save kyubuns/04a4b80cfa7cb28d76bd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Reflection; | |
using UnityEditor; | |
using UnityEngine; | |
[InitializeOnLoad] | |
class SpaceSphere | |
{ | |
static SpaceSphere() | |
{ | |
// OnGlobalEventHandler | |
// from http://anchan828.hatenablog.jp/entry/2013/12/29/015306 | |
EditorApplication.CallbackFunction function = () => OnGlobalEventHandler (Event.current); | |
FieldInfo info = typeof(EditorApplication).GetField ("globalEventHandler", BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic); | |
EditorApplication.CallbackFunction functions = (EditorApplication.CallbackFunction)info.GetValue (null); | |
functions += function; | |
info.SetValue (null, (object)functions); | |
} | |
private static bool pressed; | |
private static Tool saved; | |
public static void OnGlobalEventHandler(Event e) | |
{ | |
if (!pressed && e.type == EventType.keyDown) | |
{ | |
if(e.keyCode == KeyCode.Space) | |
{ | |
pressed = true; | |
saved = Tools.current; | |
Tools.current = Tool.View; | |
} | |
} | |
if (pressed && e.type == EventType.keyUp) | |
{ | |
if(e.keyCode == KeyCode.Space) | |
{ | |
pressed = false; | |
Tools.current = saved; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment