コガネブログ

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

【Unity】PlayableDirector の Inspector に Timeline ウィンドウを開くボタンを追加するエディタ拡張

ソースコード

using System;
using UnityEditor;
using UnityEngine;
using UnityEngine.Playables;

[CustomEditor( typeof( PlayableDirector ) )]
public sealed class PlayableDirectorInspector : Editor
{
    private static readonly Type BASE_EDITOR_TYPE = typeof( Editor )
        .Assembly
        .GetType( "UnityEditor.DirectorEditor" );

    public override void OnInspectorGUI()
    {
        var playableDirector = ( PlayableDirector ) target;

        using ( new EditorGUILayout.HorizontalScope() )
        {
            if ( GUILayout.Button( "Open Timeline Window" ) )
            {
                EditorApplication.ExecuteMenuItem( "Window/Sequencing/Timeline" );
            }
        }

        var editor = CreateEditor( playableDirector, BASE_EDITOR_TYPE );

        editor.OnInspectorGUI();
    }
}

使用例