/// <summary>构造函数</summary> private ABManifestLoader() { strManifestPath = AssetDefine.GetABOutPath() + "/" + AssetDefine.GetPlatformName(); manifestObj = null; aBReadManifest = null; isLoadFinish = false; }
public static void Compressions() { if (Directory.Exists(AssetDefine.UpkOutPant)) { Directory.Delete(AssetDefine.UpkOutPant, true); } Directory.CreateDirectory(AssetDefine.UpkOutPant); Debug.Log("Upk/Compressions()/ upkOutPath:" + AssetDefine.UpkOutPant); string androidFileListPath = AssetDefine.GetBuildAssetOutPath() + "/" + GetPlatformName(BuildTarget.Android) + "/files.txt"; string iosFileListPath = AssetDefine.GetBuildAssetOutPath() + "/" + GetPlatformName(BuildTarget.iOS) + "/files.txt"; string windowsFileListPath = AssetDefine.GetBuildAssetOutPath() + "/" + GetPlatformName(BuildTarget.StandaloneWindows64) + "/files.txt"; string OSXFileListPath = AssetDefine.GetBuildAssetOutPath() + "/" + GetPlatformName(BuildTarget.StandaloneOSX) + "/files.txt"; Filter(androidFileListPath, GetPlatformName(BuildTarget.Android)); Filter(iosFileListPath, GetPlatformName(BuildTarget.iOS)); Filter(windowsFileListPath, GetPlatformName(BuildTarget.StandaloneWindows64)); Filter(OSXFileListPath, GetPlatformName(BuildTarget.StandaloneOSX)); if (Directory.Exists(AssetDefine.UpkTempCompressionPath)) { Directory.Delete(AssetDefine.UpkTempCompressionPath, true); } DelAssetsBundle(); AssetDatabase.Refresh(); //刷新 }
//构造函数 public SingleABLoader(string abName, DelLoadComplete loadComplete) { _AssetLoader = null; _ABName = abName; _LoadCompleteHandle = loadComplete; _ABDownLoadPath = AssetDefine.GetABOutPath() + "/" + abName; }
/// <summary> /// 根据选择平台进行打包 /// </summary> /// <param name="buildTarget">打包平台的名称</param> private static void BuildPlatformDirectory(BuildTarget buildTarget) { string targetName = string.Empty; switch (buildTarget) { case BuildTarget.Android: targetName = "Android"; break; case BuildTarget.iOS: targetName = "iOS"; break; case BuildTarget.StandaloneWindows64: case BuildTarget.StandaloneWindows: targetName = "Windows"; break; case BuildTarget.StandaloneOSX: targetName = "OSX"; break; default: Debug.LogError("打包的平台不存在! buildTarget=" + buildTarget); break; } string outPath = AssetDefine.GetBuildAssetOutPath() + "/" + targetName; AutoSetLabels.SetAbLabel();//设置标签 if (!Directory.Exists(outPath)) { Directory.CreateDirectory(outPath); } BuildPipeline.BuildAssetBundles(outPath, 0, buildTarget); AssetDatabase.Refresh();//刷新 Debug.Log("打包资源成功! outPath: " + outPath); GenerateAssetList.CreateFiles(outPath);//生成资源清单 }
/// <summary>清理本地的资源</summary> private static void DelAssetsBundle() { string strNeedDeleteDIR = string.Empty; strNeedDeleteDIR = AssetDefine.GetBuildAssetOutPath(); //目录信息(场景中的目录信息数组) DirectoryInfo[] dirScenesDIRArr = null; DirectoryInfo dirTempInfo = new DirectoryInfo(strNeedDeleteDIR); dirScenesDIRArr = dirTempInfo.GetDirectories(); foreach (DirectoryInfo currentDIR in dirScenesDIRArr) { JudgeDIRorFileBuyRecursive(currentDIR); } }
//[MenuItem("MXFramework/AssetBundle/Set AssetBundle Label", false, 201)] public static void SetAbLabel() { string abFolder = AssetDefine.GetABResourcePath(); if (!Directory.Exists(abFolder)) { Directory.CreateDirectory(abFolder); } FileInfo[] files = DirectoryEx.GetFiles(abFolder, Filter); foreach (FileInfo fileInfo in files) { SetFileABLabel(fileInfo); } //清空无用AB标记 AssetDatabase.RemoveUnusedAssetBundleNames(); AssetDatabase.Refresh();//刷新 Debug.Log("自动设置标志完成!"); }
/// <summary> /// 自动设置标记 /// </summary> //[MenuItem("MXFramework/AssetBundle/Set AssetBundle Label",false,0)] public static void SetAbLabel() { //需要打包AssetBunld的跟目录 //string strNeedSetLabelRoot = Application.dataPath + "/Res/AbRes"; string strNeedSetLabelRoot = AssetDefine.GetABResourcePath(); //如果打包路径不存在者创建 if (!Directory.Exists(strNeedSetLabelRoot)) { Directory.CreateDirectory(strNeedSetLabelRoot); } //目录信息(场景中的目录信息数组) DirectoryInfo[] dirScenesDIRArr = null; DirectoryInfo dirTempInfo = new DirectoryInfo(strNeedSetLabelRoot); dirScenesDIRArr = dirTempInfo.GetDirectories(); foreach (DirectoryInfo currentDIR in dirScenesDIRArr) { string tempScenesDIR = strNeedSetLabelRoot + "/" + currentDIR.Name; //DirectoryInfo tempScenesDIRInfo = new DirectoryInfo(tempScenesDIR); int tempIndex = tempScenesDIR.LastIndexOf("/"); string tmpScenesName = tempScenesDIR.Substring(tempIndex + 1); JudgeDIRorFileBuyRecursive(currentDIR, tmpScenesName); } //清空无用AB标记 AssetDatabase.RemoveUnusedAssetBundleNames(); AssetDatabase.Refresh();//刷新 Debug.Log("自动设置标志完成!"); }
private static void DelAssetsBundle() { string strNeedDeleteDIR = string.Empty; strNeedDeleteDIR = AssetDefine.GetBuildAssetOutPath(); if (!string.IsNullOrEmpty(strNeedDeleteDIR)) { if (Directory.Exists(strNeedDeleteDIR)) { Directory.Delete(strNeedDeleteDIR, true); if (File.Exists(strNeedDeleteDIR + ".meta")) { File.Delete(strNeedDeleteDIR + ".meta"); } AssetDatabase.Refresh(); } Debug.Log("删除所有 AssetsBundle 完成!"); } }
/// <summary> /// 压缩资源 /// </summary> /// <param name="filePath">需要压缩资源路径</param> /// <param name="outFolder">压缩完成后,压缩包输出路径</param> private static void Compression(string filePath, string outFolder) { string inPath = AssetDefine.GetBuildAssetOutPath() + "/" + outFolder; string[] fileNameArr = filePath.Split('/'); string fileDir = filePath.Replace('/' + fileNameArr[fileNameArr.Length - 1], null); fileNameArr = fileNameArr[fileNameArr.Length - 1].Split('.'); string fileName = fileNameArr[0]; string[] inPathArr = new string[2]; inPathArr[0] = inPath + "/" + filePath; inPathArr[1] = inPath + "/" + filePath + ".manifest"; string outDir = AssetDefine.UpkOutPant + "/" + outFolder + "/" + fileDir + '/'; if (!Directory.Exists(outDir)) { Directory.CreateDirectory(outDir); } string outPath = outDir + fileName + "." + AssetDefine.UPK_EXTENSIONS; PackFolder(fileDir, fileName, inPathArr, outPath); }
private ABManifestLoader() { m_ManifestPath = AssetDefine.GetManifestPath(); m_ManifestObj = null; m_ABReadManifest = null; }
/// <summary>获取Ab包名</summary> private static string GetABName(FileInfo fileInfoObj) { string strABName = string.Empty; string strABPath = fileInfoObj.FullName.Replace(fileInfoObj.Extension, null).Replace(AssetDefine.GetABResourcePath(), null); string tmpUnityPath = strABPath.Replace("\\", "/"); string[] strAbPathArr = tmpUnityPath.Split('/'); if (strAbPathArr.Length < 3) { strABName = strAbPathArr[1] + "/" + strAbPathArr[1]; } else { strABName = strAbPathArr[1] + "/" + strAbPathArr[2]; } return(strABName); }
public SingleABLoader(string abName) { m_AssetLoader = null; m_AbName = abName; m_AssetBundlePath = AssetDefine.GetABLoadPath() + "/" + abName; }