Created
February 7, 2018 15:55
-
-
Save simonwittber/3439b68cd341c1ed8f453a23baef038f to your computer and use it in GitHub Desktop.
Add an "OnContextClick" message to any open Unity Editors.
This file contains 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 UnityEngine; | |
using System.Collections; | |
using UnityEditor; | |
using System.Reflection; | |
[InitializeOnLoad] | |
public static class SceneContext | |
{ | |
static System.Diagnostics.Stopwatch clickClock; | |
static SceneContext() | |
{ | |
clickClock = new System.Diagnostics.Stopwatch(); | |
SceneView.onSceneGUIDelegate -= OnSceneGUI; | |
SceneView.onSceneGUIDelegate += OnSceneGUI; | |
} | |
static void OnSceneGUI(SceneView sceneview) | |
{ | |
if (Event.current.button == 1) | |
{ | |
if (Event.current.type == EventType.MouseDown) | |
clickClock.Start(); | |
if (Event.current.type == EventType.MouseUp) | |
{ | |
clickClock.Stop(); | |
var period = clickClock.ElapsedMilliseconds; | |
clickClock.Reset(); | |
if (period < 300) | |
{ | |
EditorApplication.delayCall += OnContextClick; | |
Event.current.Use(); | |
} | |
} | |
} | |
} | |
static void OnContextClick() | |
{ | |
foreach (var i in Resources.FindObjectsOfTypeAll<Editor>()) | |
{ | |
var mi = i.GetType().GetMethod("OnContextClick", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); | |
if (mi != null) | |
mi.Invoke(i, null); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment