- Home /
Scene view controls locking up > trying to make scene view generic menu on right click
This gif explains it all:
I want to implement the generic menu into scene view when an object with component is selecte, and all goes well, except that when I exit it, the scene controls completely lock up with "rotate view" cursor showing, but not working.
Is there some kind of RefreshSceneControls() function that I'm missing that could be called when I exit the menu?
here's my editor class (the target class is empty, just a dummy for testing):
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);
}
}
Your answer
Follow this Question
Related Questions
Invert DrawLine direction in editor Window. 1 Answer
Using Handles.DrawAAPolyLine 1 Answer
Rect Handle for custom inspector 0 Answers
Editor Scripting: best way to change variables of a custom editor? 2 Answers
Responsive Editor UI Button with custom style | How to remove GUIStyle.hover delay 0 Answers