private static void BuildWorkerForTarget(string workerType, BuildTarget buildTarget, BuildOptions buildOptions, BuildEnvironment targetEnvironment) { Debug.LogFormat("Building \"{0}\" for worker platform: \"{1}\", environment: \"{2}\"", buildTarget, workerType, targetEnvironment); var spatialOSBuildConfiguration = SpatialOSBuildConfiguration.instance; var workerBuildData = new WorkerBuildData(workerType, buildTarget); var scenes = spatialOSBuildConfiguration.GetScenePathsForWorker(workerType); var buildPlayerOptions = new BuildPlayerOptions { options = buildOptions, target = buildTarget, scenes = scenes, locationPathName = workerBuildData.BuildScratchDirectory }; var result = BuildPipeline.BuildPlayer(buildPlayerOptions); if (result.summary.result != BuildResult.Succeeded) { throw new BuildFailedException($"Build failed for {workerType}"); } var zipPath = Path.Combine(PlayerBuildDirectory, workerBuildData.PackageName); var basePath = Path.Combine(EditorPaths.BuildScratchDirectory, workerBuildData.PackageName); Zip(zipPath, basePath, targetEnvironment == BuildEnvironment.Cloud); }
private static void BuildWorkerForTarget(string workerType, BuildTarget buildTarget, BuildOptions buildOptions, BuildEnvironment targetEnvironment) { Debug.Log($"Building \"{buildTarget}\" for worker platform: \"{workerType}\", environment: \"{targetEnvironment}\""); var spatialOSBuildConfiguration = SpatialOSBuildConfiguration.GetInstance(); var workerBuildData = new WorkerBuildData(workerType, buildTarget); var scenes = spatialOSBuildConfiguration.GetScenePathsForWorker(workerType); var buildPlayerOptions = new BuildPlayerOptions { options = buildOptions, target = buildTarget, scenes = scenes, locationPathName = workerBuildData.BuildScratchDirectory }; var result = BuildPipeline.BuildPlayer(buildPlayerOptions); if (result.summary.result != BuildResult.Succeeded) { throw new BuildFailedException($"Build failed for {workerType}"); } if (buildTarget == BuildTarget.Android || buildTarget == BuildTarget.iOS) { // Mobile clients can only be run locally, no need to package them return; } var zipPath = Path.Combine(PlayerBuildDirectory, workerBuildData.PackageName); var basePath = Path.Combine(EditorPaths.BuildScratchDirectory, workerBuildData.PackageName); Zip(zipPath, basePath, targetEnvironment == BuildEnvironment.Cloud); }
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); 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); var buildPlayerOptions = new BuildPlayerOptions { options = buildOptions, target = buildTarget, scenes = scenes, locationPathName = workerBuildData.BuildScratchDirectory }; var result = BuildPipeline.BuildPlayer(buildPlayerOptions); if (result.summary.result != BuildResult.Succeeded) { throw new BuildFailedException($"Build failed for {workerPlatform}"); } var zipPath = Path.GetFullPath(Path.Combine(PlayerBuildDirectory, workerBuildData.PackageName)); var basePath = PathUtil.Combine(BuildPaths.BuildScratchDirectory, workerBuildData.PackageName); Zip(zipPath, basePath, targetEnvironment == BuildEnvironment.Local ? PlayerCompression.Disabled : PlayerCompression.Enabled); } finally { PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone, symbols); } }
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(); } }
private static void BuildWorkerWithContext( BuildContext buildContext) { var spatialOsBuildConfiguration = BuildConfig.GetInstance(); Debug.Log( $"Building \"{buildContext.WorkerType}\" for platform: \"{buildContext.BuildTargetConfig.Target}\", environment: \"{buildContext.BuildEnvironment}\""); var workerBuildData = new WorkerBuildData(buildContext.WorkerType, buildContext.BuildTargetConfig.Target); var scenes = spatialOsBuildConfiguration.GetScenePathsForWorker(buildContext.WorkerType); var buildPlayerOptions = new BuildPlayerOptions { options = buildContext.BuildTargetConfig.Options, target = buildContext.BuildTargetConfig.Target, scenes = scenes, locationPathName = workerBuildData.BuildScratchDirectory }; var buildTargetGroup = BuildPipeline.GetBuildTargetGroup(buildContext.BuildTargetConfig.Target); var activeScriptingBackend = PlayerSettings.GetScriptingBackend(buildTargetGroup); if (activeScriptingBackend != buildContext.ScriptingImplementation) { PlayerSettings.SetScriptingBackend(buildTargetGroup, buildContext.ScriptingImplementation); } var activeIOSSdkVersion = PlayerSettings.iOS.sdkVersion; if (buildContext.IOSSdkVersion.HasValue && activeIOSSdkVersion != buildContext.IOSSdkVersion) { PlayerSettings.iOS.sdkVersion = buildContext.IOSSdkVersion.Value; } try { currentContext = buildContext; var result = BuildPipeline.BuildPlayer(buildPlayerOptions); if (result.summary.result != BuildResult.Succeeded) { if (buildContext.BuildTargetConfig.Target == BuildTarget.Android && string.IsNullOrEmpty(EditorPrefs.GetString("AndroidSdkRoot"))) { Debug.LogWarning($"Unable to build worker {buildContext.WorkerType} for platform Android. " + $"Ensure you have the Android SDK set inside the Unity Editor Preferences."); } throw new BuildFailedException($"Build failed for {buildContext.WorkerType}"); } } catch (Exception e) { if (e is BuildFailedException) { throw; } throw new BuildFailedException(e); } finally { currentContext = null; PlayerSettings.iOS.sdkVersion = activeIOSSdkVersion; PlayerSettings.SetScriptingBackend(buildTargetGroup, activeScriptingBackend); } if (buildContext.BuildTargetConfig.Target == BuildTarget.StandaloneOSX) { // Unity executable name has changed on MacOS // This is a temp work around our Launcher trying to run the wrong file. // See [UTY-2294] CreateLaunchJson(workerBuildData.PackageName, Application.productName); } // Package up standalone builds if (buildContext.BuildTargetConfig.Target != BuildTarget.Android && buildContext.BuildTargetConfig.Target != BuildTarget.iOS) { Package(workerBuildData.PackageName, buildContext.BuildEnvironment == BuildEnvironment.Cloud); } }
private static bool BuildWorkerForTarget( string workerType, BuildEnvironment targetEnvironment, BuildTarget buildTarget, BuildOptions buildOptions) { var spatialOSBuildConfiguration = BuildConfig.GetInstance(); if (!WorkerBuildData.BuildTargetsThatCanBeBuilt[buildTarget]) { var config = spatialOSBuildConfiguration.GetEnvironmentConfigForWorker(workerType, targetEnvironment); var target = config.BuildTargets.First(targetConfig => targetConfig.Target == buildTarget); if (target.Required) { throw new BuildFailedException( $"Build failed for {workerType}. Cannot build for required {buildTarget} because build support is not installed in the Unity Editor."); } Debug.LogWarning($"Skipping {buildTarget} because build support is not installed in the Unity Editor and the build target is not marked as 'Required'."); return(false); } Debug.Log( $"Building \"{buildTarget}\" for worker platform: \"{workerType}\", environment: \"{targetEnvironment}\""); var workerBuildData = new WorkerBuildData(workerType, buildTarget); var scenes = spatialOSBuildConfiguration.GetScenePathsForWorker(workerType); var buildPlayerOptions = new BuildPlayerOptions { options = buildOptions, target = buildTarget, scenes = scenes, locationPathName = workerBuildData.BuildScratchDirectory }; var result = BuildPipeline.BuildPlayer(buildPlayerOptions); if (result.summary.result != BuildResult.Succeeded) { if (buildTarget == BuildTarget.Android && string.IsNullOrEmpty(EditorPrefs.GetString("AndroidSdkRoot"))) { Debug.LogWarning($"Unable to build worker {workerType} for platform Android. " + $"Ensure you have the Android SDK set inside the Unity Editor Preferences."); return(false); } throw new BuildFailedException($"Build failed for {workerType}"); } if (buildTarget == BuildTarget.Android || buildTarget == BuildTarget.iOS) { // Mobile clients can only be run locally, no need to package them return(true); } if (buildTarget == BuildTarget.StandaloneOSX) { // Unity executable name has changed on MacOS // This is a temp work around our Launcher trying to run the wrong file. // See [UTY-2294] CreateLaunchJson(workerBuildData.PackageName, Application.productName); } var zipPath = Path.Combine(PlayerBuildDirectory, workerBuildData.PackageName); var basePath = Path.Combine(Common.BuildScratchDirectory, workerBuildData.PackageName); Zip(zipPath, basePath, targetEnvironment == BuildEnvironment.Cloud); return(true); }