private void BrowseForFolder()
        {
            m_UseDefaultPath = false;
            var newPath = EditorUtility.OpenFolderPanel("Bundle Folder", m_OutputPath, string.Empty);

            if (!string.IsNullOrEmpty(newPath))
            {
                var gamePath = System.IO.Path.GetFullPath(".");
                gamePath = gamePath.Replace("\\", "/");
                if (newPath.StartsWith(gamePath) && newPath.Length > gamePath.Length)
                {
                    newPath = newPath.Remove(0, gamePath.Length + 1);
                }
                m_OutputPath = newPath;
                EditorUserBuildSettings.SetPlatformSettings(EditorUserBuildSettings.activeBuildTarget.ToString(), "AssetBundleOutputPath", m_OutputPath);
            }
        }
        public void WriteBootConfig()
        {
            // boot settings string format
            // <boot setting>:<value>[;<boot setting>:<value>]*
            bool firstEntry = true;
            var  sb         = new System.Text.StringBuilder();

            foreach (var kvp in bootConfigSettings)
            {
                if (!firstEntry)
                {
                    sb.Append(";");
                }
                sb.Append($"{kvp.Key}:{kvp.Value}");
                firstEntry = false;
            }

            string buildTargetName = BuildPipeline.GetBuildTargetName(buildReport.summary.platform);

            EditorUserBuildSettings.SetPlatformSettings(buildTargetName, kXrBootSettingsKey, sb.ToString());
        }
Esempio n. 3
0
        public void Setup()
        {
            m_InternetClientServer       = PlayerSettings.WSA.GetCapability(PlayerSettings.WSACapability.InternetClientServer);
            m_PrivateNetworkClientServer = PlayerSettings.WSA.GetCapability(PlayerSettings.WSACapability.PrivateNetworkClientServer);
            PlayerSettings.WSA.SetCapability(PlayerSettings.WSACapability.InternetClientServer, true);
            PlayerSettings.WSA.SetCapability(PlayerSettings.WSACapability.PrivateNetworkClientServer, true);

            // This setting is initialized only when Window Store App is selected from the Build Settings window, and
            // is typically an empty strings when running tests via UTR on the command-line.
            bool wsaSettingNotInitialized = string.IsNullOrEmpty(EditorUserBuildSettings.wsaArchitecture);

            // If WSA build settings aren't fully initialized or running from a build machine, specify a default build configuration.
            // Otherwise we can use the existing configuration specified by the user in Build Settings.
            if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("UNITY_THISISABUILDMACHINE")) || wsaSettingNotInitialized)
            {
                EditorUserBuildSettings.wsaSubtarget    = WSASubtarget.PC;
                EditorUserBuildSettings.wsaArchitecture = "x64";
                EditorUserBuildSettings.SetPlatformSettings(BuildPipeline.GetBuildTargetName(BuildTarget.WSAPlayer), k_SettingsBuildConfiguration, WSABuildType.Debug.ToString());
                EditorUserBuildSettings.wsaUWPBuildType = WSAUWPBuildType.ExecutableOnly;
                PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.WSA, Il2CppCompilerConfiguration.Debug);
            }
        }
