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 PrepareEntityPrefabs(PlayModeStateChange state) { // Only do this when we go from edit mode to play mode if (state != PlayModeStateChange.ExitingEditMode) { return; } // Only export if the scene uses a BasicTemplateProvider var provider = Object.FindObjectOfType <BasicTemplateProvider>(); if (provider != null) { // Get worker platform var workerPlatform = provider.platform; Debug.LogFormat("Preparing EntityPrefabs for {0}", workerPlatform.ToString()); // Start prefab export EntityPrefabs.Export(workerPlatform); } }
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(); } }