private static bool BuildPlayer(string notification, BuildReleaseType releaseType, BuildPlatform platform, BuildArchitecture architecture, BuildDistribution distribution, DateTime buildTime, BuildOptions options, string configKey) { bool success = true; // Get build options. if (releaseType.developmentBuild) { options |= BuildOptions.Development; } if (releaseType.allowDebugging) { options |= BuildOptions.AllowDebugging; } if (releaseType.enableHeadlessMode) { options |= BuildOptions.EnableHeadlessMode; } // Generate build path. string buildPath = GenerateBuildPath(BuildSettings.basicSettings.buildPath, releaseType, platform, architecture, distribution, buildTime); string exeName = string.Format(platform.binaryNameFormat, SanitizeFileName(releaseType.productName)); // Save current user defines, and then set target defines. string preBuildDefines = PlayerSettings.GetScriptingDefineSymbolsForGroup(platform.targetGroup); string buildDefines = GenerateDefaultDefines(releaseType, platform, architecture, distribution); buildDefines = MergeDefines(preBuildDefines, buildDefines); PlayerSettings.SetScriptingDefineSymbolsForGroup(platform.targetGroup, buildDefines); //Debug.Log("Build Defines: " + buildDefines); // Set bundle info. // Unfortunately, there's not a good way to do this pre-5.6 that doesn't break building w/ batch mode. #if UNITY_5_6_OR_NEWER PlayerSettings.SetApplicationIdentifier(platform.targetGroup, releaseType.bundleIndentifier); #endif // Set product name. PlayerSettings.companyName = releaseType.companyName; PlayerSettings.productName = releaseType.productName; // Apply build variant. platform.ApplyVariant(); // Pre-build actions. PerformPreBuild(releaseType, platform, architecture, distribution, buildTime, ref options, configKey, buildPath); // Generate BuildConstants. BuildConstantsGenerator.Generate(buildTime, BuildSettings.productParameters.lastGeneratedVersion, releaseType, platform, architecture, distribution); // Refresh scene list to make sure nothing has been deleted or moved. releaseType.sceneList.Refresh(); // Report build starting. BuildNotificationList.instance.AddNotification(new BuildNotification( BuildNotification.Category.Notification, notification, configKey, true, null)); // Build player. FileUtil.DeleteFileOrDirectory(buildPath); string error = ""; #if UNITY_2018_1_OR_NEWER UnityEditor.Build.Reporting.BuildReport buildReport = BuildPipeline.BuildPlayer(releaseType.sceneList.GetSceneFileList(), Path.Combine(buildPath, exeName), architecture.target, options); if (buildReport.summary.result == UnityEditor.Build.Reporting.BuildResult.Failed) { error = buildReport.summary.totalErrors + " occurred."; } #else error = BuildPipeline.BuildPlayer(releaseType.sceneList.GetSceneFileList(), Path.Combine(buildPath, exeName), architecture.target, options); #endif if (!string.IsNullOrEmpty(error)) { success = false; BuildNotificationList.instance.AddNotification(new BuildNotification( BuildNotification.Category.Error, "Build Failed:", configKey.ToString() + "\n" + error, true, null)); } // Post-build actions. PerformPostBuild(releaseType, platform, architecture, distribution, buildTime, ref options, configKey, buildPath); // Restore pre-build settings. PlayerSettings.SetScriptingDefineSymbolsForGroup(platform.targetGroup, preBuildDefines); return(success); }
private static bool BuildPlayer(string notification, BuildReleaseType releaseType, BuildPlatform platform, BuildArchitecture architecture, BuildDistribution distribution, DateTime buildTime, BuildOptions options, string configKey) { bool success = true; // Get build options.获取生成选项。 if (releaseType.developmentBuild) { options |= BuildOptions.Development; } if (releaseType.allowDebugging) { options |= BuildOptions.AllowDebugging; } if (releaseType.enableHeadlessMode) { options |= BuildOptions.EnableHeadlessMode; } // Generate build path.生成生成路径。 string buildPath = GenerateBuildPath(BuildSettings.basicSettings.buildPath, releaseType, platform, architecture, distribution, buildTime); string binName = string.Format(architecture.binaryNameFormat, SanitizeFileName(releaseType.productName)); // Save current user defines, and then set target defines.保存当前用户定义,然后设置目标定义。 string preBuildDefines = PlayerSettings.GetScriptingDefineSymbolsForGroup(platform.targetGroup); string buildDefines = GenerateDefaultDefines(releaseType, platform, architecture, distribution); buildDefines = MergeDefines(preBuildDefines, buildDefines); PlayerSettings.SetScriptingDefineSymbolsForGroup(platform.targetGroup, buildDefines); //Debug.Log("Build Defines: " + buildDefines); // Save current player settings, and then set target settings.保存当前播放机设置,然后设置目标设置。 string preBuildCompanyName = PlayerSettings.companyName; string preBuildProductName = PlayerSettings.productName; PlayerSettings.companyName = releaseType.companyName; PlayerSettings.productName = releaseType.productName; // Set bundle info.设置捆绑信息。 // Unfortunately, there's not a good way to do this pre-5.6 that doesn't break building w/ batch mode.不幸的是,在5.6之前没有一个好的方法可以不破坏构建w/batch模式。 #if UNITY_5_6_OR_NEWER string preBuildBundleIdentifier = PlayerSettings.GetApplicationIdentifier(platform.targetGroup); PlayerSettings.SetApplicationIdentifier(platform.targetGroup, releaseType.bundleIndentifier); #endif // Apply build variant.应用生成变量。 platform.ApplyVariant(); // Pre-build actions.预构建操作。 PerformPreBuild(releaseType, platform, architecture, distribution, buildTime, ref options, configKey, buildPath); // Generate BuildConstants.生成生成常量。 BuildConstantsGenerator.Generate(buildTime, BuildSettings.productParameters.lastGeneratedVersion, releaseType, platform, architecture, distribution); // Refresh scene list to make sure nothing has been deleted or moved.刷新场景列表以确保未删除或移动任何内容。 releaseType.sceneList.Refresh(); // Report build starting.发布生成开始。 BuildNotificationList.instance.AddNotification(new BuildNotification( BuildNotification.Category.Notification, notification, configKey, true, null)); // Build player. FileUtil.DeleteFileOrDirectory(buildPath); string error = ""; #if UNITY_2018_1_OR_NEWER // string[] levels = BuildInfomation.levels; ///// Debug.Log("这里才开始生成"); //string parth = BuildInfomation. Pathlevels+"/Test.exe"; // string[]levels = new string[] { "Assets/Scenes/2.unity" }; string[] levels = BuildInfomation.levels; ///\ Debug.Log("这里才开始生成"); string parth = BuildInfomation.Pathlevels; Debug.Log(parth); // Debug.Log("这里才开始生成---"+ BuildInfomation.levels[0].ToString()+"---"+ parth); // Debug.Log(releaseType.sceneList.GetSceneFileList() + " --AAA-- " + Path.Combine(buildPath, binName) ); // UnityEditor.Build.Reporting.BuildReport buildReport = BuildPipeline.BuildPlayer(levels, @"C:/Users/YNHol/Desktop/00000000000000/Scenes3/Test.exe", BuildTarget.StandaloneWindows, BuildOptions.None); UnityEditor.Build.Reporting.BuildReport buildReport = BuildPipeline.BuildPlayer(levels, parth, BuildTarget.WebGL, BuildOptions.None); // UnityEditor.Build.Reporting.BuildReport buildReport = BuildPipeline.BuildPlayer(releaseType.sceneList.GetSceneFileList(), Path.Combine(buildPath, binName), architecture.target, options); // Debug.Log(levels[0].ToString() + "__生产___" + parth); ; foreach (var item in releaseType.sceneList.GetSceneFileList()) { Debug.Log(item); } // Debug.Log("这里生成开始完毕"); if (buildReport.summary.result == UnityEditor.Build.Reporting.BuildResult.Failed) { error = buildReport.summary.totalErrors + " occurred."; } #else error = BuildPipeline.BuildPlayer(releaseType.sceneList.GetSceneFileList(), Path.Combine(buildPath, binName), architecture.target, options); #endif if (!string.IsNullOrEmpty(error)) { success = false; BuildNotificationList.instance.AddNotification(new BuildNotification( BuildNotification.Category.Error, "Build Failed:", configKey.ToString() + "\n" + error, true, null)); } // Post-build actions. PerformPostBuild(releaseType, platform, architecture, distribution, buildTime, ref options, configKey, buildPath); // Restore pre-build settings. PlayerSettings.SetScriptingDefineSymbolsForGroup(platform.targetGroup, preBuildDefines); PlayerSettings.companyName = preBuildCompanyName; PlayerSettings.productName = preBuildProductName; #if UNITY_5_6_OR_NEWER PlayerSettings.SetApplicationIdentifier(platform.targetGroup, preBuildBundleIdentifier); #endif /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Build_Over_Num++; Debug.Log("这里是北京时间:" + System.DateTime.Now + " 完成了___ " + Build_Over_Num + " ___个"); if (Build_Over_Num < File.ReadAllLines(Application.dataPath + "/Pathlevels.txt", Encoding.Default).Length) { BuildInfomation.Pathlevels = File.ReadAllLines(Application.dataPath + "/Pathlevels.txt", Encoding.Default)[Build_Over_Num]; BuildInfomation.levels = new string[] { File.ReadAllLines(Application.dataPath + "/levels.txt", Encoding.Default)[Build_Over_Num] }; BuildProject.BuildAll(); } else { Debug.Log("这里是北京时间:" + System.DateTime.Now + " 全部完成! " + Build_Over_Num + "个"); Build_Over_Num = 0; } return(success); }