コガネブログ

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

【Unity】選択中のフォルダとすべてのサブフォルダのパスを取得するエディタ拡張

概要

using System.Linq;
using UnityEditor;
using UnityEngine;

public class Example
{
    [MenuItem( "Tools/Hoge" )]
    private static void Hoge()
    {
        var paths = Selection
            .GetFiltered<DefaultAsset>( SelectionMode.DeepAssets )
            .Select( x => AssetDatabase.GetAssetPath( x ) )
            .Where( x => AssetDatabase.IsValidFolder( x ) )
            .ToArray();

        foreach ( var path in paths )
        {
            Debug.Log( path );
        }
    }
}