/// <summary> /// Build method that is invoked by commandline /// </summary> public static void Build() { try { var commandLine = Environment.GetCommandLineArgs(); Debug.LogFormat("Want to build with args: {0}", String.Join(", ", commandLine)); var buildTargetArg = CommandLineUtil.GetCommandLineValue(commandLine, "buildTarget", "local"); if (string.IsNullOrEmpty(buildTargetArg)) { // The default above does not get filled when -t parameter is not passed buildTargetArg = BuildEnvironment.Local.ToString(); Debug.LogWarningFormat("Using default build target value: \"{0}\".", buildTargetArg); } BuildEnvironment buildEnvironment; switch (buildTargetArg.ToLower()) { case "cloud": buildEnvironment = BuildEnvironment.Cloud; break; case "local": buildEnvironment = BuildEnvironment.Local; break; default: throw new BuildFailedException("Unknown build target value: " + buildTargetArg); } var workerTypesArg = CommandLineUtil.GetCommandLineValue(commandLine, ConfigNames.BuildWorkerTypes, "UnityClient,UnityWorker"); var wantedWorkerPlatforms = GetWorkerPlatforms(workerTypesArg); SpatialCommands.GenerateBuildConfiguration(); foreach (var workerPlatform in wantedWorkerPlatforms) { BuildWorkerForEnvironment(workerPlatform, buildEnvironment); } } catch (Exception e) { // Log the exception so it appears in the command line, and rethrow as a BuildFailedException so the build fails. Debug.LogException(e); if (e is BuildFailedException) { throw; } throw new BuildFailedException(e); } }
private static void BuildWorkerForTarget(WorkerPlatform workerPlatform, BuildTarget buildTarget, BuildOptions buildOptions, BuildEnvironment targetEnvironment) { var spatialOSBuildConfiguration = GetBuildConfiguration(); Debug.LogFormat("Building \"{0}\" for worker platform: \"{1}\", environment: \"{2}\"", buildTarget, workerPlatform, targetEnvironment); EntityPrefabs.Export(workerPlatform); var symbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone); try { var workerBuildData = new WorkerBuildData(workerPlatform, buildTarget); var scenes = spatialOSBuildConfiguration.GetScenePathsForWorker(workerPlatform); var typeSymbol = "IMPROBABLE_WORKERTYPE_" + workerBuildData.WorkerPlatformName.ToUpper(); var workerSymbols = symbols.Split(';') .Concat(new[] { typeSymbol }) .Distinct() .Aggregate((current, next) => current + ";" + next); PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone, workerSymbols); BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions { options = buildOptions, target = buildTarget, scenes = scenes, locationPathName = workerBuildData.BuildScratchDirectory }; BuildPipeline.BuildPlayer(buildPlayerOptions); var zipPath = Path.GetFullPath(Path.Combine(PlayerBuildDirectory, workerBuildData.PackageName)); var basePath = PathUtil.Combine(BuildPaths.BuildScratchDirectory, workerBuildData.PackageName); SpatialCommands.Zip(zipPath, basePath, targetEnvironment == BuildEnvironment.Local ? PlayerCompression.Disabled : PlayerCompression.Enabled); } finally { PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone, symbols); EntityPrefabs.Clean(); } }
private static void MenuBuild(IEnumerable <WorkerPlatform> platforms, BuildEnvironment environment) { // Delaying build by a frame to ensure the editor has re-rendered the UI to avoid odd glitches. EditorApplication.delayCall += () => { Debug.Log("Generating build configuration"); SpatialCommands.GenerateBuildConfiguration(); foreach (var platform in platforms) { WorkerBuilder.BuildWorkerForEnvironment(platform, environment); } Debug.LogFormat("Completed build for {0} target", environment); }; }
private static void BuildWorkerForTarget(WorkerPlatform workerPlatform, BuildTarget buildTarget, BuildOptions buildOptions, BuildEnvironment targetEnvironment) { var spatialOSBuildConfiguration = GetBuildConfiguration(); Debug.LogFormat("Building \"{0}\" for worker platform: \"{1}\", environment: \"{2}\"", buildTarget, workerPlatform, targetEnvironment); EntityPrefabs.Export(workerPlatform); var symbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone); try { var workerBuildData = new WorkerBuildData(workerPlatform, buildTarget); var scenes = spatialOSBuildConfiguration.GetScenePathsForWorker(workerPlatform); var typeSymbol = "IMPROBABLE_WORKERTYPE_" + workerBuildData.WorkerPlatformName.ToUpper(); var workerSymbols = symbols.Split(';') .Concat(new[] { typeSymbol }) .Distinct() .Aggregate((current, next) => current + ";" + next); PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone, workerSymbols); BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions { options = buildOptions, target = buildTarget, scenes = scenes, locationPathName = workerBuildData.BuildScratchDirectory }; var buildConfigString = string.Format("WorkerPlatform={0};BuildTarget={1};BuildOptions={2}", workerPlatform, buildTarget, buildOptions); var buildErrorMessage = BuildPipeline.BuildPlayer(buildPlayerOptions); #if UNITY_2018_1_OR_NEWER if (buildErrorMessage.summary.result != UnityEditor.Build.Reporting.BuildResult.Succeeded) { throw new ApplicationException(string.Format("Failed to build player {0} due to {1} errors", buildConfigString, buildErrorMessage.summary.totalErrors)); } #else if (!string.IsNullOrEmpty(buildErrorMessage)) { throw new ApplicationException(string.Format("Failed to build player {0} due to {1}", buildConfigString, buildErrorMessage)); } #endif Debug.LogFormat("Built player {0} into {1}", buildConfigString, workerBuildData.BuildScratchDirectory); var zipPath = Path.GetFullPath(Path.Combine(PlayerBuildDirectory, workerBuildData.PackageName)); var basePath = PathUtil.Combine(BuildPaths.BuildScratchDirectory, workerBuildData.PackageName); SpatialCommands.Zip(zipPath, basePath, targetEnvironment == BuildEnvironment.Local ? PlayerCompression.Disabled : PlayerCompression.Enabled); } finally { PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone, symbols); EntityPrefabs.Clean(); } }