Created
December 13, 2017 14:51
-
-
Save lycoris102/cf16ef82419e3184604f681a94090fd9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.IO; | |
using System.Linq; | |
using UnityEditor; | |
using UnityEngine; | |
public class BuildSettingScenesCreator | |
{ | |
private const string sceneDir = "Scenes"; | |
private const string initialLoadScene = "Scenes/Title.unity"; | |
[MenuItem("Edit/BuildSettings/CreateScenes")] | |
public static void CreateBuildSettingScenes() | |
{ | |
if (!CheckExists()) | |
{ | |
return; | |
} | |
Create(); | |
} | |
private static bool CheckExists() | |
{ | |
string sceneDirFullPath = GetFullPath(sceneDir); | |
string initialLoadSceneFullPath = GetFullPath(initialLoadScene); | |
// 存在チェック | |
if (!Directory.Exists(sceneDirFullPath)) | |
{ | |
Debug.LogError("Not Found Dir :" + sceneDirFullPath); | |
return false; | |
} | |
if (!File.Exists(initialLoadSceneFullPath)) | |
{ | |
Debug.LogError("Not Found Inital Load Scene : " + initialLoadSceneFullPath); | |
return false; | |
} | |
return true; | |
} | |
private static void Create() | |
{ | |
string sceneDirAssetsPath = GetAssetsPath(sceneDir); | |
string initialLoadSceneAssetsPath = GetAssetsPath(initialLoadScene); | |
var scenes = AssetDatabase.FindAssets("t:Scene", new string[] {sceneDirAssetsPath}) | |
.Select(guid => AssetDatabase.GUIDToAssetPath(guid)) | |
.OrderBy(path => path) | |
.Where(path => path != initialLoadSceneAssetsPath) | |
.Select(path => new EditorBuildSettingsScene(path, true)) | |
.ToList(); | |
// 初回に呼び込まれて欲しいシーンを先頭に配置する | |
scenes.Insert(0, new EditorBuildSettingsScene(initialLoadSceneAssetsPath, true)); | |
EditorBuildSettings.scenes = scenes.ToArray(); | |
AssetDatabase.SaveAssets(); | |
Debug.Log("Created BuildSettings."); | |
} | |
private static string GetFullPath(string path) | |
{ | |
return Application.dataPath + "/" + path; | |
} | |
private static string GetAssetsPath(string path) | |
{ | |
return "Assets/" + path; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment