private static ABInfo GetOrInitABInfo(string abName) { if (s_ABInfoDic.ContainsKey(abName)) { return(s_ABInfoDic[abName]); } else { var isDep = ABConfig.IsDepABName(abName); var size = GetABFileSize(abName); var type = GetABType(abName, isDep); var info = new ABInfo() { type = type, size = size, name = abName, assetIcon = EditorGUIUtility.IconContent("DefaultAsset Icon").image as Texture2D }; s_ABInfoDic[abName] = info; if (!s_ABTypeStat.ContainsKey(ABType.All)) { s_ABTypeStat[ABType.All] = new StatInfo(); } if (!s_ABTypeStat.ContainsKey(info.type)) { s_ABTypeStat[info.type] = new StatInfo(); } s_ABTypeStat[ABType.All].Stat(1, info.size); s_ABTypeStat[info.type].Stat(1, info.size); return(info); } }
public static string RefreshAB(BuildTarget target) { var strPlatform = target.ToString(); s_TargetPlatform = target; s_ABDirPath = string.Format("{0}/{1}/", ABConfig.GetABDirPath(), strPlatform); if (!Directory.Exists(s_ABDirPath)) { var error = "can't find dir:" + s_ABDirPath; Debug.LogError(error); return(error); } s_TotalABs = 0; s_ABInfoDic.Clear(); s_AssetInfoDic.Clear(); s_ABTypeStat.Clear(); s_WaitingInitABs.Clear(); s_ABDirty = true; if (s_ManifestAB != null) { s_ManifestAB.Unload(true); s_ManifestAB = null; } s_ManifestAB = ABRegister.LoadAssetBundle(s_ABDirPath + strPlatform); if (s_ManifestAB != null) { s_Manifest = s_ManifestAB.LoadAsset <AssetBundleManifest>("AssetBundleManifest"); s_WaitingInitABs.AddRange(s_Manifest.GetAllAssetBundles()); s_TotalABs = s_WaitingInitABs.Count; } return(null); }
public static void RefreshAssets(List <ABInfo> abList) { s_TotalAssets = 0; s_AssetTypeStat.Clear(); s_AssetWaitingDic.Clear(); s_WaitingInitAssets.Clear(); s_CurrentAssetsList.Clear(); foreach (var info in abList) { var assetPaths = AssetDatabase.GetAssetPathsFromAssetBundle(info.name); foreach (var path in AssetDatabase.GetDependencies(assetPaths, true)) { if (ABConfig.IsExcludeAssets(path)) { continue; } if (!s_AssetWaitingDic.ContainsKey(path)) { s_AssetWaitingDic[path] = new WaitingAssetsInfo(path); s_WaitingInitAssets.Add(s_AssetWaitingDic[path]); } s_AssetWaitingDic[path].parents.Add(info.name); } } s_TotalAssets = s_AssetWaitingDic.Count; s_AssetDirty = true; }
public static void SetAssetLabels() { resourceCount = 0; typeAssets = new Dictionary <string, List <string> >(); if (File.Exists(configPath)) { File.Delete(configPath); } List <string> files = FindAllFiles.ListFiles(buildAssetsPath, true); abConfig = new ABConfig(); abConfig.data = new List <ABConfigInfo>(); FileStream fs = new FileStream(configPath, FileMode.Create); StreamWriter sw = new StreamWriter(fs); SetABName(files, true); string js = EditorJsonUtility.ToJson(abConfig, true); sw.Write(js); sw.Close(); fs.Close(); AssetDatabase.Refresh(); SetABName(new List <string> { configPath }, true); }
private static void GenerateABConfigeFile(string dir) { ABConfig abConfig = new ABConfig(); abConfig.ListABRelation.Clear(); foreach (var item in DicABRelation) { foreach (var abAndType in item.Value) { var resInfo = new ResInfo() { abName = abAndType.Value, TypeRes = abAndType.Key.FullName, assetName = item.Key }; abConfig.ListABRelation.Add(resInfo); } } using (FileStream fileStream = new FileStream($"{dir}/ABConfig.txt", FileMode.Create)) { string json = JsonUtility.ToJson(abConfig); byte[] bytes = JsonUtility.ToJson(abConfig, true).ToByteArray(); fileStream.Write(bytes, 0, bytes.Length); } //设置bundle ETEditor.BuildEditor.SetBundle(abConfigPath, "ABConfig", true); AssetDatabase.Refresh(); AssetDatabase.SaveAssets(); }
private IEnumerable LaodDependencies(string file) { ABConfig temp = null; for (int i = 0; i < dependenList.Count; i++) { temp = dependenList[i]; if (string.Equals(temp.name, file)) { dependenList.Remove(temp); temp.index++; dependenList.Add(temp); yield break; } } if (PathUtil.GetAllPath(file, out string path)) { PathUtil.PlatformPath(ref path); UnityWebRequest req = UnityWebRequestAssetBundle.GetAssetBundle(path); yield return(req.SendWebRequest()); if (req.isNetworkError || req.isHttpError) { Log.LogError(req.error); yield break; } AssetBundle ab = (req.downloadHandler as DownloadHandlerAssetBundle).assetBundle; temp = new ABConfig(file, ab); dependenList.Add(temp); } }
//单个文件加载 static void LoadFile(ABConfig abConfig) { string[] allGuid = AssetDatabase.FindAssets("t:Prefab", abConfig.m_AllPrefabPaths.ToArray()); for (int i = 0; i < allGuid.Length; i++) { string path = AssetDatabase.GUIDToAssetPath(allGuid[i]); EditorUtility.DisplayProgressBar("查找prefab", "prefab:" + path, 1.0f / allGuid.Length * i); m_ConfigFil.Add(path); GameObject obj = AssetDatabase.LoadAssetAtPath <GameObject>(path); string[] depenArr = AssetDatabase.GetDependencies(path); //得到obj的所有依赖 List <string> depenList = new List <string>(); //obj所有依赖(去重后) foreach (string item in depenArr) { //过滤脚本和已存在文件 if (!ContainAllFileAB(item) && !item.EndsWith(".cs")) { m_AllFileAB.Add(item); depenList.Add(item); } } //添加 if (m_AllPrefabDir.ContainsKey(obj.name)) { Debug.LogError("prefab重复!"); } else { m_AllPrefabDir.Add(obj.name, depenList); } } }
//UI单独的打包处理 static void LoadUIFile(ABConfig abConfig) { DirectoryInfo uiDir = new DirectoryInfo(abConfig.m_UiDirPath); FileInfo[] files = uiDir.GetFiles(); for (int i = 0; i < files.Length; i++) { FileInfo file = files[i]; string path = file.FullName.Replace("\\", "/"); path = path.Substring(path.IndexOf("/Assets") + 1); if (file.FullName.EndsWith(".meta")) { continue; } m_ConfigFil.Add(path); EditorUtility.DisplayProgressBar("查找UI", "正在检索UI:" + file.FullName, 1.0f / files.Length * i); string abName = file.Name.Substring(0, file.Name.IndexOf("_")); //添加 if (m_AllUiDic.ContainsKey(abName)) { m_AllUiDic[abName].Add(path); } else { List <string> uiPathList = new List <string>() { path }; m_AllUiDic.Add(abName, uiPathList); m_AllFileAB.Add(path); } } }
private static void InitAsset(WaitingAssetsInfo waitInfo) { var path = waitInfo.path; var extension = Path.GetExtension(path).ToLower(); if (ABConfig.IsExcludeExtention(extension)) { return; } ABAssetsInfo info = null; if (!s_AssetInfoDic.ContainsKey(path)) { var assetType = ABConfig.GetAssetType(extension); var width = 0; var height = 0; if (assetType == AssetsType.Texture) { ABHelper.GetTextureWidthAndHeight(path, out width, out height); } info = new ABAssetsInfo() { type = assetType, name = Path.GetFileNameWithoutExtension(path), extension = extension, path = path, abName = ABHelper.GetABName(path), textureWidth = width, textureHeight = height }; s_AssetInfoDic[path] = info; } else { info = s_AssetInfoDic[path]; } info.size = ABHelper.GetAssetSize(path); if (info.type == AssetsType.Texture) { var maxSize = 0; ABHelper.GetTextureMaxSize(s_TargetPlatform, info.path, out maxSize); info.textureMaxSize = maxSize; } foreach (var ab in waitInfo.parents) { info.AddRefAB(ab); } if (!s_AssetTypeStat.ContainsKey(AssetsType.None)) { s_AssetTypeStat[AssetsType.None] = new StatInfo(); } if (!s_AssetTypeStat.ContainsKey(info.type)) { s_AssetTypeStat[info.type] = new StatInfo(); } s_AssetTypeStat[AssetsType.None].Stat(1, info.size); s_AssetTypeStat[info.type].Stat(1, info.size); s_CurrentAssetsList.Add(info); s_AssetDirty = true; }
private static ABInfo GetOrInitABInfo(string abName) { if (s_ABInfoDic.ContainsKey(abName)) { return(s_ABInfoDic[abName]); } else { var isDep = ABConfig.IsDepABName(abName); var size = GetABFileSize(abName); var type = GetABType(abName, isDep); var info = new ABInfo() { type = type, size = size, name = abName, }; s_ABInfoDic[abName] = info; if (!s_ABTypeStat.ContainsKey(ABType.All)) { s_ABTypeStat[ABType.All] = new StatInfo(); } if (!s_ABTypeStat.ContainsKey(info.type)) { s_ABTypeStat[info.type] = new StatInfo(); } s_ABTypeStat[ABType.All].Stat(1, info.size); s_ABTypeStat[info.type].Stat(1, info.size); return(info); } }
private static List <string> m_ConfigFil = new List <string>();//一共就三个 prefab地址,shader sound //记录要打的包源地址 private static void OnInit() { m_AllFileAB.Clear(); m_NeedSetABNameFolderDict.Clear(); m_NeedSetABNamePrefabAndResDict.Clear(); m_ConfigFil.Clear(); aBConfig = AssetDatabase.LoadAssetAtPath <ABConfig>(ABCONFIGPATH); }
public static void Build() { m_AllFileDir.Clear(); m_AllFileAB.Clear(); m_AllPrefabDir.Clear(); m_ConfigFil.Clear(); ABConfig abconfig = AssetDatabase.LoadAssetAtPath <ABConfig>(ABConfigPath); for (int i = 0; i < abconfig.m_AllPrefab.Count; ++i) { string key = abconfig.m_AllPrefab[i].name; string path = AssetDatabase.GetAssetPath(abconfig.m_AllPrefab[i]); //显示进度条 EditorUtility.DisplayProgressBar("查找Prefab", "Prefab:" + path, i * 1 / abconfig.m_AllPrefab.Count); if (m_AllFileDir.ContainsKey(abconfig.m_AllPrefab[i].name)) { Debug.LogWarning("已存在该文件:" + abconfig.m_AllPrefab[i].name); return; } m_AllFileDir.Add(abconfig.m_AllPrefab[i].name, path); m_AllFileAB.Add(path); m_ConfigFil.Add(path); //获取关联 string[] dependens = AssetDatabase.GetDependencies(path); if (dependens != null) { List <string> dependensPath = new List <string>(); for (int j = 0; j < dependens.Length; ++j) { if (dependens[j].EndsWith(".cs") || m_AllFileAB.Contains(dependens[j])) { continue; } dependensPath.Add(dependens[j]); m_AllFileAB.Add(dependens[j]); m_ConfigFil.Add(dependens[j]); } m_AllPrefabDir.Add(key, dependensPath); } } //设置assetbunde name foreach (var key in m_AllFileDir.Keys) { SetABName(key, m_AllPrefabDir[key]); } BunildAssetBundle(); //清除进度条 EditorUtility.ClearProgressBar(); }
public override void OnGUI(Rect rect) { EditorGUI.BeginChangeCheck(); ABConfig.Instance.AB_DIR = EditorGUILayout.TextField(Styles.abDir, ABConfig.Instance.AB_DIR); if (!Directory.Exists(ABConfig.GetABDirPath())) { EditorGUILayout.HelpBox("Directory not exists:" + ABConfig.GetABDirPath(), MessageType.Warning); } ABBrowserWindow.Instance.abSource = (ABDatabase.ABSource)EditorGUILayout.EnumPopup(Styles.abSource, ABBrowserWindow.Instance.abSource); if (EditorGUI.EndChangeCheck()) { changed = true; } }
public static void MenuClicked() { //1.吧写的ABConfig读取出来 ABConfig abconfig = AssetDatabase.LoadAssetAtPath <ABConfig>(ABCONFIG_PATH); //test foreach (var str in abconfig.m_AllPrefab) { Debug.Log(str); } foreach (var item in abconfig.m_AllFileDirAb) { Debug.Log(item.AbName + " " + item.Path); } }
public static void ClearAssetLabels() { resourceCount = 0; typeAssets = new Dictionary <string, List <string> >(); List <string> files = FindAllFiles.ListFiles(buildAssetsPath, true); if (File.Exists(configPath)) { File.Delete(configPath); } abConfig = new ABConfig(); abConfig.data = new List <ABConfigInfo>(); SetABName(files, false); AssetDatabase.Refresh(); }
/// <summary> /// 加载本体 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="name"></param> /// <param name="path"></param> /// <param name="call"></param> /// <returns></returns> private IEnumerator LoadAsyn <T>(string name, string path, Action <T> call = null) where T : UnityEngine.Object { Log.LogColor("laodasyn ", "blue"); ABConfig temp = null; for (int i = 0; i < mainbodyList.Count; i++) { } PathUtil.PlatformPath(ref path); //TODO 加载依赖 #region 加载解密 /* * UnityWebRequest req = UnityWebRequestAssetBundle.GetAssetBundle(path); * yield return req.SendWebRequest(); * if (req.isNetworkError || req.isHttpError) * { * Log.LogError("下载" + req.error); * yield break; * } * byte[] byts = req.downloadHandler.data;*/ WWW www = new WWW(path); yield return(www); if (!string.IsNullOrEmpty(www.error)) { Log.LogColor("出错 ; " + www.error); yield break; } byte[] byts = www.bytes; byte byt; byt = byts[byts.Length - 2]; byts[byts.Length - 2] = byts[0]; byts[0] = byt; byt = byts[byts.Length - 1]; byts[byts.Length - 1] = byts[1]; byts[1] = byt; #endregion AssetBundle ab = AssetBundle.LoadFromMemory(byts); //AssetBundle ab = (req.downloadHandler as DownloadHandlerAssetBundle).assetBundle; T t = ab.LoadAsset <T>(name.Replace(".unity3d", "")); call?.Invoke(t); }
//整个文件夹加载 static void LoadFolder(ABConfig abConfig) { //先遍历所有的文件夹做一个键值对索引 for (int i = 0; i < abConfig.m_FileDirABs.Count; i++) { if (m_AllFileDir.ContainsKey(abConfig.m_FileDirABs[i].ABName)) { Debug.LogError("ab包配置名重复,请检查"); } else { m_AllFileDir.Add(abConfig.m_FileDirABs[i].ABName, abConfig.m_FileDirABs[i].Path); m_AllFileAB.Add(abConfig.m_FileDirABs[i].Path); m_ConfigFil.Add(abConfig.m_FileDirABs[i].Path); } } }
public static void Build() { m_AllFileDir.Clear(); ABConfig abConfig = AssetDatabase.LoadAssetAtPath <ABConfig>(ABCONFIGPATH); foreach (ABConfig.FileDirABName fileDir in abConfig.m_AllFileDirAB) { if (m_AllFileDir.ContainsKey(fileDir.ABName)) { Debug.LogError("AB包配置名字重复,请检查!"); } else { m_AllFileDir.Add(fileDir.ABName, fileDir.Path); m_AllFileAB.Add(fileDir.Path); } } string[] allStr = AssetDatabase.FindAssets("t:Prefab", abConfig.m_AllPrefabPath.ToArray()); for (int i = 0; i < allStr.Length; i++) { string path = AssetDatabase.GUIDToAssetPath(allStr[i]); EditorUtility.DisplayProgressBar("查找Prefab", "Prefab:" + path, i * 1.0f / allStr.Length); if (!ContainAllFileAB(path)) { GameObject obj = AssetDatabase.LoadAssetAtPath <GameObject>(path); //获取所有与他有依赖关系的物体 string[] allDepend = AssetDatabase.GetDependencies(path); List <string> allDependPath = new List <string>(); for (int j = 0; j < allDepend.Length; j++) { Debug.Log(allDepend[j]); if (!ContainAllFileAB(allDepend[j]) && !allDepend[j].EndsWith(".cs")) { } } } } EditorUtility.ClearProgressBar(); }
public static void Build() { Init(); ABConfig abConfig = AssetDatabase.LoadAssetAtPath <ABConfig>(ABCONFIGPATH); if (abConfig == null) { Debug.LogError("ab包配置加载失败"); return; } LoadFolder(abConfig); //加载文件夹 LoadUIFile(abConfig); //加载UI包 LoadFile(abConfig); //加载prefab //设置ab包 foreach (string name in m_AllFileDir.Keys) { SetAB(name, m_AllFileDir[name]); } foreach (string name in m_AllUiDic.Keys) { foreach (var uiPath in m_AllUiDic[name]) { SetAB(name, uiPath); } } foreach (string name in m_AllPrefabDir.Keys) { SetAB(name, m_AllPrefabDir[name]); } BuildAssetBundle(); //打包 DeletAB(); //删除多余的ab包 //清理ab包 string[] allABNames = AssetDatabase.GetAllAssetBundleNames(); for (int i = 0; i < allABNames.Length; i++) { AssetDatabase.RemoveAssetBundleName(allABNames[i], true); EditorUtility.DisplayProgressBar("清理ab包设置", "正在清理:" + allABNames[i], 1.0f / allABNames.Length * i); } AssetDatabase.Refresh(); EditorUtility.ClearProgressBar(); }
private static void ABInfoDepCountAndSize(ABInfo info, string abName) { var list = s_Manifest.GetAllDependencies(abName); if (list == null || list.Length == 0) { return; } foreach (var ab in list) { if (info.AddDepAB(ab)) { if (!ABConfig.IsCommonAB(ab)) { info.depSize += GetABFileSize(ab); } var depInfo = GetOrInitABInfo(ab); depInfo.AddRefAB(info.name); ABInfoDepCountAndSize(info, ab); } } }
public static void SVBuild() { m_ConfigFil.Clear(); m_AllFileAB.Clear(); m_AllFileDir.Clear(); m_AllPrefabDir.Clear(); ABConfig config = AssetDatabase.LoadAssetAtPath <ABConfig>(ABCONFIGPATH); List <string> prefabList = config.m_AllPrefabPath; List <ABConfig.FileDirABName> fileDirList = config.m_AllFileDirAB; //将dirPath存放对应数据结构 foreach (ABConfig.FileDirABName dirPath in fileDirList) { EditorUtility.DisplayProgressBar("查找Prefab", "Prefab:", 0.9f); if (m_AllFileDir.ContainsKey(dirPath.ABName)) { Debug.LogError("AB包名称重复"); } else { m_AllFileDir.Add(dirPath.ABName, dirPath.Path); m_AllFileAB.Add(dirPath.Path); m_ConfigFil.Add(dirPath.Path); } } //将prefab path存放对应数据结构 string[] prefabIDs = AssetDatabase.FindAssets("t:Prefab", config.m_AllPrefabPath.ToArray()); // Debug.Log("prefabs: " + prefabs.Length); foreach (string uID in prefabIDs) { // Debug.LogWarning("uID " + uID); string path = AssetDatabase.GUIDToAssetPath(uID); // Debug.LogWarning("uid path " + path); if (ConatinABName(path, m_ConfigFil.ToArray())) { continue; } GameObject obj = AssetDatabase.LoadAssetAtPath <GameObject>(path); string[] allDepend = AssetDatabase.GetDependencies(path); List <string> dependPrefabs = new List <string>(); foreach (string dependPath in allDepend) { if (!ContainAllFileAB(dependPath) && !dependPath.EndsWith(".cs")) { m_AllFileAB.Add(dependPath); dependPrefabs.Add(dependPath); } } m_AllPrefabDir.Add(obj.name, dependPrefabs); m_ConfigFil.Add(path); } //将对应资源赋值assetbundle name foreach (string name in m_AllFileDir.Keys) { SetABName(name, m_AllFileDir[name]); } foreach (string name in m_AllPrefabDir.Keys) { SetABName(name, m_AllPrefabDir[name]); } //删除之前废弃的文件 SVDelete(); //生成对应配置列表 SVGenerateConfigeFiles(); //打包 SVBuildBundles(); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); //刷新工程视图 EditorUtility.ClearProgressBar(); }
public void Init(ABConfig abConfig) { AllPrefabPathAB = new List <string>(abConfig.AllPrefabPathAB); AllAssetAB = new List <ABConfigItem>(abConfig.AllAssetAB); AllFileDirAB = new List <ABConfigItem>(abConfig.AllFileDirAB); }
public static void MenuClick1() { m_ConfigFil.Clear(); m_AllFileAB.Clear(); m_AllFileDir.Clear(); m_AllPrefabDir.Clear(); ABConfig abConfig = AssetDatabase.LoadAssetAtPath <ABConfig>(ABCONFIGPATH); foreach (var fileDir in abConfig.m_AllFileDirAB) { if (m_AllFileDir.ContainsKey(fileDir.ABName)) { Log.Error("AB包配置名字重复,请检查!"); } else { m_AllFileDir.Add(fileDir.ABName, fileDir.Path); m_AllFileAB.Add(fileDir.Path); m_ConfigFil.Add(fileDir.Path); } } string[] allStr = AssetDatabase.FindAssets("t:Prefab", abConfig.m_AllPrefabPath.ToArray()); for (int i = 0; i < allStr.Length; i++) { string path = AssetDatabase.GUIDToAssetPath(allStr[i]); EditorUtility.DisplayProgressBar("查找Prefab", "Prefab:" + path, i * 1.0f / allStr.Length); m_ConfigFil.Add(path); if (!ContainAllFileAB(path)) { GameObject obj = AssetDatabase.LoadAssetAtPath <GameObject>(path); string[] allDepend = AssetDatabase.GetDependencies(path); List <string> allDependPath = new List <string>(); for (int j = 0; j < allDepend.Length; j++) { Debug.Log(path + " " + allDepend[j]); if (!ContainAllFileAB(allDepend[j]) && !allDepend[j].EndsWith(".cs")) { Debug.Log("add " + path + " " + allDepend[j]); m_AllFileAB.Add(allDepend[j]); allDependPath.Add(allDepend[j]); } } if (m_AllPrefabDir.ContainsKey(obj.name)) { Debug.LogError("存在相同名字的Prefab!名字:" + obj.name); } else { m_AllPrefabDir.Add(obj.name, allDependPath); } } } foreach (string name in m_AllFileDir.Keys) { SetABName(name, m_AllFileDir[name]); } foreach (string name in m_AllPrefabDir.Keys) { SetABName(name, m_AllPrefabDir[name]); } BunildAssetBundle(); string[] oldABNames = AssetDatabase.GetAllAssetBundleNames(); for (int i = 0; i < oldABNames.Length; i++) { AssetDatabase.RemoveAssetBundleName(oldABNames[i], true); EditorUtility.DisplayProgressBar("清除AB包名", "名字:" + oldABNames[i], i * 1.0f / oldABNames.Length); } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); EditorUtility.ClearProgressBar(); }
public static void GenerateResConfig(string outputPath, string resVersion, bool generateClass, string classPath) { List <AssetBundleInfo> assetBundleInfos = new List <AssetBundleInfo>(); string[] abNames = AssetDatabase.GetAllAssetBundleNames(); foreach (var abName in abNames) { string[] astNames = AssetDatabase.GetAssetPathsFromAssetBundle(abName); AssetBundleInfo abInfo = new AssetBundleInfo(); abInfo.name = abName; abInfo.assets = astNames; assetBundleInfos.Add(abInfo); } string assetConfig = JsonUtility.ToJson(new AssetConfig() { abInfos = assetBundleInfos }, true); File.WriteAllText(outputPath + "/assetconfig.json", assetConfig); CopyResFiles(outputPath); AssetDatabase.Refresh(); ABConfig abConfig = new ABConfig { items = new List <ResItem>(), resversion = resVersion }; //避免把resconfig 本身也统计进去 if (File.Exists(outputPath + "/resconfig.json")) { File.Delete(outputPath + "/resconfig.json"); } //此处是在Asset目录之外 的output目录遍历的,所以没有.meta文件 string[] files = Directory.GetFiles(outputPath, "*", SearchOption.AllDirectories) .Where(s => s.GetFileExtendName() != ".manifest" && s.GetFileExtendName() != ".DS_Store").ToArray(); foreach (var file in files) { string realPath = Path.GetFullPath(file); string refPath = file.Replace(outputPath + Path.DirectorySeparatorChar, ""); ResItem resItem = CreateConfigItem(realPath, Path.GetFileNameWithoutExtension(file), refPath); abConfig.items.Add(resItem); } string content = JsonUtility.ToJson(abConfig, true); File.WriteAllText(outputPath + "/resconfig.json", content); if (generateClass) { if (!classPath.EndsWith(".cs")) { classPath += ".cs"; } string dir = Path.GetDirectoryName(classPath); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } var path = Path.GetFullPath(classPath); StreamWriter writer = new StreamWriter(File.Open(path, FileMode.Create)); PTBundleInfoGenerator.WriteClass(writer, "PTGame.AssetBundle", assetBundleInfos); writer.Close(); AssetDatabase.Refresh(); } }
public static void BuildAllAssetBundles() { allFileDir.Clear(); allPrefabDir.Clear(); allFileAB.Clear(); validFile.Clear(); //文件夹类型 ABConfig aBConfig = AssetDatabase.LoadAssetAtPath <ABConfig>(ABCONFIGPATH); foreach (ABConfig.FileDirABName fileDir in aBConfig.allFileDirAB) { if (allFileDir.ContainsKey(fileDir.ABName)) { Debug.LogError("AB包配置名字重复,请检查!"); } else { allFileDir.Add(fileDir.ABName, fileDir.ABPath); allFileAB.Add(fileDir.ABPath); validFile.Add(fileDir.ABPath); } } //单个文件 string[] allStr = AssetDatabase.FindAssets("t:Prefab", aBConfig.allPrefabPath.ToArray()); for (int i = 0; i < allStr.Length; i++) { string path = AssetDatabase.GUIDToAssetPath(allStr[i]); EditorUtility.DisplayProgressBar("查找prefab", "Prefab:" + path, i * 1.0f / allStr.Length); validFile.Add(path); if (!ContainAllFileAB(path)) { GameObject obj = AssetDatabase.LoadAssetAtPath <GameObject>(path); string[] allDepend = AssetDatabase.GetDependencies(path); List <string> allDependPath = new List <string>(); //添加的不包含自己 allDependPath.Add(path); for (int j = 0; j < allDepend.Length; j++) { if (!ContainAllFileAB(allDepend[j]) && !allDepend[j].EndsWith(".cs")) { allFileAB.Add(allDepend[j]); allDependPath.Add(allDepend[j]); } } if (allPrefabDir.ContainsKey(obj.name)) { Debug.LogError("存在相同名字的Prefab! 名字:" + obj.name); } else { allPrefabDir.Add(obj.name, allDependPath); } } } foreach (string name in allFileDir.Keys) { SetABName(name, allFileDir[name]); } foreach (string name in allPrefabDir.Keys) { SetABName(name, allPrefabDir[name]); } BuildAssetBundle(); //清理掉设置assetbundleName的痕迹,避免mainfest刷新,影响svn不必要的更新 string[] oldNameList = AssetDatabase.GetAllAssetBundleNames(); for (int i = 0; i < oldNameList.Length; i++) { AssetDatabase.RemoveAssetBundleName(oldNameList[i], true); EditorUtility.DisplayProgressBar("清除AB包名称", "名字:" + oldNameList[i], i * 1.0f / oldNameList.Length); } //在此过程之前避免编辑器的刷新,以避免打包过慢问题 AssetDatabase.Refresh(); EditorUtility.ClearProgressBar(); }
private static void AddResAsset() { if (!Directory.Exists(ABConfigPath)) { Directory.CreateDirectory(ABConfigPath); } string fileName = ABConfigPath + typeof(ABConfig).Name + ".asset"; var abConfigOld = Resources.Load <ABConfig>(typeof(ABConfig).Name); if (abConfig == null) { abConfig = ScriptableObject.CreateInstance <ABConfig>(); } else { abConfig = ScriptableObject.CreateInstance <ABConfig>(); abConfig.Init(abConfigOld); } Dictionary <string, int> abConfigDic = new Dictionary <string, int>(); for (int i = 0; i < abConfig.AllAssetAB.Count; i++) { abConfigDic.Add(abConfig.AllAssetAB[i].Path, i); } for (int i = 0; i < abConfig.AllFileDirAB.Count; i++) { abConfigDic.Add(abConfig.AllFileDirAB[i].Path, i); } object[] select = Selection.objects; for (int i = 0; i < select.Length; i++) { if (select[i].GetType() == typeof(MonoScript)) { continue; } string path = AssetDatabase.GetAssetPath(select[i] as Object); string[] temp = {}; if (select[i].GetType() == typeof(TextAsset)) { temp = (select[i] as TextAsset).name.Split(' '); } else { temp = select[i].ToString().Split(' '); } string name = string.Empty; if (temp.Length > 1) { for (int j = 0; j < temp.Length - 1; j++) { Debug.Log(temp[j]); name += temp[j] + " "; } name = name.Trim().TrimEnd().ToLower(); } else if (temp.Length == 1) { name = temp[0].Trim().TrimEnd().ToLower(); } if (select[i].GetType() == typeof(DefaultAsset)) { if (abConfigDic.ContainsKey(path)) { int index = abConfigDic[path]; var item = abConfig.AllFileDirAB[index]; item.ABName = name; item.Path = path; } else { var item = new ABConfig.ABConfigItem(); item.ABName = name; item.Path = path; abConfig.AllFileDirAB.Add(item); } } else { if (abConfigDic.ContainsKey(path)) { int index = abConfigDic[path]; var item = abConfig.AllAssetAB[index]; item.ABName = name; item.Path = path; } else { var item = new ABConfig.ABConfigItem(); item.ABName = name; item.Path = path; abConfig.AllAssetAB.Add(item); } } } if (File.Exists(fileName)) { File.Delete(fileName); } UnityEditor.AssetDatabase.CreateAsset(abConfig, fileName); UnityEditor.AssetDatabase.SaveAssets(); UnityEditor.AssetDatabase.Refresh(); }
public static void BuildAB() { Clear(); if (!Directory.Exists(BundleTargetPath)) { Directory.CreateDirectory(BundleTargetPath); } if (!Directory.Exists(ABBytePath)) { Directory.CreateDirectory(ABBytePath); } string abConfigPath = ABConfigPath + typeof(ABConfig).Name + ".asset"; ABConfig abConfig = AssetDatabase.LoadAssetAtPath <ABConfig>(abConfigPath); if (abConfig == null) { Debug.LogError("请创建ABConfig 配置AssetBundle路径"); return; } foreach (ABConfig.ABConfigItem fileDir in abConfig.AllFileDirAB) { if (_AllFileDir.ContainsKey(fileDir.ABName)) { Debug.LogError("AB包配置名字重复,请检查! abName:" + fileDir.ABName); } else { _AllFileDir.Add(fileDir.ABName, fileDir.Path); _AllFilterAB.Add(fileDir.Path); _ConfigFile.Add(fileDir.Path); } } foreach (ABConfig.ABConfigItem fileDir in abConfig.AllAssetAB) { if (_AllAssetsAB.ContainsKey(fileDir.ABName)) { Debug.LogError("AB包配置名字重复,请检查! abName:" + fileDir.ABName); } else { _AllAssetsAB.Add(fileDir.ABName, fileDir.Path); _AllFilterAB.Add(fileDir.Path); _ConfigFile.Add(fileDir.Path); } } if (abConfig.AllPrefabPathAB.Count > 0) { string[] allStr = AssetDatabase.FindAssets("t:Prefab", abConfig.AllPrefabPathAB.ToArray()); for (int i = 0; i < allStr.Length; i++) { string path = AssetDatabase.GUIDToAssetPath(allStr[i]); EditorUtility.DisplayProgressBar("查找Prefab", "Prefab:" + path, i * 1.0f / allStr.Length); _ConfigFile.Add(path); if (!ContainAllFileAB(path)) { GameObject obj = AssetDatabase.LoadAssetAtPath <GameObject>(path); //获得依赖项 string[] allDepend = AssetDatabase.GetDependencies(path); List <string> allDependPath = new List <string>(); for (int j = 0; j < allDepend.Length; j++) { if (!ContainAllFileAB(allDepend[j]) && !allDepend[j].EndsWith(".cs")) { _AllFilterAB.Add(allDepend[j]); allDependPath.Add(allDepend[j]); } } if (_AllPrefabDir.ContainsKey(obj.name)) { Debug.LogError("存在相同明星的Prefab UIName" + obj.name); } else { _AllPrefabDir.Add(obj.name, allDependPath); } } } } foreach (string name in _AllFileDir.Keys) { SetABName(name, _AllFileDir[name]); } foreach (string name in _AllAssetsAB.Keys) { SetABName(name, _AllAssetsAB[name]); } foreach (string name in _AllPrefabDir.Keys) { SetABName(name, _AllPrefabDir[name]); } BuidAssetBundle(); //清除设置好的ab标签 ClearABTagName(); AssetDatabase.Refresh(); EditorUtility.ClearProgressBar(); }
private static void RemoveResAsset() { if (!Directory.Exists(ABConfigPath)) { Directory.CreateDirectory(ABConfigPath); } string fileName = ABConfigPath + typeof(ABConfig).Name + ".asset"; var abConfigOld = Resources.Load <ABConfig>(typeof(ABConfig).Name); if (abConfig == null) { abConfig = ScriptableObject.CreateInstance <ABConfig>(); } else { abConfig = ScriptableObject.CreateInstance <ABConfig>(); abConfig.Init(abConfigOld); } Dictionary <string, int> abConfigDic = new Dictionary <string, int>(); for (int i = 0; i < abConfig.AllAssetAB.Count; i++) { abConfigDic.Add(abConfig.AllAssetAB[i].Path, i); } for (int i = 0; i < abConfig.AllFileDirAB.Count; i++) { abConfigDic.Add(abConfig.AllFileDirAB[i].Path, i); } object[] select = Selection.objects; for (int i = 0; i < select.Length; i++) { if (select[i].GetType() == typeof(MonoScript)) { continue; } string path = AssetDatabase.GetAssetPath(select[i] as Object); if (select[i].GetType() == typeof(DefaultAsset)) { if (abConfigDic.ContainsKey(path)) { int index = abConfigDic[path]; abConfig.AllFileDirAB.RemoveAt(index); } } else { if (abConfigDic.ContainsKey(path)) { int index = abConfigDic[path]; abConfig.AllAssetAB.RemoveAt(index); } } } if (File.Exists(fileName)) { File.Delete(fileName); } UnityEditor.AssetDatabase.CreateAsset(abConfig, fileName); UnityEditor.AssetDatabase.SaveAssets(); UnityEditor.AssetDatabase.Refresh(); }
public static void BuildAB() { m_AllFileABList.Clear(); m_AllFileDir.Clear(); m_AllPrefabABDir.Clear(); m_ConfigABList.Clear(); ABConfig aBConfig = AssetDatabase.LoadAssetAtPath <ABConfig>(ABCONFIGPATH); //先打包文件夹,再打包prefab //获取需要打包的文件夹 foreach (ABConfig.FileDirABName fileDir in aBConfig.m_AllFileDirABList) { if (m_AllFileDir.ContainsKey(fileDir.AbName)) { Debug.LogError("AB包名重复,请检查!"); } else { m_AllFileDir.Add(fileDir.AbName, fileDir.FilePath); m_AllFileABList.Add(fileDir.FilePath); m_ConfigABList.Add(fileDir.FilePath); } } //获取需要打包的Prefab string[] allStr = AssetDatabase.FindAssets("t:prefab", aBConfig.m_AllPrefabPathList.ToArray()); for (int i = 0; i < allStr.Length; i++) { //FindAssets方法找到的是GUID,通过下面方法转换成path string path = AssetDatabase.GUIDToAssetPath(allStr[i]); m_ConfigABList.Add(path); //显示进度条 EditorUtility.DisplayProgressBar("查找Prefab", "Prefab: " + path, i * 1.0f / allStr.Length); if (!ContainAllFileAB(path)) { GameObject go = AssetDatabase.LoadAssetAtPath <GameObject>(path); //获取当前prefab的所有依赖项路径 string[] allDependPaths = AssetDatabase.GetDependencies(path); List <string> dependList = new List <string>(); for (int j = 0; j < allDependPaths.Length; j++) { //不包含该文件,且该文件不是.cs文件 if (!ContainAllFileAB(allDependPaths[j]) && !allDependPaths[j].EndsWith(".cs")) { m_AllFileABList.Add(allDependPaths[j]); //加入过滤List中 dependList.Add(allDependPaths[j]); } } if (m_AllPrefabABDir.ContainsKey(go.name)) { Debug.LogError("存在相同名字的Prefab :" + go.name); } else { m_AllPrefabABDir.Add(go.name, dependList); } } } //设置AB包名 foreach (string name in m_AllFileDir.Keys) { SetABName(name, m_AllFileDir[name]); } foreach (string name in m_AllPrefabABDir.Keys) { SetABName(name, m_AllPrefabABDir[name]); } BuildAssetBundle(); //清除AB包,作用:文件AB包名更改后会更改其.meta文件,这样打包后可能会导致各种各样的问题 //在每次打完AB包后,清除所有AB包名,可以避免一些意外的错误。 string[] oldABNames = AssetDatabase.GetAllAssetBundleNames(); for (int i = 0; i < oldABNames.Length; i++) { AssetDatabase.RemoveAssetBundleName(oldABNames[i], true); EditorUtility.DisplayProgressBar("清除AB包", "名字:" + oldABNames[i], i * 1.0f / oldABNames.Length); } AssetDatabase.Refresh(); //清除进度条 EditorUtility.ClearProgressBar(); }
public static void Build() { _allFileAB.Clear(); _allFileDir.Clear(); _allPrefabDir.Clear(); _configFil.Clear(); ABConfig config = AssetDatabase.LoadAssetAtPath <ABConfig>(ABCONIFG_PATH); foreach (ABConfig.FileDirABName fileDir in config._allFileDirAB) { if (_allFileDir.ContainsKey(fileDir.ABName)) { Debug.LogError("AB包配置名字重复,请检查!"); continue; } _allFileDir.Add(fileDir.ABName, fileDir.Path); _allFileAB.Add(fileDir.Path); _configFil.Add(fileDir.Path); } //获取路径下所有Prefab的GUID string[] allPath = AssetDatabase.FindAssets("t:Prefab", config._allPrefabPath.ToArray()); for (int i = 0; i < allPath.Length; i++) { //找到对应Prefab的全地址 string path = AssetDatabase.GUIDToAssetPath(allPath[i]); //显示进度条 EditorUtility.DisplayProgressBar("查找Prefab", "Prefab:" + path, i * 1.0f / allPath.Length); _configFil.Add(path); if (!ContainAllFileAB(path)) { GameObject obj = AssetDatabase.LoadAssetAtPath <GameObject>(path); //获取所有的依赖项 string[] allDepend = AssetDatabase.GetDependencies(path); List <string> allDependPath = new List <string>(); for (int j = 0; j < allDepend.Length; j++) { //过滤已经存在别的AB包中的依赖项和剔除cs代码 if (!ContainAllFileAB(allDepend[j]) && !allDepend[j].EndsWith(".cs")) { _allFileAB.Add(allDepend[j]); allDependPath.Add(allDepend[j]); } } if (_allPrefabDir.ContainsKey(obj.name)) { Debug.LogError("存在相同名字的Prefab! 名字:" + obj.name); } else { _allPrefabDir.Add(obj.name, allDependPath); } } } foreach (string name in _allFileDir.Keys) { SetABName(name, _allFileDir[name]); } foreach (string name in _allPrefabDir.Keys) { SetABName(name, _allPrefabDir[name]); } BunildAssetBundle(); //清除AB包名字,防止meta文件老是冲突 string[] oldABName = AssetDatabase.GetAllAssetBundleNames(); for (int i = 0; i < oldABName.Length; i++) { AssetDatabase.RemoveAssetBundleName(oldABName[i], true); EditorUtility.DisplayProgressBar("清除旧的AB包名", "AB包名字:" + oldABName[i], i * 1.0f / oldABName.Length); } AssetDatabase.Refresh(); EditorUtility.ClearProgressBar(); // BuildPipeline.BuildAssetBundles(Application.streamingAssetsPath, BuildAssetBundleOptions.ChunkBasedCompression, EditorUserBuildSettings.activeBuildTarget); // AssetDatabase.SaveAssets(); }