ソースコード
using System.IO; using System.Linq; using UnityEngine.SceneManagement; public static class Utils { public static bool CanLoadScene( string sceneName ) { return Enumerable .Range( 0, SceneManager.sceneCountInBuildSettings ) .Select( c => SceneUtility.GetScenePathByBuildIndex( c ) ) .Select( c => Path.GetFileNameWithoutExtension( c ) ) .Any( c => c == sceneName ) ; } }
使い方
var sceneName = "TitleScene"; if ( Utils.CanLoadScene( sceneName ) ) { SceneManager.LoadScene( sceneName ); }