Unity・3DCG技術ブログ

TAもどきによるUnity・3DCGに関する記事をアップします。

【Unity】GetWindowで特定のEditorWindowの隣にEditorWindowをこさせるサンプル

概要

EditorWindow.GetWindowの引数desiredDockNextTotypeofでタイプを指定すると、そのタイプの隣に ウィンドウがくるサンプル。

f:id:serialtv:20200719183702p:plain

コード

using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;

public class ExampleWindow : EditorWindow
{
    [MenuItem("Window/ExampleWindow")]
    static void Init()
    {
        // SceneViewの隣にExampleWindowがドックする。
        GetWindow<ExampleWindow>(desiredDockNextTo: typeof(SceneView));
    }

    void OnEnable()
    {
        var button1 = new Button(() => Debug.Log("button1"))
        {
            name = "button1",
            text = "button1"
        };
        rootVisualElement.Add(button1);
    }
}