Created
November 29, 2016 18:14
-
-
Save karl-/58a7b0b8bfa8b84234b38633136324d7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| using UnityEditor; | |
| using System.Collections; | |
| using System.Collections.Generic; | |
| using System.IO; | |
| public class AutomaticBuild : EditorWindow | |
| { | |
| const string BUILD_PATH = "Builds"; | |
| [MenuItem("Tools/Build Game &d")] | |
| private static void OpenWindow() | |
| { | |
| EditorWindow.GetWindow<AutomaticBuild>(true, "Automated Build", true).Show(); | |
| } | |
| BuildOptions options = BuildOptions.None; | |
| void OnGUI() | |
| { | |
| bool developmentBuild = options == BuildOptions.Development; | |
| developmentBuild = EditorGUILayout.Toggle("Development", developmentBuild); | |
| options = developmentBuild ? BuildOptions.Development : BuildOptions.None; | |
| GUILayout.FlexibleSpace(); | |
| if(GUILayout.Button("Build")) | |
| { | |
| Rect r = this.position; | |
| r.x += 10f; | |
| this.position = r; | |
| EditorApplication.delayCall += () => { DoBuild(); }; | |
| } | |
| } | |
| void DoBuild() | |
| { | |
| int previousBuildNumber = EditorPrefs.GetInt("AutomatedBuildIncrement", 0); | |
| int currentBuildNumber = previousBuildNumber + 1; | |
| EditorPrefs.SetInt("AutomatedBuildIncrement", currentBuildNumber); | |
| CreateFolderIfItDoesntExist(BUILD_PATH); | |
| string[] scenes = GetScenesInProject(); | |
| Debug.Log( string.Join("\n", scenes) ); | |
| string result = BuildPipeline.BuildPlayer( | |
| scenes, | |
| string.Format("{0}/MyBuild-{1}", BUILD_PATH, currentBuildNumber), | |
| BuildTarget.StandaloneOSXIntel, | |
| options); | |
| if( string.IsNullOrEmpty(result) ) | |
| Debug.Log("Build success!"); | |
| else | |
| Debug.Log(result); | |
| } | |
| private static void CreateFolderIfItDoesntExist(string path) | |
| { | |
| if( !Directory.Exists(path) ) | |
| { | |
| Debug.Log("Created directory: " + Path.GetFullPath(path)); | |
| Directory.CreateDirectory(path); | |
| } | |
| } | |
| private static string[] GetScenesInProject() | |
| { | |
| return Directory.GetFiles( | |
| "Assets", | |
| "*.unity", | |
| SearchOption.AllDirectories); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment