うにてぃブログ

主にUnityとC#に関する記事を書いていきます

【Unity】UnityEditor で Unityデフォルトの EditorWindow を取得する

EditorWindow を取得する方法として EditorWindow.GetWindow があるが
これはすでに EditorWindow を開いていた場合でも新しく EditorWindowを作成してしまう

すでに開いている EditorWindow を確認する方法として以下がある

var findSceneView = Resources.FindObjectsOfTypeAll(typeof(SceneView));
sceneView = findSceneView.Length <= 0
    ? GetWindow(typeof(SceneView)) as SceneView
    : findSceneView[0] as SceneView;

しかしながら Unityデフォルトの EditorWindow を使いたくても
ほとんどが internal クラスのため無理やり取得する必要があるため
Type を 取得しなければいけない

各種EditorWindowのType取得方法

下記を利用して取得した Type を利用すると EditorWindowを容易に取得できる

  • typeof(EditorWindow).Assembly.GetType("UnityEditor.SceneHierarchyWindow"))
  • typeof(EditorWindow).Assembly.GetType("UnityEditor.GameView")
  • typeof(EditorWindow).Assembly.GetType("UnityEditor.SceneView")
  • typeof(EditorWindow).Assembly.GetType("UnityEditor.ProjectBrowser")
  • typeof(EditorWindow).Assembly.GetType("UnityEditor.ConsoleWindow")
  • typeof(EditorWindow).Assembly.GetType("UnityEditor.InspectorWindow")
  • typeof(EditorWindow).Assembly.GetType("UnityEditor.AnimationWindow")
  • typeof(EditorWindow).Assembly.GetType("UnityEditor.ProfilerWindow")
  • typeof(EditorWindow).Assembly.GetType("UnityEditor.AssetStoreWindow")
  • typeof(EditorWindow).Assembly.GetType("UnityEditor.FrameDebuggerWindow")
  • typeof(UnityEditor.Graphs.Graph).Assembly.GetType("UnityEditor.Graphs.AnimatorControllerTool")
  • typeof(UnityEditor.Sprites.Packer).Assembly.GetType("UnityEditor.Sprites.PackerWindow")