Esempio n. 4
0
            public override void Update(VisualElement root)
            {
                base.Update(root);

                var content = root.Q("content");
                var table   = AddTable(content);

                // Build target - Windows
                MakeRow(table, "Active target - Windows",
                        () => (EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneWindows) || (EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneWindows64),
                        () => { EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Standalone, BuildTarget.StandaloneWindows64); });

                // Scripting backend - IL2CPP
                MakeRow(table, "Scripting Backend",
                        () => PlayerSettings.GetScriptingBackend(BuildTargetGroup.Standalone) == ScriptingImplementation.IL2CPP,
                        () => { PlayerSettings.SetScriptingBackend(BuildTargetGroup.Standalone, ScriptingImplementation.IL2CPP); });

                // Copy PDB files
                MakeRow(table, "Copy PDB files",
                        () => EditorUserBuildSettings.GetPlatformSettings("Standalone", kSettingCopyPDBFiles).ToLower() == "true",
                        () => { EditorUserBuildSettings.SetPlatformSettings("Standalone", kSettingCopyPDBFiles, "true"); });
            }
        public void OnGUI(Rect pos)
        {
            m_ScrollPosition = EditorGUILayout.BeginScrollView(m_ScrollPosition);

            EditorGUILayout.Space();
            GUILayout.BeginVertical();
            // 选择平台
            var target = (BuildTarget)EditorGUILayout.EnumPopup(m_BuildTargetContent, m_BuildTarget);

            if (target != m_BuildTarget)
            {
                m_BuildTarget = target;
                EditorPrefs.SetInt(k_BuildPrefPrefix + "BuildTarget", (int)m_BuildTarget);
                if (m_UserDefaultPath)
                {
                    m_OutputPath  = "AssetBundles/";
                    m_OutputPath += m_BuildTarget.ToString();
                    EditorUserBuildSettings.SetPlatformSettings(EditorUserBuildSettings.activeBuildTarget.ToString(), "AssetBundleOutputPath", m_OutputPath);
                }
            }

            EditorGUILayout.Space();
            GUILayout.BeginVertical();
            // 路径
            var newPath = EditorGUILayout.TextField("Out Path", m_OutputPath);

            if (newPath != m_OutputPath)
            {
                m_UserDefaultPath = false;
                m_OutputPath      = newPath;
                EditorUserBuildSettings.SetPlatformSettings(EditorUserBuildSettings.activeBuildTarget.ToString(), "AssetBundleOutputPath", m_OutputPath);
            }


            GUILayout.EndVertical();
            EditorGUILayout.EndScrollView();
        }
        /// <summary>
        /// Generates a Player solution using the default configuration.
        /// </summary>
        public static void GenerateHoloLensPlayerSolution()
        {
            EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.WSA, BuildTarget.WSAPlayer);
            EditorUserBuildSettings.SetPlatformSettings("WindowsStoreApps", "CopyReferences", "true");
            EditorUserBuildSettings.SetPlatformSettings("WindowsStoreApps", "CopyPDBFiles", "true");

            EditorUserBuildSettings.wsaUWPVisualStudioVersion = "Visual Studio 2017";
            EditorUserBuildSettings.wsaUWPSDK    = "10.0.18362.0";
            EditorUserBuildSettings.wsaSubtarget = WSASubtarget.HoloLens;

            PlayerSettings.SetScriptingBackend(BuildTargetGroup.WSA, ScriptingImplementation.IL2CPP);

            BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions()
            {
                locationPathName = "UWP",
                target           = BuildTarget.WSAPlayer,
                targetGroup      = BuildTargetGroup.WSA,
                options          = BuildOptions.None,
                scenes           = EditorBuildSettings.scenes
                                   .Where(scene => scene.enabled)
                                   .Select(scene => scene.path)
                                   .ToArray(),
            };

            // checks for exceptions and returns proper error code
            BuildReport  report  = BuildPipeline.BuildPlayer(buildPlayerOptions);
            BuildSummary summary = report.summary;

            if (summary.result == BuildResult.Succeeded)
            {
                EditorApplication.Exit(0);
            }
            else
            {
                EditorApplication.Exit(1);
            }
        }
        public void OnGUI(Rect pos)
        {
            m_scrollPosition = EditorGUILayout.BeginScrollView(m_scrollPosition);
            bool newState = false;

            //basic options
            EditorGUILayout.Space();
            GUILayout.BeginVertical();

            m_buildTarget = ABBuilder.Instance.CurBuildPlatform;
            EditorGUILayout.TextField(m_TargetContent, m_buildTarget.ToString());

            EditorPrefs.SetInt(kBuildPrefPrefix + "BuildTarget", (int)m_buildTarget);

            m_outputPath = ABBuilder.Instance.GetPathPrefix_Assetbundle();
            EditorUserBuildSettings.SetPlatformSettings(ABBuilder.GetCurrentBuildPlatformName(), "AssetBundleOutputPath", m_outputPath);

            //output path
            EditorGUILayout.Space();
            GUILayout.BeginHorizontal();
            var newPath = EditorGUILayout.TextField("Output Path", m_outputPath);

            if (newPath != m_outputPath)
            {
                m_useDefaultPath = false;
                m_outputPath     = newPath;
                EditorUserBuildSettings.SetPlatformSettings(ABBuilder.GetCurrentBuildPlatformName(), "AssetBundleOutputPath", m_outputPath);
            }

            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            if (string.IsNullOrEmpty(m_outputPath))
            {
                m_outputPath = EditorUserBuildSettings.GetPlatformSettings(ABBuilder.GetCurrentBuildPlatformName(), "AssetBundleOutputPath");
            }
            GUILayout.EndHorizontal();
            EditorGUILayout.Space();

            newState = GUILayout.Toggle(
                m_ForceRebuild.state,
                m_ForceRebuild.content);
            if (newState != m_ForceRebuild.state)
            {
                EditorPrefs.SetBool(m_ForceRebuild.PrefKey, newState);
                m_ForceRebuild.state = newState;
            }
            newState = GUILayout.Toggle(
                m_CopyToStreaming.state,
                m_CopyToStreaming.content);
            if (newState != m_CopyToStreaming.state)
            {
                EditorPrefs.SetBool(m_CopyToStreaming.PrefKey, newState);
                m_CopyToStreaming.state = newState;
            }

            // advanced options
            EditorGUILayout.Space();
            m_advancedSettings = EditorGUILayout.Foldout(m_advancedSettings, "Advanced Settings");
            if (m_advancedSettings)
            {
                var indent = EditorGUI.indentLevel;
                EditorGUI.indentLevel = 1;
                CompressOptions cmp = (CompressOptions)EditorGUILayout.IntPopup(
                    m_CompressionContent,
                    (int)m_compression,
                    m_CompressionOptions,
                    m_CompressionValues);

                if (cmp != m_compression)
                {
                    m_compression = cmp;
                    EditorPrefs.SetInt(kBuildPrefPrefix + "Compression", (int)m_compression);
                }
                foreach (var tog in m_toggleData)
                {
                    newState = EditorGUILayout.ToggleLeft(
                        tog.content,
                        tog.state);
                    if (newState != tog.state)
                    {
                        EditorPrefs.SetBool(tog.PrefKey, newState);
                        tog.state = newState;
                    }
                }
                EditorGUILayout.Space();
                EditorGUI.indentLevel = indent;
            }

            // build.
            EditorGUILayout.Space();
            if (GUILayout.Button("Build"))
            {
                ExecuteBuild();
            }
            GUILayout.EndVertical();
            EditorGUILayout.EndScrollView();
        }
