コガネブログ

平日更新を目標に Unity や C#、Visual Studio、ReSharper などのゲーム開発アレコレを書いていきます

【Unity】EditorWindow で UIElements を構築するスクリプトを書く場合は CreateGUI 関数を使用する

概要

CreateGUI is called when the EditorWindow's rootVisualElement is ready to be populated.

CreateGUI 関数は EditorWindow の rootVisualElement が
操作できるようになるタイミングで呼び出される

using UnityEditor;
using UnityEngine.UIElements;

public class Example : EditorWindow
{
    [MenuItem( "Tools/Hoge" )]
    private static void Open()
    {
        GetWindow<Example>();
    }

    private void CreateGUI()
    {
        rootVisualElement.Add( new Label( "ピカチュウ" ) );
    }
}

参考サイト様