static bool IsFilter(string path) { if (string.IsNullOrEmpty(path)) { return(true); } if (path.EndsWith(".cs")) { return(true); } string extension = Path.GetExtension(path); extension = extension.ToLower(); string folder = ""; if (string.Equals(extension, ".unity")) { folder = "scenes"; } string bundleName = PackAssetBundleUtlis.GetBundleName(path, folder); string bundlePath = string.Format("{0}/{1}", PackAssetBundle.bundleBuildFolder, bundleName); if (File.Exists(bundlePath)) { return(true); } return(false); }
static void DisposeSingleScene(string scenPath) { if (string.IsNullOrEmpty(scenPath)) { return; } string bundleName = string.Empty; // 打包依赖忽略文件; string sceneName = System.IO.Path.GetFileNameWithoutExtension(scenPath); string[] deps = AssetDatabase.GetDependencies(scenPath); FileDepencies.AddDepencies(scenPath, deps); if (deps != null) { for (int i = 0; i < deps.Length; i++) { string dep = deps[i]; if (PackAssetBundleUtlis.IsFilterSceneRes(dep, scenPath)) { continue; } bundleName = PackAssetBundleUtlis.GetBundleName(dep); _packTools.PushAssetBuild(dep, bundleName, false); } } //打场景本身; bundleName = PackAssetBundleUtlis.GetBundleName(scenPath, "scenes"); _packTools.PushAssetBuild(scenPath, bundleName); }
public static List <string> CheckShaderLods(string[] allFiles, int minLod = 100) { if (allFiles == null) { return(null); } List <string> shader_infos = new List <string>(); for (int i = 0; i < allFiles.Length; i++) { string file = allFiles[i]; PackAssetBundleUtlis.ShowProgress(i, allFiles.Length, "检测ShaderLOD", file); int shader_lod = GetShaderLOD(file); if (shader_lod <= minLod) { continue; } shader_infos.Add(string.Format("{0} ----- minLod = {1}", file, shader_lod)); } EditorUtility.ClearProgressBar(); return(shader_infos); }
// 编译原包 public static void BuildSrcApp() { // 拷贝Data包 PackAssetBundleUtlis.CopyFolder(string.Format("{0}/{0}", ResourceConst.PkgBundleFolder), "Assets/StreamingAssets"); AssetDatabase.Refresh(); string cur_dir = System.Environment.CurrentDirectory; string build_dir = ""; string app_name = ""; BuildTarget build_target = BuildTarget.StandaloneWindows64; BuildTargetGroup target_group = BuildTargetGroup.Standalone; string root_dir = ""; foreach (string arg in System.Environment.GetCommandLineArgs()) { if (arg.StartsWith("buildDir")) { root_dir = arg.Split('@')[1]; break; } #if UNITY_ANDROID root_dir = string.Format("{0}/build/android", System.IO.Directory.GetParent(cur_dir)); #elif UNITY_IPHONE root_dir = string.Format("{0}/build/ios", System.IO.Directory.GetParent(cur_dir)); #elif UNITY_STANDALONE_WIN root_dir = string.Format("{0}/build/pc", System.IO.Directory.GetParent(cur_dir)); #endif } #if UNITY_ANDROID build_dir = string.Format("{0}/{1}_{2}", root_dir, DateTime.Now.ToString("yyyy-MM-dd"), DateTime.Now.ToString("HHmmss")); app_name = string.Format("{0}/{1}_{2}.apk", build_dir, DateTime.Now.ToString("yyyy-MM-dd"), DateTime.Now.ToString("HHmmss")); build_target = BuildTarget.Android; #elif UNITY_IPHONE build_dir = string.Format("{0}/{1}_{2}", root_dir, DateTime.Now.ToString("yyyy-MM-dd"), DateTime.Now.ToString("HHmmss")); app_name = string.Format("{0}/{1}_{2}.ipa", build_dir, DateTime.Now.ToString("yyyy-MM-dd"), DateTime.Now.ToString("HHmmss")); build_target = BuildTarget.iOS; #elif UNITY_STANDALONE_WIN build_dir = string.Format("{0}/{1}_{2}", root_dir, DateTime.Now.ToString("yyyy-MM-dd"), DateTime.Now.ToString("HHmmss")); app_name = string.Format("{0}/{1}_{2}.exe", build_dir, DateTime.Now.ToString("yyyy-MM-dd"), DateTime.Now.ToString("HHmmss")); build_target = BuildTarget.StandaloneWindows64; #endif System.IO.Directory.CreateDirectory(build_dir); List <string> editor_scenes = new List <string>(); foreach (EditorBuildSettingsScene scene in EditorBuildSettings.scenes) { if (!scene.enabled) { continue; } editor_scenes.Add(scene.path); } string[] scene_array = editor_scenes.ToArray(); EditorUserBuildSettings.SwitchActiveBuildTarget(build_target); //string res = BuildPipeline.BuildPlayer(scene_array, app_name, build_target, BuildOptions.None); }
static IEnumerator DisposeSceneAsync() { string[] scenePaths = Directory.GetFiles(ResourceConst.ScenePath, "*.unity"); if (scenePaths == null || scenePaths.Length < 1) { yield break; } for (int i = 0; i < scenePaths.Length; i++) { string scenePath = scenePaths[i]; PackAssetBundleUtlis.ShowProgress(i, scenePaths.Length, "分析场景:", scenePath); DisposeSingleScene(scenePath); yield return(1); } string[] sceneConfPaths = Directory.GetFiles(ResourceConst.ScenePath, "*.asset"); if (sceneConfPaths == null || sceneConfPaths.Length < 1) { yield break; } foreach (string sceneConf in sceneConfPaths) { _packTools.PushAssetBuild(sceneConf, ResourceConst.bundleSceneConf); } EditorUtility.ClearProgressBar(); }
private static void Build() { //_packTools.DisposeFbx(); _packTools.BuildAssetBundle(bundleBuildFolder, BuildAssetBundleOptions.DeterministicAssetBundle); EditorUtility.UnloadUnusedAssetsImmediate(); PackAssetBundleUtlis.DisposeFiles(bundleBuildFolder); }
static IEnumerator PackAllAssetBundleAsync(bool check) { string srcConfFolder = GetConf(); if (string.IsNullOrEmpty(srcConfFolder)) { yield break; } if (!Directory.Exists(ResourceConst.PkgBundleFolder)) { Directory.CreateDirectory(ResourceConst.PkgBundleFolder); } Clear(); DateTime dt1 = System.DateTime.UtcNow; // 分析场景; yield return(EditorCoroutineRunner.StartEditorCoroutine(DisposeSceneAsync())); DateTime dt2 = System.DateTime.UtcNow; yield return(EditorCoroutineRunner.StartEditorCoroutine(DisposeResourcesFolderAsync())); DateTime dt3 = System.DateTime.UtcNow; Build(); DateTime dt4 = System.DateTime.UtcNow; // 拷贝Conf; PackAssetBundleUtlis.CopyFolder(srcConfFolder, bundleBuildFolder); FileListUtility.BuildFileList(false); DateTime dt5 = System.DateTime.UtcNow; string confFolder = Path.GetFileName(srcConfFolder); PackAssetBundleUtlis.CopyAssetBundle(bundleBuildFolder, ResourceConst.PkgBundleFolder, confFolder); DateTime dt6 = System.DateTime.UtcNow; string info = string.Format("bundle打包完成\n总共{0}个文件\n耗时:{1}分钟\n其中:\n" , _packTools.Count, (dt6 - dt1).TotalMinutes.ToString("f1")); info = string.Format("{0}分析场景资源耗时:{1}秒\n", info, (dt2 - dt1).TotalSeconds.ToString("f1")); info = string.Format("{0}分析Resource资源耗时:{1}秒\n", info, (dt3 - dt2).TotalSeconds.ToString("f1")); info = string.Format("{0}打包AssetBundle耗时:{1}秒\n", info, (dt4 - dt3).TotalSeconds.ToString("f1")); info = string.Format("{0}生成FileList耗时:{1}秒\n", info, (dt5 - dt4).TotalSeconds.ToString("f1")); info = string.Format("{0}拷贝AssetBundle耗时:{1}秒\n", info, (dt6 - dt5).TotalSeconds.ToString("f1")); EditorUtility.DisplayDialog("打包完成", info, "好的"); if (check) { PackAssetBundleUtlis.CheckAllBundles(); } }
public static void BuildFileList(bool show_dialog) { Clear(); DateTime dt1 = System.DateTime.UtcNow; // 获取AssetBundleManifest; string manifestPath = string.Format("{0}/{1}", PackAssetBundle.bundleBuildFolder, ResourceConst.PkgBundleFolder); AssetBundleManifest manifest = PackBundleTools.GetAssetBundleManifest(manifestPath); if (manifest == null) { return; } // 计算总控文件; AddBundleInfo(ResourceConst.PkgBundleFolder, ref s_FileList); // 计算Config; AddConfInfo(s_FileList); // 计算其它文件; string[] allBundleKeyList = manifest.GetAllAssetBundles(); for (int i = 0; i < allBundleKeyList.Length; i++) { string file = allBundleKeyList[i]; if (string.IsNullOrEmpty(file)) { continue; } AddBundleInfo(file, ref s_FileList); PackAssetBundleUtlis.ShowProgress(i, allBundleKeyList.Length, "计算MD5:", file); } EditorUtility.ClearProgressBar(); string strFileList = string.Format("{0}.txt", ResourceConst.FileListName); DateTime dt2 = System.DateTime.UtcNow; BuildCommon.WriteJsonToFile(PackAssetBundle.bundleBuildFolder, strFileList, s_FileList); FileDepencies.WriteMd5Info(); DateTime dt3 = System.DateTime.UtcNow; BuildFileListAssetBundle(PackAssetBundle.bundleBuildFolder, strFileList, ResourceConst.FileListName); DateTime dt4 = System.DateTime.UtcNow; if (show_dialog) { string info = string.Format("FileList生成完成,总时长{0}秒", (dt4 - dt1).TotalSeconds.ToString("f1")); EditorUtility.DisplayDialog("打包完成", info, "好的"); } }
public static void CopyAssetBundle2StreamingAssets() { //string srcConfFolder = GetConf(); //if ( string.IsNullOrEmpty(srcConfFolder) ) //{ // return; //} //// 拷贝conf文件夹; //PackAssetBundleUtlis.CopyFolder(srcConfFolder, "Assets/StreamingAssets"); PackAssetBundleUtlis.CopyFolder(string.Format("{0}/{0}", ResourceConst.PkgBundleFolder), "Assets/StreamingAssets"); AssetDatabase.Refresh(); EditorUtility.DisplayDialog("拷贝完成", "拷贝完成", "好的"); }
static ArtResourceFileList BuildMD5() { ArtResourceFileList filelist = new ArtResourceFileList(); filelist.m_BuildTime = System.DateTime.Now.ToString(); for (int i = 0; i < s_AllArtsFiles.Count; i++) { string path = s_AllArtsFiles[i]; string md5 = GetUnityFileMD5(path); //ArtResourceInfo info = new ArtResourceInfo(); //info.mFilePath = path; //info.mFileMD5 = md5; filelist.m_ResourceInfoList.Add(path, md5); PackAssetBundleUtlis.ShowProgress(i, s_AllArtsFiles.Count, "计算MD5:", path); } EditorUtility.ClearProgressBar(); return(filelist); }
static void DisposeAsset(string path, bool check_dep = true) { if (string.IsNullOrEmpty(path)) { return; } if (PackAssetBundleUtlis.IsFilterAsset(path)) { return; } string bundleName = string.Empty; if (check_dep) { // 分析依赖; string[] deps = AssetDatabase.GetDependencies(path); FileDepencies.AddDepencies(path, deps); if (deps != null) { for (int i = 0; i < deps.Length; i++) { string dep = deps[i]; if (PackAssetBundleUtlis.IsFilterAssetDep(dep, path)) { continue; } bundleName = PackAssetBundleUtlis.GetBundleName(dep); _packTools.PushAssetBuild(dep, bundleName, false); } } } // 添加Asset自身; bundleName = PackAssetBundleUtlis.GetBundleName(path); _packTools.PushAssetBuild(path, bundleName); }
public static void OnlyCopyConf2StreamingAssets() { string srcConfFolder = GetConf(); if (string.IsNullOrEmpty(srcConfFolder)) { return; } DateTime dt1 = System.DateTime.UtcNow; // 拷贝conf文件夹; PackAssetBundleUtlis.CopyFolder(srcConfFolder, string.Format("{0}", bundleBuildFolder)); PackAssetBundleUtlis.CopyFolder(srcConfFolder, string.Format("{0}", ResourceConst.BundleFolder)); DateTime dt2 = System.DateTime.UtcNow; bool result = FileListUtility.BuildFileListByConf(); DateTime dt3 = System.DateTime.UtcNow; //FileListUtility.BuildFileList(true); // 拷贝FileList文件; string fileList = string.Format("{0}/{1}", bundleBuildFolder, ResourceConst.FileListName); string newFileList = string.Format("{0}/{1}", ResourceConst.BundleFolder, ResourceConst.FileListName); PackAssetBundleUtlis.CopyFile(fileList, newFileList); GitUtility.PrintGitToData(); DateTime dt4 = System.DateTime.UtcNow; if (result) { string info = string.Format("Conf打包完成,总时长{0}秒", (dt4 - dt1).TotalSeconds.ToString("f1")); EditorUtility.DisplayDialog("打包完成", info, "好的"); } else { EditorUtility.DisplayDialog("打包失败", "Conf打包失败,详情请看Log!", "马上去看"); } }
static void DisposeSceneRes() { string[] scenePaths = Directory.GetFiles(ResourceConst.ScenePath, "*.unity"); if (scenePaths == null || scenePaths.Length < 1) { return; } string[] sceneConfPaths = Directory.GetFiles(ResourceConst.ScenePath, "*.asset"); foreach (string sceneConf in sceneConfPaths) { DisposeAsset(sceneConf); } for (int i = 0; i < scenePaths.Length; i++) { string scenePath = scenePaths[i]; PackAssetBundleUtlis.ShowProgress(i, scenePaths.Length, "分析场景资源:", scenePath); DisposeAsset(scenePath); } EditorUtility.ClearProgressBar(); }
// 处理场景资源; static void DisposeScene() { string[] scenePaths = null; try { scenePaths = Directory.GetFiles(ResourceConst.ScenePath, "*.unity"); } catch (System.Exception ex) { Debug.LogError(ex.ToString()); } if (scenePaths == null || scenePaths.Length < 1) { return; } for (int i = 0; i < scenePaths.Length; i++) { string scenePath = scenePaths[i]; PackAssetBundleUtlis.ShowProgress(i, scenePaths.Length, "分析场景:", scenePath); DisposeSingleScene(scenePath); } string[] sceneConfPaths = Directory.GetFiles(ResourceConst.ScenePath, "*.asset"); if (sceneConfPaths == null || sceneConfPaths.Length < 1) { return; } foreach (string sceneConf in sceneConfPaths) { _packTools.PushAssetBuild(sceneConf, ResourceConst.bundleSceneConf); } EditorUtility.ClearProgressBar(); }
public static void CheckAllBundles() { PackAssetBundleUtlis.CheckAllBundles(); }
public static void PackAllAssetBundle(bool check, bool tip_dialog = true) { string srcConfFolder = GetConf(tip_dialog); if (string.IsNullOrEmpty(srcConfFolder)) { return; } if (!Directory.Exists(ResourceConst.PkgBundleFolder)) { Directory.CreateDirectory(ResourceConst.PkgBundleFolder); } Clear(); DateTime dt1 = System.DateTime.UtcNow; // 分析场景; DisposeScene(); DateTime dt2 = System.DateTime.UtcNow; DisposeResourcesInfoFolder(); // 检查用到的Shader; if (!CheckShader()) { return; } DateTime dt3 = System.DateTime.UtcNow; Build(); DateTime dt4 = System.DateTime.UtcNow; // 拷贝Conf; PackAssetBundleUtlis.CopyFolder(srcConfFolder, bundleBuildFolder); FileListUtility.BuildFileList(false); GitUtility.PrintGitToData(); //GitUtility.PrintGitModifyDetailToData_2(); // 记录比较; string compareInfo = PackAssetBundleUtlis.CompareFileList(BundleUpdateMode.Update_CRC); string compareInfo2 = PackAssetBundleUtlis.CompareFileList(BundleUpdateMode.Update_MD5); string compareInfo3 = PackAssetBundleUtlis.CompareFileList(BundleUpdateMode.Update_CRCANDMD5); string compareInfo4 = PackAssetBundleUtlis.CompareFileList(BundleUpdateMode.Update_CRCORMD5); DateTime dt5 = System.DateTime.UtcNow; string confFolder = Path.GetFileName(srcConfFolder); PackAssetBundleUtlis.CopyAssetBundle(bundleBuildFolder, ResourceConst.PkgBundleFolder, confFolder); DateTime dt6 = System.DateTime.UtcNow; // BuildMiniFileList.Build(); DateTime dt7 = System.DateTime.UtcNow; // ExportMiniClient.Export(); DateTime dt8 = System.DateTime.UtcNow; string info = string.Format("bundle打包完成\n总共{0}个文件\n耗时:{1}分钟\n其中:\n" , _packTools.Count, (dt6 - dt1).TotalMinutes.ToString("f1")); info = string.Format("{0}分析场景资源耗时:{1}秒\n", info, (dt2 - dt1).TotalSeconds.ToString("f1")); info = string.Format("{0}分析Resource资源耗时:{1}秒\n", info, (dt3 - dt2).TotalSeconds.ToString("f1")); info = string.Format("{0}打包AssetBundle耗时:{1}秒\n", info, (dt4 - dt3).TotalSeconds.ToString("f1")); info = string.Format("{0}生成FileList耗时:{1}秒\n", info, (dt5 - dt4).TotalSeconds.ToString("f1")); info = string.Format("{0}拷贝AssetBundle耗时:{1}秒\n", info, (dt6 - dt5).TotalSeconds.ToString("f1")); info = string.Format("{0}生成FileList2耗时:{1}秒\n", info, (dt7 - dt6).TotalSeconds.ToString("f1")); info = string.Format("{0}导出微端资源耗时:{1}秒\n", info, (dt8 - dt7).TotalSeconds.ToString("f1")); info = string.Format("{0}\n{1}\n", info, compareInfo); info = string.Format("{0}\n{1}\n", info, compareInfo2); info = string.Format("{0}\n{1}\n", info, compareInfo3); info = string.Format("{0}\n{1}\n", info, compareInfo4); if (tip_dialog) { EditorUtility.DisplayDialog("打包完成", info, "好的"); } if (check) { PackAssetBundleUtlis.CheckAllBundles(tip_dialog); } }