/// <summary> /// /// </summary> /// <param name="type"></param> /// <param name="buildAssetBundleOptions"></param> /// <param name="buildOptions">打包配置</param> /// <param name="isBuildExe">是否打包EXE</param> /// <param name="isContainAB">是否包涵AB包</param> public static void Build(PlatformType type, BuildAssetBundleOptions buildAssetBundleOptions, BuildOptions buildOptions, bool isBuildExe, bool isContainAB, int clientVersion) { ClientVersion = clientVersion; BuildTarget buildTarget = BuildTarget.StandaloneWindows; string exeName = "ET"; switch (type) { case PlatformType.PC: buildTarget = BuildTarget.StandaloneWindows64; exeName += ".exe"; break; case PlatformType.Android: buildTarget = BuildTarget.Android; exeName += ".apk"; break; case PlatformType.IOS: buildTarget = BuildTarget.iOS; break; case PlatformType.MacOS: buildTarget = BuildTarget.StandaloneOSX; break; } string fold = string.Format(BuildFolder, type); if (!Directory.Exists(fold)) { Directory.CreateDirectory(fold); } Log.Debug("StartBuildAB:" + fold); BuildPipeline.BuildAssetBundles(fold, buildAssetBundleOptions, buildTarget); //创建版本文件信息 GenerateVersionInfo(fold); if (isContainAB) { Log.Debug("CreateSA"); FileHelper.CleanDirectory("Assets/StreamingAssets/"); Log.Debug("将资源拷贝到SA"); FileHelper.CopyDirectory(fold, "Assets/StreamingAssets/"); } if (isBuildExe) { AssetDatabase.Refresh(); string[] levels = { "Assets/Scenes/Init.unity", }; BuildPipeline.BuildPlayer(levels, $"{relativeDirPrefix}/{exeName}", buildTarget, buildOptions); Log.Debug("完成exe打包"); } }
public static void Gen() { ProcessHelper.Run("dotnet", "Proto2CS.dll", "..\\Tools\\Proto2CS\\Bin\\", false); FileHelper.CleanDirectory("Assets\\Bundles\\Lua\\pbc\\AutoGeneratedCode\\"); File.Copy("..\\Proto\\OuterMessage.proto", "Assets\\Bundles\\Lua\\pbc\\AutoGeneratedCode\\OuterMessage.txt"); AssetDatabase.Refresh(); }
public static void Build(PlatformType type, BuildAssetBundleOptions buildAssetBundleOptions, BuildOptions buildOptions, bool isBuildExe, bool isContainAB, string version) { BuildTarget buildTarget = BuildTarget.StandaloneWindows; string exeName = "ET"; switch (type) { case PlatformType.PC: buildTarget = BuildTarget.StandaloneWindows64; exeName += ".exe"; break; case PlatformType.Android: buildTarget = BuildTarget.Android; exeName += ".apk"; break; case PlatformType.IOS: buildTarget = BuildTarget.iOS; break; case PlatformType.MacOS: buildTarget = BuildTarget.StandaloneOSX; break; } string fold = string.Format(BuildFolder, type, version); if (!Directory.Exists(fold)) { Directory.CreateDirectory(fold); } Log.Info("<color=yellow>开始资源打包</color>"); BuildPipeline.BuildAssetBundles(fold, buildAssetBundleOptions, buildTarget); GenerateVersionInfo(fold); Log.Info($"<color=yellow>完成资源打包----------------->>>{fold}</color>"); if (isContainAB) { FileHelper.CleanDirectory("Assets/StreamingAssets/"); FileHelper.CopyDirectory(fold, "Assets/StreamingAssets/"); } if (isBuildExe) { AssetDatabase.Refresh(); string[] levels = { "Assets/Scenes/Init.unity", }; Log.Info("开始EXE打包"); BuildPipeline.BuildPlayer(levels, $"{relativeDirPrefix}/{exeName}", buildTarget, buildOptions); Log.Info("完成exe打包"); } }
public static void Build(PlatformType type, BuildAssetBundleOptions buildAssetBundleOptions, BuildOptions buildOptions, bool isBuildExe, bool isContainAB) { BuildTarget buildTarget = BuildTarget.StandaloneWindows; switch (type) { case PlatformType.PC: buildTarget = BuildTarget.StandaloneWindows64; exeName += ".exe"; break; case PlatformType.Android: buildTarget = BuildTarget.Android; exeName += ".apk"; break; case PlatformType.IOS: buildTarget = BuildTarget.iOS; break; case PlatformType.MacOS: buildTarget = BuildTarget.StandaloneOSX; break; } string fold = "Assets/StreamingAssets/"; if (!Directory.Exists(fold)) { Directory.CreateDirectory(fold); } GenerateVersionInfo(fold); Log.Info("完成00Version.txt"); if (isContainAB) { FileHelper.CleanDirectory("Assets/StreamingAssets/"); FileHelper.CopyDirectory(fold, "Assets/StreamingAssets/"); } if (isBuildExe) { AssetDatabase.Refresh(); string[] levels = { $"Assets/Scenes/{sceneName}.unity", }; Log.Info("开始EXE打包"); BuildPipeline.BuildPlayer(levels, $"{relativeDirPrefix}/{exeName}", buildTarget, buildOptions); Log.Info("完成exe打包"); } }
public static void Build(PlatformType type, BuildAssetBundleOptions buildAssetBundleOptions, BuildOptions buildOptions, bool isBuildExe, bool isContainAB) { BuildTarget buildTarget = BuildTarget.StandaloneWindows; string exeName = "ET"; switch (type) { case PlatformType.PC: buildTarget = BuildTarget.StandaloneWindows64; exeName += ".exe"; break; case PlatformType.Android: buildTarget = BuildTarget.Android; exeName += ".apk"; break; case PlatformType.IOS: buildTarget = BuildTarget.iOS; break; case PlatformType.MacOS: buildTarget = BuildTarget.StandaloneOSX; break; } string fold = string.Format(BuildFolder, type); if (!Directory.Exists(fold)) { Directory.CreateDirectory(fold); } Log.Info("开始资源打包"); BuildPipeline.BuildAssetBundles(fold, buildAssetBundleOptions, buildTarget); GenerateVersionInfo(fold); Log.Info("完成资源打包"); if (isContainAB) { FileHelper.CleanDirectory("Assets/StreamingAssets/"); FileHelper.CopyDirectory(fold, "Assets/StreamingAssets/"); } if (isBuildExe) { string[] levels = EditorBuildSettingsScene.GetActiveSceneList(EditorBuildSettings.scenes); Log.Info("开始EXE打包"); BuildPipeline.BuildPlayer(levels, $"{relativeDirPrefix}/{exeName}", buildTarget, buildOptions); Log.Info("完成exe打包"); } }
public static bool Build(string target, string versionName, bool isClearStreamingAssetsFolder, bool isCopyToStreamingAssetsFolder, bool isBuildAssets, bool isBuildExecutor) { if (AddressableAssetSettingsDefaultObject.Settings == null) { EditorWindow.GetWindow <AddressableAssetsEditorWindow>().ShowNotification(new UnityEngine.GUIContent("请先通过\nWindow/Asset Management/Addressables/Groups\n打开面板\n并创建基础资源!")); return(false); } AddressableAssetSettings settings = AssetDatabase.LoadAssetAtPath <AddressableAssetSettings>($"{AddressableAssetSettingsDefaultObject.kDefaultConfigFolder}/{AddressableAssetSettingsDefaultObject.kDefaultConfigAssetName}.asset"); //if (settings.profileSettings.GetVariableNames().Contains(kStreamingLoadPath)) //{ // settings.profileSettings.SetValue(settings.profileSettings.GetProfileId("Default"), kStreamingLoadPath, "{UnityEngine.Application.streamingAssetsPath}/[BuildTarget]"); //} //else //{ // settings.profileSettings.CreateValue(kStreamingLoadPath, "{UnityEngine.Application.streamingAssetsPath}/[BuildTarget]"); //} if (bundleNamingPropertyInfo == null) { bundleNamingPropertyInfo = typeof(BundledAssetGroupSchema).GetProperty("BundleNaming", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); } //更新Group模板的发布路径和加载路径 UpdateGroupTemplateBuildAndLoadPath(settings, $"{settings.GroupTemplateFolder}/Packed Assets.asset"); UpdateGroupBuildAndLoadPath(settings, $"{settings.GroupFolder}/Default Local Group.asset"); //清除旧有资源 CleanGroup(settings); //自动生成Group List <AddressableAssetGroupSchema> schemas = AssetDatabase.LoadAssetAtPath <AddressableAssetGroupTemplate>($"{settings.GroupTemplateFolder}/Packed Assets.asset").SchemaObjects; string[] directories = Directory.GetDirectories($"{UnityEngine.Application.dataPath}/AddressableAssets/"); //string remoteBuildPath = $"./{settings.profileSettings.GetValueByName(settings.profileSettings.GetProfileId("Default"), AddressableAssetSettings.kRemoteBuildPath).Replace("[BuildTarget]", UnityEditor.EditorUserBuildSettings.activeBuildTarget.ToString())}"; //string localBuildPath = $"./{settings.profileSettings.GetValueByName(settings.profileSettings.GetProfileId("Default"), AddressableAssetSettings.kLocalBuildPath).Replace("[UnityEngine.AddressableAssets.Addressables.BuildPath]", UnityEngine.AddressableAssets.Addressables.BuildPath).Replace("[BuildTarget]", UnityEditor.EditorUserBuildSettings.activeBuildTarget.ToString())}"; string buildPath = $"./{UnityEngine.AddressableAssets.Addressables.BuildPath}"; tempAddress = string.Empty; foreach (string folderPath in directories) { if (folderPath.Substring(folderPath.LastIndexOf('/') + 1).StartsWith("~")) { continue; } BuildGroup(folderPath, settings, schemas); } //生成资源地址 GenerateAddress(settings); //打包资源 if (isBuildAssets) { FileHelper.CleanDirectory("Assets/ServerData/"); AddressableAssetSettings.CleanPlayerContent(); AddressableAssetSettings.BuildPlayerContent(); if (!Directory.Exists(UnityEngine.Application.streamingAssetsPath)) { Directory.CreateDirectory(UnityEngine.Application.streamingAssetsPath); } //复制打包资源到服务器资源文件夹 FileHelper.CopyDirectory(buildPath.Substring(0, buildPath.IndexOf("aa")), $"../Release/{UnityEditor.EditorUserBuildSettings.activeBuildTarget}/{versionName}/"); AssetDatabase.Refresh(); } if (isBuildExecutor) { string[] levels = { "Assets/Scenes/Init.unity", }; DirectoryInfo directoryInfo = new System.IO.DirectoryInfo($"{relativeDirPrefix}/{UnityEditor.EditorUserBuildSettings.activeBuildTarget}/发布文件/{PlayerSettings.productName}_{UnityEngine.SystemInfo.deviceName}_{System.DateTime.Now.ToString("yyyyMMddmmHHss")}/"); if (!directoryInfo.Exists) { directoryInfo.Create(); } Log.Info("开始打包可执行文件..."); BuildPipeline.BuildPlayer(levels, $"{directoryInfo.FullName}{PlayerSettings.productName}.exe", EditorUserBuildSettings.activeBuildTarget, BuildOptions.None); Log.Info("可执行文件打包完成."); AssetDatabase.Refresh(); System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo.FileName = "explorer"; process.StartInfo.Arguments = @"/e /root," + directoryInfo.FullName; process.Start(); } Log.Info("完成"); return(true); }