Unity自动添加场景到BuildSettings

using UnityEngine;
using System.Collections;
using UnityEditor;
using System.Collections.Generic;
using System.IO;
public class Easy : Editor {

   [MenuItem("Tools/同步所有场景到SceneSetting文件")]
   static void CheckSceneSetting()
   {
    List dirs = new List();
    GetDirs(Application.dataPath,ref dirs);
    EditorBuildSettingsScene[] newSettings = new EditorBuildSettingsScene[dirs.Count];
    for(int i =0; i< newSettings.Length;i++)
    {
        newSettings[i] = new EditorBuildSettingsScene(dirs[i],true);
    }
    EditorBuildSettings.scenes = newSettings;
    EditorApplication.SaveAssets();
   }
    private static void GetDirs(string dirPath, ref List dirs)
   {
    foreach (string path in Directory.GetFiles(dirPath))
    {
        if(System.IO.Path.GetExtension(path) == ".unity") 
        {
            dirs.Add(path.Substring(path.IndexOf("Assets/")));
        }
    }
    if (Directory.GetDirectories(dirPath).Length > 0)
    {
        foreach (string path in Directory.GetDirectories(dirPath))
            GetDirs(path,ref dirs);
    }
 }
}

你可能感兴趣的:(Unity自动添加场景到BuildSettings)