- Home /
How can I tell if the "Gizmos" button has been checked in the Game view?
I've got some lines that I'm rendering using the GL.* functions (I need to do this because I need the lines that I'm rendering to be depth tested). However, I'd like these lines to respect the "gizmos" option on the game view so I can use that to turn them on/off.
Is there any way to find out whether or not this button is pressed?
Answer by Edwin · Jan 06, 2011 at 05:34 PM
Well, here's one way:
bool AreGizmosVisible()
{
Assembly asm = Assembly.GetAssembly(typeof(UnityEditor.Editor));
Type type = asm.GetType("UnityEditor.GameView");
if (type != null)
{
EditorWindow window = EditorWindow.GetWindow(type);
FieldInfo gizmosField = type.GetField("m_Gizmos", BindingFlags.NonPublic | BindingFlags.Instance);
if(gizmosField != null)
return (bool)gizmosField.GetValue(window);
}
return false;
}
Of course, it could break if Unity changes, but it works in 3.1, and shouldn't go horribly wrong if the relevant private field is removed.
This caused extremely weird and confusing rendering glitches in my Unity editor that took me awhile to trace down. For example, when calling this once per frame game objects were no longer selectable and keyboard events like arrows didn't work. So be careful with this!
Your answer
Follow this Question
Related Questions
Editor Windows : Help required 1 Answer
Can't add script: The script is an editor script 2 Answers
Where can I find Unity's editor files? 1 Answer
Unity3d how to access Gizmos Tab in scene view via code 0 Answers
Gizmos icons 0 Answers