コガネブログ

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

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

ソースコード

using System;
using UnityEditor;
using UnityEngine;

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

    public override void OnInspectorGUI()
    {
        var animator = ( Animator ) target;

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

        var editor = CreateEditor( animator, BASE_EDITOR_TYPE );

        editor.OnInspectorGUI();
    }
}

使用例