Skip to content

Instantly share code, notes, and snippets.

@mminer
Created October 7, 2021 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mminer/1fca7d7c66567991746f24a4797e92db to your computer and use it in GitHub Desktop.
Save mminer/1fca7d7c66567991746f24a4797e92db to your computer and use it in GitHub Desktop.
Gets a reference to the main Unity editor window.
static Object GetMainEditorWindow()
{
var containerWindowType = typeof(EditorWindow).Assembly.GetType("UnityEditor.ContainerWindow");
var showModeField = containerWindowType.GetField("m_ShowMode", BindingFlags.Instance | BindingFlags.NonPublic);
return Resources
.FindObjectsOfTypeAll(containerWindowType)
.First(window => (int)showModeField.GetValue(window) == 4);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment