How to get Unity default EditorWindow (Game, Scene, Hierarchy...)
This file contains 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 System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEditor; | |
using System.IO; | |
using System.Text; | |
public class _CheckTool { | |
[MenuItem("CheckTool/Check")] | |
public static void Check() | |
{ | |
StringBuilder sb = new StringBuilder(); | |
var game = UnityEditorWindowHelper.GetWindow(WindowType.Game); | |
sb.AppendLine(game.ToString()); | |
var scene = UnityEditorWindowHelper.GetWindow(WindowType.Scene); | |
sb.AppendLine(scene.ToString()); | |
var hierarchy = UnityEditorWindowHelper.GetWindow(WindowType.Hierarchy); | |
sb.AppendLine(hierarchy.ToString()); | |
var console = UnityEditorWindowHelper.GetWindow(WindowType.Console); | |
sb.AppendLine(console.ToString()); | |
var inspector = UnityEditorWindowHelper.GetWindow(WindowType.Inspector); | |
sb.AppendLine(inspector.ToString()); | |
Write(sb.ToString()); | |
} | |
private static void Write(string output) | |
{ | |
StreamWriter writer = new StreamWriter("Assets/result.txt", false); | |
writer.Write(output); | |
writer.Close(); | |
Debug.Log(output); | |
} | |
} |
This file contains 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
(UnityEditor.GameView) | |
(UnityEditor.SceneView) | |
(UnityEditor.SceneHierarchyWindow) | |
(UnityEditor.ConsoleWindow) | |
(UnityEditor.InspectorWindow) |
This file contains 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 UnityEngine; | |
using UnityEditor; | |
using System; | |
public enum WindowType | |
{ | |
Game, | |
Scene, | |
Hierarchy, | |
Console, | |
Inspector, | |
} | |
public static class UnityEditorWindowHelper | |
{ | |
public static EditorWindow GetWindow(WindowType windowType) | |
{ | |
var assembly = typeof(UnityEditor.EditorWindow).Assembly; | |
var type = assembly.GetType(Convert(windowType)); | |
return EditorWindow.GetWindow(type); | |
} | |
private static string Convert(WindowType windowType) | |
{ | |
string name = string.Empty; | |
switch (windowType) | |
{ | |
case WindowType.Game: | |
name = "UnityEditor.GameView"; | |
break; | |
case WindowType.Scene: | |
name = "UnityEditor.SceneView"; | |
break; | |
case WindowType.Hierarchy: | |
name = "UnityEditor.SceneHierarchyWindow"; | |
break; | |
case WindowType.Console: | |
name = "UnityEditor.ConsoleWindow"; | |
break; | |
case WindowType.Inspector: | |
name = "UnityEditor.InspectorWindow"; | |
break; | |
default: | |
throw new NotImplementedException(); | |
} | |
return name; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment