OnBecameVisible and OnBecameInvisible are in the Unity docs as methods of the Renderer and MonoBehaviour classes. It turns out that they work for EditorWindows, too!
They get called when a docked window changes visibility; meaning that when a docked window is hidden by a sibling window within that dock, OnBecameInvisible gets called. Similarly, when the window becomes visible again, of course, OnBecameVisible is called.
using UnityEditor; using UnityEngine; public class OnBecameVisibleEditorWindow : EditorWindow { private void OnBecameVisible() { Debug.Log("Window is visible"); } private void OnBecameInvisible() { Debug.Log("Window is invisible"); } [MenuItem("Tools/OnBecameVisible Window")] public static void Init_ToolsMenu() { EditorWindow window = EditorWindow.GetWindow<OnBecameVisibleEditorWindow>(); window.title = "OnBecameVisible"; window.Show(); } }
There is a little gotcha, though. It seems that both methods get called when docking and undocking the window. Not sure why, really. It’s just another Unity quirk!
Posted on 2014-11-23, 12:28 am By Dean Lackey
No comments yet Categories: Unity Tips Tags: unity tips, unityeditor
Leave a Reply
You must be logged in to post a comment.