Created
December 20, 2016 17:45
-
-
Save nothke/74236859b5ec3acea8a1318e28d0a228 to your computer and use it in GitHub Desktop.
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; | |
[CustomEditor(typeof(ContextDummy))] | |
public class ContextDummyEditor : Editor | |
{ | |
Event prevMouseEvent; | |
bool contextIsOpen; | |
void OnSceneGUI() | |
{ | |
Event currentEvent = Event.current; | |
/* | |
if (currentEvent.isMouse) | |
Debug.Log("Current event: " + Event.current); | |
Debug.Log("id: " + GUIUtility.hotControl); | |
*/ | |
// After exiting the generic menu: | |
if (currentEvent.type == EventType.mouseDown | |
&& contextIsOpen) | |
{ | |
Debug.Log("Exited context"); | |
// RENABLE SCENE CONTROLS ???? | |
//currentEvent.type = EventType.DragExited; | |
//Event.current.type = EventType.Layout; | |
EditorGUIUtility.hotControl = 0; | |
HandleUtility.Repaint(); | |
SceneView.RepaintAll(); | |
contextIsOpen = false; | |
currentEvent.Use(); | |
} | |
// Show context menu: | |
if (currentEvent.isMouse | |
&& currentEvent.type == EventType.mouseUp | |
&& currentEvent.button == 1 | |
&& prevMouseEvent.type != EventType.mouseDrag) | |
{ | |
Debug.Log("Current event is: " + Event.current + " and last swas: " + prevMouseEvent); | |
Debug.Log("Opened context"); | |
DisplayContext(currentEvent.mousePosition); | |
currentEvent.Use(); | |
// GUIUtility.hotControl = 0; | |
} | |
if (currentEvent != null && currentEvent.isMouse) | |
prevMouseEvent = new Event(currentEvent); | |
} | |
void DisplayContext(Vector2 at) | |
{ | |
contextIsOpen = true; | |
GenericMenu menu = new GenericMenu(); | |
menu.AddItem(new GUIContent("IN Connect to closest"), false, Callback, "item 1"); | |
menu.AddItem(new GUIContent("OUT Connect to closest"), false, Callback, "item 2"); | |
menu.AddSeparator(""); | |
menu.AddItem(new GUIContent("SubMenu/MenuItem3"), false, Callback, "item 3"); | |
menu.ShowAsContext(); | |
} | |
void Callback(object obj) | |
{ | |
Debug.Log("Selected: " + obj); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment