Ejemplo n.º 1
0
        static BuildTarget Supported2Target(SupportedBuild supported)
        {
            switch (supported)
            {
            case SupportedBuild.Android:
                return(BuildTarget.Android);

            case SupportedBuild.iOS:
                return(BuildTarget.iOS);

            case SupportedBuild.StandaloneLinux:
                return(BuildTarget.StandaloneLinux);

            case SupportedBuild.StandaloneLinux64:
                return(BuildTarget.StandaloneLinux64);

            case SupportedBuild.StandaloneLinuxUniversal:
                return(BuildTarget.StandaloneLinuxUniversal);

            case SupportedBuild.StandaloneOSX:
                return(BuildTarget.StandaloneOSX);

            case SupportedBuild.StandaloneWindows:
                return(BuildTarget.StandaloneWindows);

            case SupportedBuild.StandaloneWindows64:
                return(BuildTarget.StandaloneWindows64);

            case SupportedBuild.WebGL:
                return(BuildTarget.WebGL);
            }
            return(BuildTarget.NoTarget);
        }
Ejemplo n.º 2
0
        static bool BuildPlayer(EditorBuildSettingsScene[] scenes, BuildOptions options, string versionDir, string productName, SupportedBuild buildTarget, bool autoRun, string[] customDefines, string bundleID)
        {
            BuildTarget target = Supported2Target(buildTarget);
            string      dir    = GenerateBuildDirectory(versionDir, target, out bool dirExists);

            if (dirExists)
            {
                if (EditorUtility.DisplayDialog("Overwrite Build", "Overwrite build at path: '" + dir + "' ?", "Yes", "No"))
                {
                    Directory.Delete(dir);
                }
                else
                {
                    return(false);
                }
            }

            if (autoRun)
            {
                options |= BuildOptions.AutoRunPlayer;
            }

            string fileName = string.Format(BinaryNameFormat(target), productName);

            BuildTargetGroup targetGroup      = GetBuildTargetGroup(target);
            string           preBuildDefines  = PlayerSettings.GetScriptingDefineSymbolsForGroup(targetGroup);
            string           preBuildBundleID = PlayerSettings.GetApplicationIdentifier(targetGroup);

            PlayerSettings.SetApplicationIdentifier(targetGroup, bundleID);

            string defines = preBuildDefines;

            if (customDefines != null)
            {
                defines += ";" + string.Join(";", customDefines);
            }

            PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup, defines);
            //Debug.Log("Build Defines: " + defines);

            /*
             * // APPLY ANDROID VARIANTS
             * PlayerSettings.Android.targetArchitectures = (AndroidArchitecture)System.Enum.Parse(typeof(AndroidArchitecture), { "FAT", "ARMv7", "x86" });
             * EditorUserBuildSettings.androidBuildSubtarget = (MobileTextureSubtarget)System.Enum.Parse(typeof(MobileTextureSubtarget), { "ETC", "ETC2", "ASTC", "DXT", "PVRTC", "ATC", "Generic" });
             * EditorUserBuildSettings.androidBuildSystem = (AndroidBuildSystem)System.Enum.Parse(typeof(AndroidBuildSystem), { "Internal", "Gradle", "ADT (Legacy)" });
             */

            string error  = "";
            var    report = BuildPipeline.BuildPlayer(scenes, Path.Combine(dir, fileName), target, options);

            if (report.summary.result == UnityEditor.Build.Reporting.BuildResult.Failed)
            {
                error = report.summary.totalErrors + " occurred.";
            }

            bool success = string.IsNullOrEmpty(error);

            if (!success)
            {
                Debug.LogError("Build Failed: " + target.ToString() + "\n" + error);
            }

            // Restore pre-build settings.
            PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup, preBuildDefines);
            PlayerSettings.SetApplicationIdentifier(targetGroup, preBuildBundleID);

            return(success);
        }