Skip to content

Instantly share code, notes, and snippets.

@yasirkula

yasirkula/UIToggler.cs

Last active Jan 11, 2020
Embed
What would you like to do?
Quickly toggle the visibility of UI layer (canvases) in Unity's Scene view
using UnityEditor;
using UnityEngine;
public class UIToggler
{
private const int UI_LAYER = 1 << 5;
[InitializeOnLoadMethod]
private static void Init()
{
#if UNITY_2019_1_OR_NEWER
SceneView.duringSceneGui -= OnSceneGUI;
SceneView.duringSceneGui += OnSceneGUI;
#else
SceneView.onSceneGUIDelegate -= OnSceneGUI;
SceneView.onSceneGUIDelegate += OnSceneGUI;
#endif
}
private static void OnSceneGUI( SceneView sceneView )
{
Handles.BeginGUI();
bool uiVisible = ( Tools.visibleLayers & UI_LAYER ) == UI_LAYER;
if( GUI.Button( new Rect( 0f, 0f, 125f, 25f ), uiVisible ? "Hide Canvas" : "Show Canvas" ) )
{
if( uiVisible )
Tools.visibleLayers &= ~UI_LAYER;
else
Tools.visibleLayers |= UI_LAYER;
}
Handles.EndGUI();
}
}
@yasirkula

This comment has been minimized.

Copy link
Owner Author

@yasirkula yasirkula commented Dec 9, 2019

How To

Simply create a folder called Editor inside your Project window and add this script inside it. Then, click the small button at the top left corner of the Scene view to toggle the UI objects' visibility in Scene view.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.