Skip to content

Instantly share code, notes, and snippets.

@kyubuns
Created September 16, 2015 10:28
Show Gist options
  • Save kyubuns/04a4b80cfa7cb28d76bd to your computer and use it in GitHub Desktop.
Save kyubuns/04a4b80cfa7cb28d76bd to your computer and use it in GitHub Desktop.
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