Example #1
0
        /// <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 =
                    CommandLineUtility.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 =
                    CommandLineUtility.GetCommandLineValue(commandLine, BuildConfigNames.BuildWorkerTypes,
                                                           "UnityClient,UnityGameLogic");

                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);
            }
        }
Example #2
0
        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);

                SpatialCommands.Zip(zipPath, basePath,
                                    targetEnvironment == BuildEnvironment.Local
                        ? PlayerCompression.Disabled
                        : PlayerCompression.Enabled);
            }
            finally
            {
                PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone, symbols);
            }
        }
Example #3
0
        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);
            };
        }