8
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Preference ウィンドウをドッキング可能な状態で開く

Posted at

#概要
Preferencesウィンドウをちょこちょこいじる為、Preferencesウィンドウを常に表示しておきたいのですが、
普通に開くとドッキングできないフローティングウィンドウとして開かれるため、常に開いておくと少し邪魔な感じがします。
SceneViewやInspectorのように、ドッキング可能なウィンドウとして開けないかと試してみました。

#Preferencesウィンドウのクラス名は…
EditorWindowであれば、クラス名がわかれば
EditorWindow.GetWindow
を使って、ドッキング可能なウィンドウとして開くことができるのでは、と考えました。

幸い、フォーカスしているウィンドウ、もしくはマウスオーバーしたウィンドウのクラスを調べられるものがEditorWindowにあるため、
これを利用してクラス名を調べました。
EditorWindow.mouseOverWindow
EditorWindow.focusedWindow

調べてみたところ、UnityEditor.PreferencesWindowと言うクラス名のようです。
001.png

#ドッキング可能ウィンドウとして開く
クラス名がわかったので、早速開こう…と思ったのですが、そのまま

EditorWindow.GetWindow(typeof(UnityEditor.PreferencesWindow));

としても、PreferencesWindowが見つからずにエラーになります。
仕方がないので、Reflectionを使用してUnityEditor.PreferencesWindowを取得してウィンドウを開きます。

using UnityEngine;
using UnityEditor;
using System.Reflection;

public class DockablePreferencesWindow : Editor
{
	[MenuItem("Window/Open Dockable Preferences")]
	static void OpenDockablePreferences()
	{
		var asm = Assembly.Load("UnityEditor");
		var pref_win_type = asm.GetType("UnityEditor.PreferencesWindow");
		EditorWindow.GetWindow(pref_win_type, false, "Preferences");
	}
}

これでドッキング可能なウィンドウとしてPreferencesウィンドウを開くことができました。やったね!
002.png

8
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?