private static void BuildAssetBundle(AssetBundleBuildSetting dirSetting) { var projectInfo = ProjectInfoDati.GetActualInstance(); var startTime = DateTime.Now; Debug.Log($"应用{projectInfo.DevelopProjectName}在{DateTime.Now}开始执行AssetBundle打包!"); var assetBundleOutPutDir = projectInfo.AssetBundleBuildDir; IOUtility.EnsureDirExist(assetBundleOutPutDir); try { BuildPipeline.BuildAssetBundles(assetBundleOutPutDir, BuildAssetBundleOptions.ChunkBasedCompression, EditorUserBuildSettings.activeBuildTarget); } catch (Exception e) { Debug.Log($"应用{projectInfo.DevelopProjectName}的AssetBundle打包操作发生异常," + $"异常信息为{e.Message}!"); throw; } var endTime = DateTime.Now; var costTimeStamp = (endTime - startTime); var minutes = costTimeStamp.Minutes; var seconds = costTimeStamp.Seconds; buildTotalSecond += costTimeStamp.TotalSeconds; Debug.Log($"应用{projectInfo.DevelopProjectName}在{DateTime.Now}结束执行AssetBundle打包!"); Debug.Log($"应用{projectInfo.DevelopProjectName}的AssetBundle打包操作已完成," + $"耗时为{minutes}分{seconds}秒!"); Debug.Log($"应用{projectInfo.DevelopProjectName}的AssetBundle打包操作已完成," + $"当前总耗时为{buildTotalSecond}秒!"); }
/// <summary> /// 将可序列化脚本对象创建为资产文件。 /// 如果目标路径上已有资产文件则将会删除。 /// 该方法会确保目标路径存在。 /// </summary> /// <param name="scriptObject"></param> /// <param name="path"></param> public static void CreateScriptAsset(Object scriptObject, string path) { IOUtility.EnsureDirExist(path); if (File.Exists(path)) { File.Delete(path); } AssetDatabase.CreateAsset(scriptObject, path); }
//[MenuItem("Yu/AssetBundle/打包当前应用的AssetBundle &b")] public static void BuildAllAssetBundle() { var currentApp = ProjectInfoDati.GetActualInstance(); var assetBundleOutPutDir = currentApp.AssetBundleBuildDir; IOUtility.EnsureDirExist(assetBundleOutPutDir); BuildPipeline.BuildAssetBundles(assetBundleOutPutDir, BuildAssetBundleOptions.ChunkBasedCompression, EditorUserBuildSettings.activeBuildTarget); UnityEditorUtility.DisplayTooptx($"应用{currentApp.DevelopProjectName}的AssertBundle打包已完成!"); AssetDatabase.Refresh(); }
public static void CreateAsset(Object asset, string path, bool isDeletedExist = false) { var fullPath = UnityIOUtility.GetFullPath(path); if (File.Exists(fullPath) && isDeletedExist) { File.Delete(fullPath); Refresh(); } IOUtility.EnsureDirExist(fullPath); var assetsPath = UnityIOUtility.GetAssetsPath(fullPath); var arg = new object[] { asset, assetsPath }; CreateAssetMethod.Invoke(null, arg); }