Created
April 1, 2016 15:07
-
-
Save craigmjohnston/ef7eb09b760da1e598c7cc30a5bd7956 to your computer and use it in GitHub Desktop.
A Unity3d editor script used to perform generic builds from the command line.
This file contains 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 System; | |
using System.Collections.Generic; | |
using UnityEditor; | |
public class Build { | |
static string[] SCENES = FindEnabledEditorScenes(); | |
static void PerformBuild() { | |
GenericBuild( | |
SCENES, | |
GetArg("-targetPath"), | |
(BuildTarget) Enum.Parse(typeof (BuildTarget), GetArg("-buildTarget")), | |
(BuildOptions) Enum.Parse(typeof (BuildOptions), GetArg("-buildOptions") ?? "None")); | |
} | |
private static string[] FindEnabledEditorScenes() { | |
List<string> EditorScenes = new List<string>(); | |
foreach(EditorBuildSettingsScene scene in EditorBuildSettings.scenes) { | |
if (!scene.enabled) continue; | |
EditorScenes.Add(scene.path); | |
} | |
return EditorScenes.ToArray(); | |
} | |
static void GenericBuild(string[] scenes, string target_dir, BuildTarget build_target, BuildOptions build_options) { | |
EditorUserBuildSettings.SwitchActiveBuildTarget(build_target); | |
string res = BuildPipeline.BuildPlayer(scenes,target_dir,build_target,build_options); | |
if (res.Length > 0) { | |
throw new Exception("BuildPlayer failure: " + res); | |
} | |
} | |
// Helper function for getting the command line arguments | |
// Taken from: https://effectiveunity.com/articles/making-most-of-unitys-command-line.html | |
private static string GetArg(string name) | |
{ | |
var args = System.Environment.GetCommandLineArgs(); | |
for (int i = 0; i < args.Length; i++) | |
{ | |
if (args[i] == name && args.Length > i + 1) | |
{ | |
return args[i + 1]; | |
} | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment