【Unity】複数Inspectorウィンドウのスクロールを同期するエディター拡張
3387 ワード
はじめに
Inspectorウィンドウのスクロール位置を変更した時、
他のウィンドウも同じ位置までスクロールさせるエディター拡張を作ってみました。
Unity2018.2.0f2で動作確認済みです
InspectorウィンドウのカスタマイズTips
開いている全てのインスペクタを取得する
// InspectorウィンドウのTypeを取得
s_TypeInspectorWindow = Assembly.Load("UnityEditor.dll").GetType("UnityEditor.InspectorWindow");
// 全てのInspectorウィンドウを取得
return (EditorWindow[])Resources.FindObjectsOfTypeAll(s_TypeInspectorWindow);
Inspectorウィンドウの内部実装を見る方法
// InspectorウィンドウのTypeを取得
s_TypeInspectorWindow = Assembly.Load("UnityEditor.dll").GetType("UnityEditor.InspectorWindow");
// 全てのInspectorウィンドウを取得
return (EditorWindow[])Resources.FindObjectsOfTypeAll(s_TypeInspectorWindow);
Unityテクノロジーズが公開しているGitHubからInspectorウィンドウのソースコードが確認できます。
Inspectorウィンドウはクラスそのものが非公開となっているため、情報を取得したい場合はリフレクション経由で呼び出すことになります。
インスペクタが表示しているオブジェクトの取得
InspectorWindowクラスのGetInspectedObject()メソッドを実行すると、Inspectorウィンドウが表示しているオブジェクトを取得できます。
var k_GetFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
// GetInspectedObjectメソッドの取得
var method = s_TypeInspectorWindow.GetMethod("GetInspectedObject", k_GetFlags);
// メソッド実行してInspectorが表示するオブジェクトを取得
return method.Invoke(inspector, null);
Author And Source
この問題について(【Unity】複数Inspectorウィンドウのスクロールを同期するエディター拡張), 我々は、より多くの情報をここで見つけました https://qiita.com/r-ngtm/items/41a4582646d21deb3486著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .