给场景自动添加AssetBundleName

来源:互联网 发布:实用五金工具手册软件 编辑:程序博客网 时间:2024/05/16 17:20
[MenuItem("Tools/Auto Scene Bundle")]static void AutoSceneBundleName(){List<string> filesPaths = new List<string>();  filesPaths.AddRange(  Directory.GetFiles(Path.GetFullPath(".") + Path.DirectorySeparatorChar, "*.unity", SearchOption.AllDirectories)  );  int counter = -1;  foreach (string filePath in filesPaths) {  EditorUtility.DisplayProgressBar("Auto Scene Bundle", filePath, counter / (float) filesPaths.Count);  counter++;  var path = filePath.Substring (filePath.IndexOf("Assets"));AssetImporter importer = AssetImporter.GetAtPath (path);if(importer!=null){importer.assetBundleName = filePath.Substring(filePath.LastIndexOf("/")+1);importer.SaveAndReimport ();}}  EditorUtility.ClearProgressBar();  AssetDatabase.Refresh();  }


会遍历所有的场景,给场景添加AssetBundleName,名字为场景的名