/// <summary> /// 加载单个ab包到缓存字典 /// </summary> /// <param name="abName">ab包名字</param> /// <returns></returns> private IEnumerator LoadABundle(string abName, Action ac) { //编辑器下test使用 string url = System.IO.Path.Combine(PathManger.GetLoaderPath(), abName); //外网链接 // string url = PathManger.assetBundleWebUrl + PathManger.ABProjectName+"/"+abName; Debug.Log("url:" + url); if (string.IsNullOrEmpty(url)) { Debug.LogError(GetType() + "需要下载的" + abName + "资源的url为空!"); } UnityWebRequest webRequest = UnityWebRequest.GetAssetBundle(url); yield return(webRequest.SendWebRequest()); if (!string.IsNullOrEmpty(webRequest.error)) { Debug.LogError(webRequest.error + "URL: " + url); } else { // AssetBundle ab = (webRequest.downloadHandler as DownloadHandlerAssetBundle).assetBundle; AssetBundle ab = DownloadHandlerAssetBundle.GetContent(webRequest); if (ab != null) { ABundleDic[abName] = ab; Debug.Log(ab.name + "包加载完成"); ac(); } } }
public static void BuildAllAB() { //(打包)AB的输出路径 string strABOutPathDIR = ""; BuildTarget buildTarget = BuildTarget.NoTarget; buildTarget = GetActiveBuildTarget(); strABOutPathDIR = PathManger.GetABOutFile(); if (!Directory.Exists(strABOutPathDIR)) { Directory.CreateDirectory(strABOutPathDIR); } //打包生成 BuildPipeline.BuildAssetBundles(strABOutPathDIR, BuildAssetBundleOptions.ChunkBasedCompression, buildTarget); AssetDatabase.Refresh(); Debug.Log("AB资源打包完成-文件路径:" + strABOutPathDIR); }
public static void SetABLabels() { keyValueList = new KeyValueInfo(); keyValueList.KeyValueList = new List <KeyValueNode>(); keyValueList.KeyValueList.Clear(); //需要给AB做标记的根目录 string strNeedSetABLableRootDIR = ""; //目录信息 DirectoryInfo[] dirScenesDIRArray = null; //清空无用AB标记 AssetDatabase.RemoveUnusedAssetBundleNames(); //定位需要打包资源的文件夹根目录。 strNeedSetABLableRootDIR = PathManger.GetABResoursesPath(); DirectoryInfo dirTempInfo = new DirectoryInfo(strNeedSetABLableRootDIR); dirScenesDIRArray = dirTempInfo.GetDirectories(); //遍历每个“场景”文件夹(目录) foreach (DirectoryInfo currentDIR in dirScenesDIRArray) { //遍历本场景目录下的所有的目录或者文件, //如果是目录,则继续递归访问里面的文件,直到定位到文件。 string tmpScenesDIR = strNeedSetABLableRootDIR + "/" + currentDIR.Name; //res/** DirectoryInfo tmpScenesDIRInfo = new DirectoryInfo(tmpScenesDIR); //场景目录信息res/**/** int tmpIndex = tmpScenesDIR.LastIndexOf("/"); string tmpScenesName = tmpScenesDIR.Substring(tmpIndex + 1); //场景名称 //递归调用与处理目录或文件系统,如果找到文件,修改AssetBundle 的标签(label) JudgeDIROrFileByRecursive(currentDIR, tmpScenesName); }//foreach_end //将生成的bundle名与资源名添加到json文件 JsonConfigManger.DataToJson(PathManger.jsonInfoPath, keyValueList); Debug.Log("Json数据配置完成!"); //刷新 AssetDatabase.Refresh(); //提示 Debug.Log("AssetBundles 标签设置完成!"); }
public static void DeleteAllABs() { //(打包)AB的输出路径 string strNeedDeleteDIR = ""; strNeedDeleteDIR = PathManger.GetABOutFile(); if (!string.IsNullOrEmpty(strNeedDeleteDIR)) { try { //参数true 表示可以删除非空目录。 Directory.Delete(strNeedDeleteDIR, true); //去除删除警告 File.Delete(strNeedDeleteDIR + ".meta"); //刷新 AssetDatabase.Refresh(); Debug.Log("资源删除完成!"); } catch (System.Exception) { Debug.Log(strNeedDeleteDIR + "文件夹不存在"); } } }