Example #1
0
        // private
        private static BuildOptions OptionsForTarget(CookerPreset.Target target)
        {
            var options = BuildOptions.None;

            if (target.Headless)
            {
                options |= BuildOptions.EnableHeadlessMode;
            }

            switch (target.Type)
            {
            case CookerPreset.Target.BuildType.Debug:
                options |= BuildOptions.Development;
                options |= BuildOptions.AllowDebugging;
                break;

            case CookerPreset.Target.BuildType.Release:
                break;

            case CookerPreset.Target.BuildType.Shipping:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(options);
        }
Example #2
0
        /// <summary>
        ///     Builds target.
        /// </summary>
        /// <param name="target">The target.</param>
        public static void Build(CookerPreset.Target target)
        {
            if (!string.IsNullOrEmpty(target.PreBuildAction))
            {
                CallBuildEvent(target.PreBuildAction);
            }

            var scenes  = EditorBuildSettings.scenes.Select(scene => scene.path).ToArray();
            var defines = string.Join(";", DefineSymbolsForTarget(target));
            var options = OptionsForTarget(target);

            // use has some hacks, so we can use .exe for all platforms
            // it will be changed by the build pipeline
            var outputPath     = Path.Combine(BuildPath, target.OutputName);
            var outputPathName = Path.Combine(outputPath, target.ExecutableName);

            // delete the output directory if exists
            if (Directory.Exists(outputPathName))
            {
                // delete the directory
                Directory.Delete(outputPath, true);
            }

            // TODO: use separate CLI nogfx/headless unity through console/terminal with parameters
            // to build the game(do not block the current unity instance)

            // set define symbols and refresh
            PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone, defines);
            AssetDatabase.Refresh();

            // build!
            BuildPipeline.BuildPlayer(scenes.ToArray(), outputPathName, target.BuildTarget, options);

            if (target.BuildContent)
            {
                var assetBundleOutput = outputPath + "/" + target.ContentDirectoryName;

                // build clean content directory if needed
                if (Directory.Exists(assetBundleOutput))
                {
                    Directory.Delete(assetBundleOutput, true);
                }

                Directory.CreateDirectory(assetBundleOutput);

                // build content
                BuildPipeline.BuildAssetBundles(assetBundleOutput, target.ContentBuildOptions, target.BuildTarget);
            }

            if (!string.IsNullOrEmpty(target.PostBuildAction))
            {
                CallBuildEvent(target.PostBuildAction);
            }
        }
Example #3
0
        // private
        private static string[] DefineSymbolsForTarget(CookerPreset.Target target)
        {
            var defines = new List <string>
            {
                "UNITY_3D", "CATCH_EXCEPTIONS"
            };

            switch (target.Type)
            {
            case CookerPreset.Target.BuildType.Debug:
                defines.Add("DEBUG");
                break;

            case CookerPreset.Target.BuildType.Release:
                defines.Add("RELEASE");
                break;

            case CookerPreset.Target.BuildType.Shipping:
                defines.Add("SHIPPING");
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            defines.AddRange(target.DefineSymbols);

            switch (target.BuildTarget)
            {
            case BuildTarget.StandaloneOSX:
                defines.Add("OSX");
                defines.Add("OSX64");
                break;

            case BuildTarget.StandaloneWindows:
                defines.Add("WINDOWS");
                break;

            case BuildTarget.StandaloneWindows64:
                defines.Add("WINDOWS");
                defines.Add("WINDOWS64");
                break;

            case BuildTarget.StandaloneLinux64:
                defines.Add("LINUX");
                defines.Add("LINUX64");
                break;

            case BuildTarget.iOS:
                defines.Add("IOS");
                break;

            case BuildTarget.Android:
                defines.Add("ANDROID");
                break;

            case BuildTarget.WebGL:
                defines.Add("WEBGL");
                break;

            // TODO: we need more supported platforms
            default:
                throw new ArgumentOutOfRangeException();
            }

            return(defines.ToArray());
        }
Example #4
0
 /// <summary>
 ///     Uses defines from given target.
 /// </summary>
 public static void SetDefines(CookerPreset.Target target)
 {
     PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone,
                                                      string.Join(";", DefineSymbolsForTarget(target)));
 }