コガネブログ

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

【Unity】選択中のファイルの数を常に表示するエディタ拡張

ソースコード

using UnityEditor;
using UnityEngine;

public sealed class SelectedFilesCountWindow : EditorWindow
{
    private int m_count;

    [MenuItem( "Window/Selected Files Count" )]
    private static void Init()
    {
        var win = GetWindow<SelectedFilesCountWindow>( "Selected Files" );
        win.minSize = new Vector2( 32, 16 );
    }

    private void OnEnable()
    {
        Selection.selectionChanged += OnChanged;
    }

    private void OnDisable()
    {
        Selection.selectionChanged -= OnChanged;
    }

    private void OnChanged()
    {
        m_count = Selection.objects.Length;
        Repaint();
    }

    private void OnGUI()
    {
        GUILayout.Label( $"Selected Files: {m_count.ToString()}" );
    }
}

使い方

f:id:baba_s:20190921152701p:plain

Unity メニューの「Window > Selected Files Count」を選択すると

f:id:baba_s:20190921152703p:plain

選択中のファイルを常に表示するウィンドウを表示できます