Guest User

Untitled

a guest
Dec 15th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. using System.IO;
  2. using System.Linq;
  3. using UnityEditor;
  4. using UnityEngine;
  5.  
  6. public class BuildSettingScenesCreator
  7. {
  8. private const string sceneDir = "Scenes";
  9. private const string initialLoadScene = "Scenes/Title.unity";
  10.  
  11. [MenuItem("Edit/BuildSettings/CreateScenes")]
  12. public static void CreateBuildSettingScenes()
  13. {
  14. if (!CheckExists())
  15. {
  16. return;
  17. }
  18.  
  19. Create();
  20. }
  21.  
  22. private static bool CheckExists()
  23. {
  24. string sceneDirFullPath = GetFullPath(sceneDir);
  25. string initialLoadSceneFullPath = GetFullPath(initialLoadScene);
  26.  
  27. // 存在チェック
  28. if (!Directory.Exists(sceneDirFullPath))
  29. {
  30. Debug.LogError("Not Found Dir :" + sceneDirFullPath);
  31. return false;
  32. }
  33.  
  34. if (!File.Exists(initialLoadSceneFullPath))
  35. {
  36. Debug.LogError("Not Found Inital Load Scene : " + initialLoadSceneFullPath);
  37. return false;
  38. }
  39.  
  40. return true;
  41. }
  42.  
  43. private static void Create()
  44. {
  45. string sceneDirAssetsPath = GetAssetsPath(sceneDir);
  46. string initialLoadSceneAssetsPath = GetAssetsPath(initialLoadScene);
  47.  
  48. var scenes = AssetDatabase.FindAssets("t:Scene", new string[] {sceneDirAssetsPath})
  49. .Select(guid => AssetDatabase.GUIDToAssetPath(guid))
  50. .OrderBy(path => path)
  51. .Where(path => path != initialLoadSceneAssetsPath)
  52. .Select(path => new EditorBuildSettingsScene(path, true))
  53. .ToList();
  54.  
  55. // 初回に呼び込まれて欲しいシーンを先頭に配置する
  56. scenes.Insert(0, new EditorBuildSettingsScene(initialLoadSceneAssetsPath, true));
  57.  
  58. EditorBuildSettings.scenes = scenes.ToArray();
  59. AssetDatabase.SaveAssets();
  60.  
  61. Debug.Log("Created BuildSettings.");
  62. }
  63.  
  64. private static string GetFullPath(string path)
  65. {
  66. return Application.dataPath + "/" + path;
  67. }
  68.  
  69. private static string GetAssetsPath(string path)
  70. {
  71. return "Assets/" + path;
  72. }
  73. }
Add Comment
Please, Sign In to add comment