Esempio n. 8
0
        public void OnGUI(Rect pos)
        {
            m_ScrollPosition = EditorGUILayout.BeginScrollView(m_ScrollPosition);
            bool newState = false;

            //basic options
            EditorGUILayout.Space();
            GUILayout.BeginVertical();

            // build target
            using (new EditorGUI.DisabledScope(!AssetBundleModel.Model.DataSource.CanSpecifyBuildTarget)) {
                ValidBuildTarget tgt = (ValidBuildTarget)EditorGUILayout.EnumPopup(m_TargetContent, m_BuildTarget);
                if (tgt != m_BuildTarget)
                {
                    m_BuildTarget = tgt;
                    if (m_UseDefaultPath)
                    {
                        m_OutputPath  = "AssetBundles/";
                        m_OutputPath += m_BuildTarget.ToString();
                        EditorUserBuildSettings.SetPlatformSettings(EditorUserBuildSettings.activeBuildTarget.ToString(), "AssetBundleOutputPath", m_OutputPath);
                    }
                }
            }


            ////output path
            using (new EditorGUI.DisabledScope(!AssetBundleModel.Model.DataSource.CanSpecifyBuildOutputDirectory)) {
                EditorGUILayout.Space();
                GUILayout.BeginHorizontal();
                var newPath = EditorGUILayout.TextField("Output Path", m_OutputPath);
                if (newPath != m_OutputPath)
                {
                    m_UseDefaultPath = false;
                    m_OutputPath     = newPath;
                    EditorUserBuildSettings.SetPlatformSettings(EditorUserBuildSettings.activeBuildTarget.ToString(), "AssetBundleOutputPath", m_OutputPath);
                }
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Browse", GUILayout.MaxWidth(75f)))
                {
                    BrowseForFolder();
                }
                if (GUILayout.Button("Reset", GUILayout.MaxWidth(75f)))
                {
                    ResetPathToDefault();
                }
                if (string.IsNullOrEmpty(m_OutputPath))
                {
                    m_OutputPath = EditorUserBuildSettings.GetPlatformSettings(EditorUserBuildSettings.activeBuildTarget.ToString(), "AssetBundleOutputPath");
                }
                GUILayout.EndHorizontal();
                EditorGUILayout.Space();

                newState = GUILayout.Toggle(
                    m_ForceRebuild.state,
                    m_ForceRebuild.content);
                if (newState != m_ForceRebuild.state)
                {
                    if (newState)
                    {
                        m_OnToggles.Add(m_ForceRebuild.content.text);
                    }
                    else
                    {
                        m_OnToggles.Remove(m_ForceRebuild.content.text);
                    }
                    m_ForceRebuild.state = newState;
                }
                newState = GUILayout.Toggle(
                    m_CopyToStreaming.state,
                    m_CopyToStreaming.content);
                if (newState != m_CopyToStreaming.state)
                {
                    if (newState)
                    {
                        m_OnToggles.Add(m_CopyToStreaming.content.text);
                    }
                    else
                    {
                        m_OnToggles.Remove(m_CopyToStreaming.content.text);
                    }
                    m_CopyToStreaming.state = newState;
                }
            }

            // advanced options
            using (new EditorGUI.DisabledScope(!AssetBundleModel.Model.DataSource.CanSpecifyBuildOptions)) {
                EditorGUILayout.Space();
                m_AdvancedSettings = EditorGUILayout.Foldout(m_AdvancedSettings, "Advanced Settings");
                if (m_AdvancedSettings)
                {
                    var indent = EditorGUI.indentLevel;
                    EditorGUI.indentLevel = 1;
                    CompressOptions cmp = (CompressOptions)EditorGUILayout.IntPopup(
                        m_CompressionContent,
                        (int)m_Compression,
                        m_CompressionOptions,
                        m_CompressionValues);

                    if (cmp != m_Compression)
                    {
                        m_Compression = cmp;
                    }
                    foreach (var tog in m_ToggleData)
                    {
                        newState = EditorGUILayout.ToggleLeft(
                            tog.content,
                            tog.state);
                        if (newState != tog.state)
                        {
                            if (newState)
                            {
                                m_OnToggles.Add(tog.content.text);
                            }
                            else
                            {
                                m_OnToggles.Remove(tog.content.text);
                            }
                            tog.state = newState;
                        }
                    }
                    EditorGUILayout.Space();
                    EditorGUI.indentLevel = indent;
                }
            }

            // build.
            EditorGUILayout.Space();
            if (GUILayout.Button("Build"))
            {
                EditorApplication.delayCall += ExecuteBuild;
            }
            GUILayout.EndVertical();
            EditorGUILayout.EndScrollView();
        }
        public static void Build(string[] args)
        {
            BuildOptions buildOptions = BuildOptions.None;

            // Gather values from args
            Dictionary <string, string> options = GetValidatedOptions(args);

            // Set version for this build
            PlayerSettings.bundleVersion             = options["buildVersion"];
            PlayerSettings.macOS.buildNumber         = options["buildVersion"];
            PlayerSettings.Android.bundleVersionCode = int.Parse(options["androidVersionCode"]);

            // Apply build target
            var buildTarget = (BuildTarget)Enum.Parse(typeof(BuildTarget), options["buildTarget"]);

            switch (buildTarget)
            {
            case BuildTarget.Android:
            {
                EditorUserBuildSettings.buildAppBundle = options["customBuildPath"].EndsWith(".aab");
                if (options.TryGetValue("androidKeystoreName", out string keystoreName) &&
                    !string.IsNullOrEmpty(keystoreName))
                {
                    PlayerSettings.Android.keystoreName = keystoreName;
                }
                if (options.TryGetValue("androidKeystorePass", out string keystorePass) &&
                    !string.IsNullOrEmpty(keystorePass))
                {
                    PlayerSettings.Android.keystorePass = keystorePass;
                }
                if (options.TryGetValue("androidKeyaliasName", out string keyaliasName) &&
                    !string.IsNullOrEmpty(keyaliasName))
                {
                    PlayerSettings.Android.keyaliasName = keyaliasName;
                }
                if (options.TryGetValue("androidKeyaliasPass", out string keyaliasPass) &&
                    !string.IsNullOrEmpty(keyaliasPass))
                {
                    PlayerSettings.Android.keyaliasPass = keyaliasPass;
                }
                break;
            }

            case BuildTarget.StandaloneOSX:
                PlayerSettings.SetScriptingBackend(BuildTargetGroup.Standalone, ScriptingImplementation.Mono2x);
                break;

            case BuildTarget.WebGL:
                if (options.TryGetValue("tag", out string tagVersion) &&
                    !string.IsNullOrEmpty(tagVersion))
                {
                    string[] tagParameters = tagVersion.Split('-');
                    if (tagParameters.Contains("minsize"))
                    {
                        EditorUserBuildSettings.SetPlatformSettings(BuildPipeline.GetBuildTargetName(BuildTarget.WebGL), "CodeOptimization", "size");
                        PlayerSettings.WebGL.exceptionSupport = WebGLExceptionSupport.None;
                        PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.WebGL, Il2CppCompilerConfiguration.Master);
                    }
                    else if (tagParameters.Contains("debug"))
                    {
                        EditorUserBuildSettings.SetPlatformSettings(BuildPipeline.GetBuildTargetName(BuildTarget.WebGL), "CodeOptimization", "size");
                        PlayerSettings.WebGL.exceptionSupport = WebGLExceptionSupport.FullWithStacktrace;
                        PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.WebGL, Il2CppCompilerConfiguration.Debug);
                        PlayerSettings.WebGL.debugSymbolMode = WebGLDebugSymbolMode.Embedded;
                        buildOptions |= BuildOptions.Development;
                    }
                    else
                    {
                        EditorUserBuildSettings.SetPlatformSettings(BuildPipeline.GetBuildTargetName(BuildTarget.WebGL), "CodeOptimization", "speed");
                    }
                    if (tagParameters.Contains("webgl2"))
                    {
                        PlayerSettings.SetGraphicsAPIs(BuildTarget.WebGL, new[] { GraphicsDeviceType.OpenGLES3 });
                    }
                    if (tagParameters.Contains("webgl1"))
                    {
                        PlayerSettings.SetGraphicsAPIs(BuildTarget.WebGL, new[] { GraphicsDeviceType.OpenGLES2 });
                    }
                }
                break;
            }

            // Custom build
            Build(buildTarget, buildOptions, options["customBuildPath"]);
        }
