16
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Unityのシーン一覧を取得する

Posted at

EditorBuildSettingsから拾う

using UnityEngine;
using UnityEditor;

[InitializeOnLoad]
public class SceneFinder
{
    static SceneFinder ()
    {
        Debug.Log ("-----  EditorSettings -----");
        foreach (var scene in EditorBuildSettings.scenes) {
            Debug.Log (scene);
        }
    }
}

ただし、この方法だとビルド設定で登録してあるシーンしか拾えない

ので、

AssetDatabaseから拾う

using UnityEngine;
using UnityEditor;

[InitializeOnLoad]
public class SceneFinder
{
    static SceneFinder ()
    {
        Debug.Log ("---- AssetDatabase ----");
        foreach (var guid in AssetDatabase.FindAssets("t:Scene")) {
            var path = AssetDatabase.GUIDToAssetPath (guid);
            Debug.Log (AssetDatabase.LoadMainAssetAtPath (path));
        }
    }
}

これならAssets配下に存在するシーンを全て取得できる。

他にはSystem.IO.Directoryを使ってシーンっぽいファイル名を検索しまくる、なんて方法もありそうですね。

16
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?