Created
August 14, 2020 08:27
-
-
Save baba-s/9f2a9d400966d6d4fcdc74ca37f4b8e8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 UnityEditor; | |
| using UnityEngine; | |
| namespace Kogane.Internal | |
| { | |
| [InitializeOnLoad] | |
| internal static class UILayerVisibleSwitcherOnSceneView | |
| { | |
| private const string BUTTON_TEXT = " UI "; | |
| private static readonly Rect m_buttonPosition = new Rect( 2, 2, 50, 20 ); | |
| private static readonly int m_uiLayerMask = LayerMask.GetMask( "UI" ); | |
| private static readonly GUIContent m_visibleContent = EditorGUIUtility.IconContent( "scenevis_visible_hover" ); | |
| private static readonly GUIContent m_hiddenContent = EditorGUIUtility.IconContent( "scenevis_hidden_hover" ); | |
| static UILayerVisibleSwitcherOnSceneView() | |
| { | |
| m_visibleContent.text = BUTTON_TEXT; | |
| m_hiddenContent.text = BUTTON_TEXT; | |
| SceneView.duringSceneGui += OnGUI; | |
| } | |
| private static void OnGUI( SceneView sceneView ) | |
| { | |
| Handles.BeginGUI(); | |
| var isVisible = ( Tools.visibleLayers & m_uiLayerMask ) != 0; | |
| var content = isVisible ? m_visibleContent : m_hiddenContent; | |
| if ( GUI.Button( m_buttonPosition, content ) ) | |
| { | |
| Tools.visibleLayers ^= m_uiLayerMask; | |
| SceneView.RepaintAll(); | |
| } | |
| Handles.EndGUI(); | |
| } | |
| } | |
| } |
Author
baba-s
commented
Aug 14, 2020

Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment