コガネブログ

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

【Unity】Unity プロジェクトに含まれているすべてのシーンファイルのパスを取得するエディタ拡張のサンプル

方法1

using System.Linq;
using UnityEditor;
using UnityEngine;

public static class Example
{
    [MenuItem( "Tools/Hoge" )]
    private static void Hoge()
    {
        var list = AssetDatabase
            .FindAssets( "t:scene" )
            .Select( AssetDatabase.GUIDToAssetPath )
        ;

        foreach ( var n in list )
        {
            Debug.Log( n );
        }
    }
}

おそらく Project ビューの順番通りの並びで取得できる

方法2

using System.Linq;
using UnityEditor;
using UnityEngine;

public static class Example
{
    [MenuItem( "Tools/Hoge" )]
    private static void Hoge()
    {
        var list = AssetDatabase
            .GetAllAssetPaths()
            .Where( c => c.EndsWith( ".unity" ) )
        ;

        foreach ( var n in list )
        {
            Debug.Log( n );
        }
    }
}

おそらく Project ビューの順番通りの並びにならない