Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Syy9
Created July 28, 2018 07:32
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Syy9/c0df54799395f0437ef5933ac61ee374 to your computer and use it in GitHub Desktop.
Save Syy9/c0df54799395f0437ef5933ac61ee374 to your computer and use it in GitHub Desktop.
How to get Unity default EditorWindow (Game, Scene, Hierarchy...)
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);
}
}
(UnityEditor.GameView)
(UnityEditor.SceneView)
(UnityEditor.SceneHierarchyWindow)
(UnityEditor.ConsoleWindow)
(UnityEditor.InspectorWindow)
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