Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Finding what editor window is focused c#

Discussion in 'Scripting' started by unityplanetarium, Jul 29, 2020.

  1. unityplanetarium

    unityplanetarium

    Joined:
    Apr 15, 2020
    Posts:
    16
    Hi, I am making a custom editor window for a project and I am trying to get the currently focused editor window to see if its either an inspector window or the scene window.

    I have been using
    Code (CSharp):
    1. if (EditorWindow.focusedWindow.title == "Inspector")
    2. {
    3.      do something here
    4. }
    however in unity it throughs a warning

    Code (CSharp):
    1. warning CS0618: 'EditorWindow.title' is obsolete: 'Use titleContent instead (it supports setting a title icon as well).'
    it works as expected however I would
    1.Prefer to change over to titleContent, however the docs are non existant and all other searches for this return how to set the title and icon and not how to get and compare.
    2.Stop the message showing as the functionality works as expected (why break something if it works... just dont know for how long it will work though)
    3. A different way to find and compare the focused window?
     
  2. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    10,004
    You either use reflection (since most of the built-in windows are internal or use string comparison:
    Code (CSharp):
    1. UnityEditor.EditorWindow.focusedWindow.ToString() == "Something"
    If you Debug.Log out the focusedWindow.ToString() and you click through all the windows you can explore what they give you back. Usually the namespace like UnityEditor.SceneHierarchyWindow.
     
    unityplanetarium likes this.
  3. unityplanetarium

    unityplanetarium

    Joined:
    Apr 15, 2020
    Posts:
    16