Esempio n. 10
0
    static void BuildRelease(BuildTarget target, bool isDebug = false)
    {
        MaterialCollector.BuildMaterialCollection();

        string targetString = "";
        string releaseName  = "";

        BuildSettings.Instance.build_date = System.DateTime.Now.ToString("yyy-MM-dd");
        EditorUtility.SetDirty(BuildSettings.Instance);
        AssetDatabase.SaveAssets();

        switch (target)
        {
        case BuildTarget.StandaloneOSX:
            releaseName  = BuildSettings.Instance.osx_exe;
            targetString = "Mac";
            break;

        case BuildTarget.StandaloneLinux64:
            releaseName  = BuildSettings.Instance.linux_exe;
            targetString = "Linux";
            break;

        case BuildTarget.StandaloneWindows:
            releaseName  = BuildSettings.Instance.win_exe;
            targetString = "Win";
            break;

        case BuildTarget.StandaloneWindows64:
            releaseName  = BuildSettings.Instance.win_exe;
            targetString = "Win x64";
            break;

        default:
            break;
        }

        string path = "Build/" + (isDebug ? BuildSettings.Instance.build_date : BuildSettings.Instance.content_version) + "/" + targetString + (isDebug ? "_debug" : "") + "/";

        if (Directory.Exists(path))
        {
            Directory.Delete(path, true);
        }

        string[] levels = new string[] { "Assets/Scenes/Map Mode.unity" };
        EditorUserBuildSettings.SetPlatformSettings("Standalone", "CopyPDBFiles", "false");
        var options = BuildOptions.None;

        if (isDebug)
        {
            options |= BuildOptions.AllowDebugging;
        }
        UnityEngine.Debug.Log(BuildPipeline.BuildPlayer(levels, path + releaseName, target, options));
        CopyExtras(path);

        using (ZipFile zip = new ZipFile())
        {
            zip.AddDirectory(path);
            zip.Save("Build/" + BuildSettings.Instance.title + " " + (isDebug ? BuildSettings.Instance.build_date : BuildSettings.Instance.content_version) + " " + targetString + (isDebug ? "_debug" : "") + ".zip");
        }
    }
