在unity3D5.x版本中,一部分以前的代码无法正常运行,比如:加载场景时,使用Application.loadedLevel会提示“已过时”,需要使用EditorSceneManager.OpenScene(FileName[scount]);所以写一篇记录下在新版本环境实现一些功能的笔记(一些没变化)。
一.获取当前场景所有Tag
想要获取场景(多个场景)的Tag,需要先加载场景,我是想要做一个插件,能让使用者一键获取项目中所有的场景,并读取场景中对应的Tag。那么就需要遍历项目中的场景,一般项目中都会把场景存放在Scenes文件夹下
所以读取指定文件夹下所有文件即可
//获取文件路径
string DPath = Application.dataPath;
int num = DPath.LastIndexOf("/");
DPath = DPath.Substring(0, num);
DPath = DPath + "/Assets/Scenes";
//读取文件夹下的所有对象存到数组中
List<string> filename = new List<string>();
if (Directory.Exists(DPath))
{
DirectoryInfo direction = new DirectoryInfo(DPath);
FileInfo[] files = direction.GetFiles("*", SearchOption.AllDirectories);