怎么找出 打了勾的场景呢?
方法1: 大家都知道可以代码写死
方法2: 因为我们知道这个文件是保存在
ProjectSettings\EditorBuildSettings.asset
打开后你可以看到.(注意把文件强制改成文本格式,不然你看到的是二进制)
const string BuildSceneName = "ProjectSettings/EditorBuildSettings.asset"; static string[] levels = null; public static string[] Levels { get { if (levels == null) { StreamReader sr = new StreamReader(BuildSceneName); string line = sr.ReadLine(); int index = 0; List<string> add = new List<string>(); while (true) { if (index < 6) { line = sr.ReadLine(); index += 1; continue; } line = sr.ReadLine(); if (line == null) break; line.Trim(); string[] st = line.Split(‘:‘); int num = int.Parse(st[1]); if (num == 1) { line = sr.ReadLine(); add.Add(line.Split(‘:‘)[1].Trim()); } else line = sr.ReadLine(); } string[] lvs = new string[add.Count]; for (int i = 0; i < add.Count; ++i) { lvs[i] = add[i]; } levels = lvs; } return levels; } }
第3种办法:
通过查文档 得到 , 上面的场景是否打钩 可以通过API 取到的.瞬间就简单了是不是?
static string[] GetBuildScenes() { List<string> names = new List<string>(); foreach(EditorBuildSettingsScene e in EditorBuildSettings.scenes) { if(e==null) continue; if(e.enabled) names.Add(e.path); } return names.ToArray(); }
时间: 2024-10-21 07:03:57