Esempio n. 11
0
        public static void BuildGame(string buildDir, BuildTarget buildTarget, bool headLessBuild, bool devBuild = false, bool autoConnectProfiler = false,
                                     bool deepProfiling = false, bool scriptDebugging = false, bool copyPdbFiles = false, bool scriptsOnly = false)
        {
            Debug.Log($"Starting game build at {DateTime.Now:G}...");
            Stopwatch stopwatch = Stopwatch.StartNew();

            if (buildTarget == BuildTarget.StandaloneWindows || buildTarget == BuildTarget.StandaloneWindows64)
            {
                buildDir += ".exe";
            }

            Debug.Log($"Building to '{buildDir}'...");

            //Set target group
            #region Target Group

            BuildTargetGroup targetGroup;
            switch (buildTarget)
            {
            case BuildTarget.StandaloneLinux64:
            case BuildTarget.StandaloneWindows64:
            case BuildTarget.StandaloneOSX:
            case BuildTarget.StandaloneWindows:
                targetGroup = BuildTargetGroup.Standalone;
                break;

            case BuildTarget.iOS:
                targetGroup = BuildTargetGroup.iOS;
                break;

            case BuildTarget.Android:
                targetGroup = BuildTargetGroup.Android;
                break;

            case BuildTarget.WebGL:
                targetGroup = BuildTargetGroup.WebGL;
                break;

            case BuildTarget.WSAPlayer:
                targetGroup = BuildTargetGroup.WSA;
                break;

            case BuildTarget.PS4:
                targetGroup = BuildTargetGroup.PS4;
                break;

            case BuildTarget.XboxOne:
                targetGroup = BuildTargetGroup.XboxOne;
                break;

            case BuildTarget.tvOS:
                targetGroup = BuildTargetGroup.tvOS;
                break;

            case BuildTarget.Switch:
                targetGroup = BuildTargetGroup.Switch;
                break;

            case BuildTarget.Lumin:
                targetGroup = BuildTargetGroup.Lumin;
                break;

            case BuildTarget.Stadia:
                targetGroup = BuildTargetGroup.Stadia;
                break;

            case BuildTarget.CloudRendering:
                targetGroup = BuildTargetGroup.CloudRendering;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            #endregion

            //Setup build options
            BuildOptions options = BuildOptions.None;

            //Server/Headless mode
            if (headLessBuild)
            {
                options |= BuildOptions.EnableHeadlessMode;
            }

            //Copy PDB files
            string existingCopyPdbFilesOptions =
                EditorUserBuildSettings.GetPlatformSettings("Standalone", CopyPdbFilesEditorString);

            if (copyPdbFiles)
            {
                EditorUserBuildSettings.SetPlatformSettings("Standalone", CopyPdbFilesEditorString,
                                                            SettingsManager.CopyPdbFiles ? "true" : "false");
            }

            //Dev build
            if (devBuild)
            {
                options |= BuildOptions.Development;

                if (autoConnectProfiler)
                {
                    options |= BuildOptions.ConnectWithProfiler;
                }

                if (deepProfiling)
                {
                    options |= BuildOptions.EnableDeepProfilingSupport;
                }

                if (scriptDebugging)
                {
                    options |= BuildOptions.AllowDebugging;
                }
            }

            //Scripts only
            if (scriptsOnly)
            {
                options |= BuildOptions.BuildScriptsOnly;
            }

            //Run build action pre-build
            Debug.Log("Running build actions pre build...");
            try
            {
                BuildActions.RunPreActions(Path.GetDirectoryName(buildDir), buildTarget, ref options);
            }
            catch (Exception ex)
            {
                Debug.LogError($"An error occurred while running a build action's pre build! {ex}");
            }

            Debug.Log("Build actions pre build done!");

            Debug.Log("Building player...");

            //Build the player
            BuildReport report = BuildPipeline.BuildPlayer(new BuildPlayerOptions
            {
                locationPathName = buildDir,
                target           = buildTarget,
                options          = options,
                targetGroup      = targetGroup,
                scenes           = EditorBuildSettings.scenes.Select(scene => scene.path).ToArray()
            });

            //Set CopyPDBFiles to it's original setting
            EditorUserBuildSettings.SetPlatformSettings("Standalone", CopyPdbFilesEditorString,
                                                        existingCopyPdbFilesOptions);

            //If the build failed
            if (report.summary.result != BuildResult.Succeeded)
            {
                stopwatch.Stop();
                Debug.LogError($"Build failed for some reason! Completed in {stopwatch.ElapsedMilliseconds / 1000}s.");
                return;
            }

            //Run Build Action post build
            try
            {
                BuildActions.RunPostActions(Path.GetDirectoryName(buildDir), report);
            }
            catch (Exception ex)
            {
                Debug.LogError($"An error occurred while running a build action's post build! {ex}");
            }

            //End
            stopwatch.Stop();
            Debug.Log($"Build done in {stopwatch.ElapsedMilliseconds / 1000}s!");
        }
Esempio n. 12
0
        public void OnGUI(Rect pos)
        {
            m_ScrollPosition = EditorGUILayout.BeginScrollView(m_ScrollPosition);
            bool newState = false;

            //basic options
            EditorGUILayout.Space();
            GUILayout.BeginVertical();
            ValidBuildTarget tgt = (ValidBuildTarget)EditorGUILayout.EnumPopup(m_TargetContent, m_BuildTarget);

            if (tgt != m_BuildTarget)
            {
                m_BuildTarget = tgt;
                EditorPrefs.SetInt(k_BuildPrefPrefix + "BuildTarget", (int)m_BuildTarget);
                if (m_UseDefaultPath)
                {
                    m_OutputPath  = "AssetBundles/";
                    m_OutputPath += m_BuildTarget.ToString();
                    EditorUserBuildSettings.SetPlatformSettings(EditorUserBuildSettings.activeBuildTarget.ToString(), "AssetBundleOutputPath", m_OutputPath);
                }
            }


            ////output path
            EditorGUILayout.Space();
            GUILayout.BeginHorizontal();
            var newPath = EditorGUILayout.TextField("Output Path", m_OutputPath);

            if (newPath != m_OutputPath)
            {
                m_UseDefaultPath = false;
                m_OutputPath     = newPath;
                EditorUserBuildSettings.SetPlatformSettings(EditorUserBuildSettings.activeBuildTarget.ToString(), "AssetBundleOutputPath", m_OutputPath);
            }
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Browse", GUILayout.MaxWidth(75f)))
            {
                BrowseForFolder();
            }
            if (GUILayout.Button("Reset", GUILayout.MaxWidth(75f)))
            {
                ResetPathToDefault();
            }
            if (string.IsNullOrEmpty(m_OutputPath))
            {
                m_OutputPath = EditorUserBuildSettings.GetPlatformSettings(EditorUserBuildSettings.activeBuildTarget.ToString(), "AssetBundleOutputPath");
            }
            GUILayout.EndHorizontal();
            EditorGUILayout.Space();

            newState = GUILayout.Toggle(
                m_ForceRebuild.state,
                m_ForceRebuild.content);
            if (newState != m_ForceRebuild.state)
            {
                EditorPrefs.SetBool(m_ForceRebuild.prefsKey, newState);
                m_ForceRebuild.state = newState;
            }
            newState = GUILayout.Toggle(
                m_CopyToStreaming.state,
                m_CopyToStreaming.content);
            if (newState != m_CopyToStreaming.state)
            {
                EditorPrefs.SetBool(m_CopyToStreaming.prefsKey, newState);
                m_CopyToStreaming.state = newState;
            }


            // advanced options
            EditorGUILayout.Space();
            m_AdvancedSettings = EditorGUILayout.Foldout(m_AdvancedSettings, "Advanced Settings");
            if (m_AdvancedSettings)
            {
                var indent = EditorGUI.indentLevel;
                EditorGUI.indentLevel = 1;
                CompressOptions cmp = (CompressOptions)EditorGUILayout.IntPopup(
                    m_CompressionContent,
                    (int)m_Compression,
                    m_CompressionOptions,
                    m_CompressionValues);

                if (cmp != m_Compression)
                {
                    m_Compression = cmp;
                    EditorPrefs.SetInt(k_BuildPrefPrefix + "Compression", (int)m_Compression);
                }
                foreach (var tog in m_ToggleData)
                {
                    newState = EditorGUILayout.ToggleLeft(
                        tog.content,
                        tog.state);
                    if (newState != tog.state)
                    {
                        EditorPrefs.SetBool(tog.prefsKey, newState);
                        tog.state = newState;
                    }
                }
                EditorGUILayout.Space();
                EditorGUI.indentLevel = indent;
            }

            // build.
            EditorGUILayout.Space();
            if (GUILayout.Button("Build"))
            {
                ExecuteBuild();
            }
            GUILayout.EndVertical();
            EditorGUILayout.EndScrollView();
        }
Esempio n. 13
0
 public static void SetArchitectureForPlatform(BuildTarget buildTarget, OSArchitecture architecture)
 {
     EditorUserBuildSettings.SetPlatformSettings(BuildPipeline.GetBuildTargetName(buildTarget), EditorUserBuildSettings.kSettingArchitecture, architecture.ToString().ToLower());
 }