예제 #1
0
        public virtual bool Build(PostBuildOption option)
        {
            string path;

            try
            {
                //get output directory
                var dir = EditorProjectPrefs.Local.GetString("LastBuildDirectory", string.Empty);
                if (string.IsNullOrEmpty(this.BuildFileName))
                {
                    string extension = GetExtension(this.BuildTarget);
                    path = EditorUtility.SaveFilePanel("Build", dir, string.IsNullOrEmpty(extension) ? Application.productName + "." + extension : Application.productName, extension);
                    if (!string.IsNullOrEmpty(path))
                    {
                        return(false);
                    }
                }
                else
                {
                    string possiblePath = this.BuildDirectory;
                    if (!string.IsNullOrEmpty(possiblePath) && possiblePath.StartsWith("."))
                    {
                        possiblePath = System.IO.Path.Combine(Application.dataPath, possiblePath);
                    }
                    if (!string.IsNullOrEmpty(possiblePath) && System.IO.Directory.Exists(possiblePath))
                    {
                        path = System.IO.Path.Combine(possiblePath, this.GetBuildFileNameWithExtension());
                        path = System.IO.Path.GetFullPath(path);
                    }
                    else
                    {
                        path = EditorUtility.OpenFolderPanel("Build", dir, string.Empty);
                        if (!string.IsNullOrEmpty(path))
                        {
                            path = System.IO.Path.Combine(path, this.GetBuildFileNameWithExtension());
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                Debug.LogException(ex);
                return(false);
            }

            return(this.Build(path, option));
        }
예제 #2
0
        public bool Build(PostBuildOption option)
        {
            try
            {
                var settings = this.target as BuildSettings;
                var scenes   = this.GetScenePaths();

                //set version
                settings.Version.Build++;
                EditorUtility.SetDirty(settings);
                PlayerSettings.bundleVersion = settings.Version.ToString();
                AssetDatabase.SaveAssets();

                //get output directory
                var    dir = EditorProjectPrefs.Local.GetString("LastBuildDirectory", string.Empty);
                string path;
                switch (settings.BuildTarget)
                {
                case BuildTarget.StandaloneWindows:
                case BuildTarget.StandaloneWindows64:
                    path = EditorUtility.SaveFilePanel("Build", dir, Application.productName + ".exe", "exe");
                    break;

                case BuildTarget.StandaloneLinux:
                case BuildTarget.StandaloneLinuxUniversal:
                    path = EditorUtility.SaveFilePanel("Build", dir, Application.productName + ".x86", "x86");
                    break;

                case BuildTarget.StandaloneLinux64:
                    path = EditorUtility.SaveFilePanel("Build", dir, Application.productName + ".x86_64", "x86_64");
                    break;

                case BuildTarget.StandaloneOSXIntel:
                case BuildTarget.StandaloneOSXIntel64:
                case BuildTarget.StandaloneOSXUniversal:
                    path = EditorUtility.SaveFilePanel("Build", dir, Application.productName + ".app", "app");
                    break;

                default:
                    path = EditorUtility.SaveFilePanel("Build", dir, Application.productName, "");
                    break;
                }

                //build
                if (!string.IsNullOrEmpty(path))
                {
                    EditorProjectPrefs.Local.SetString("LastBuildDirectory", System.IO.Path.GetDirectoryName(path));

                    if (settings.InputSettings != null)
                    {
                        var copy = InputSettings.LoadGlobalInputSettings(false);
                        settings.InputSettings.ApplyToGlobal();

                        BuildPipeline.BuildPlayer(scenes, path, settings.BuildTarget, settings.BuildOptions);

                        copy.ApplyToGlobal();
                    }
                    else
                    {
                        BuildPipeline.BuildPlayer(scenes, path, settings.BuildTarget, settings.BuildOptions);
                    }

                    if ((option & PostBuildOption.OpenFolder) != 0)
                    {
                        EditorUtility.RevealInFinder(path);
                    }
                    if ((option & PostBuildOption.Run) != 0)
                    {
                        var proc = new System.Diagnostics.Process();
                        proc.StartInfo.FileName = path;
                        proc.Start();
                    }

                    return(true);
                }
            }
            catch (System.Exception ex)
            {
                Debug.LogException(ex);
            }

            return(false);
        }
예제 #3
0
        protected virtual System.Collections.IEnumerator DoBuild(PostBuildOption postBuildOption)
        {
            this.Build(postBuildOption);

            yield break;
        }
예제 #4
0
        public virtual bool Build(string path, PostBuildOption option)
        {
            try
            {
                var scenes     = this.GetScenePaths();
                var buildGroup = BuildPipeline.GetBuildTargetGroup(this.BuildTarget);

                //set version
                this.Version.Build++;
                EditorUtility.SetDirty(this);
                PlayerSettings.bundleVersion = this.Version.ToString();
                AssetDatabase.SaveAssets();

                //build
                if (!string.IsNullOrEmpty(path))
                {
                    //save last build directory
                    EditorProjectPrefs.Local.SetString("LastBuildDirectory", System.IO.Path.GetDirectoryName(path));


                    //do build
                    InputSettings cacheInputs  = null;
                    string        cacheSymbols = null;
                    Dictionary <BuildSettings.PlayerSettingOverride, object> cachePlayerSettings = null;

                    if (this.InputSettings != null)
                    {
                        cacheInputs = InputSettings.LoadGlobalInputSettings(false);
                        this.InputSettings.ApplyToGlobal();
                    }
                    if (this.DefineSymbols)
                    {
                        cacheSymbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(buildGroup) ?? string.Empty;
                        PlayerSettings.SetScriptingDefineSymbolsForGroup(buildGroup, this.Symbols);
                    }

                    if (_playerSettingOverrides.Count > 0)
                    {
                        cachePlayerSettings = new Dictionary <PlayerSettingOverride, object>();
                        foreach (var setting in _playerSettingOverrides)
                        {
                            if (setting.SettingInfo != null)
                            {
                                cachePlayerSettings[setting] = setting.SettingInfo.GetValue(null, null);
                                try
                                {
                                    setting.SettingInfo.SetValue(null, setting.SettingValue, null);
                                }
                                catch (System.Exception)
                                { }
                            }
                        }
                    }

                    var report = BuildPipeline.BuildPlayer(scenes, path, this.BuildTarget, this.BuildOptions);

                    if (cacheInputs != null)
                    {
                        cacheInputs.ApplyToGlobal();
                    }
                    if (cacheSymbols != null)
                    {
                        PlayerSettings.SetScriptingDefineSymbolsForGroup(buildGroup, cacheSymbols);
                    }
                    if (cachePlayerSettings != null)
                    {
                        //loop backwards when resetting from cache
                        for (int i = _playerSettingOverrides.Count - 1; i >= 0; i--)
                        {
                            var setting = _playerSettingOverrides[i];
                            if (setting.SettingInfo != null)
                            {
                                try
                                {
                                    setting.SettingInfo.SetValue(null, cachePlayerSettings[setting], null);
                                }
                                catch (System.Exception)
                                { }
                            }
                        }
                    }

                    if (report != null && report.summary.result == UnityEditor.Build.Reporting.BuildResult.Succeeded)
                    {
                        //save
                        if ((option & PostBuildOption.OpenFolder) != 0)
                        {
                            EditorUtility.RevealInFinder(path);
                        }
                        if ((option & PostBuildOption.Run) != 0)
                        {
                            var proc = new System.Diagnostics.Process();
                            proc.StartInfo.FileName = path;
                            proc.Start();
                        }

                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (System.Exception ex)
            {
                Debug.LogException(ex);
            }

            return(false);
        }