Skip to content

Instantly share code, notes, and snippets.

@YutaKaseda
Created December 7, 2015 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YutaKaseda/e16b45825009cff98e7e to your computer and use it in GitHub Desktop.
Save YutaKaseda/e16b45825009cff98e7e to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public class BatchBuild : MonoBehaviour {
//for Android
static void BuildProject_Android(){
Debug.Log ("AndroidBuild...");
string[] scenePaths = GetEnabledScenePaths();
string outputPath = Application.dataPath + "/../アプリケーション名.apk";
BuildTarget target = BuildTarget.Android;
BuildOptions opt = BuildOptions.None;
ApplicationBuild(scenePaths,outputPath,target,opt);
}
//for iOS Device
static void BuildProject_iOS(){
Debug.Log ("iOSBuild...");
string[] scenePaths = GetEnabledScenePaths();
string outputPath = "Device";
BuildTarget target = BuildTarget.iOS;
BuildOptions opt = BuildOptions.SymlinkLibraries;
//ProjectDataSize Reduction
EditorUserBuildSettings.symlinkLibraries = true;
//Prevent SimulatorBuild
PlayerSettings.iOS.sdkVersion = iOSSdkVersion.DeviceSDK;
ApplicationBuild(scenePaths,outputPath,target,opt);
}
//RunBuild
static void ApplicationBuild(string[] scenePaths,string outputPath,BuildTarget target,BuildOptions opt){
string error = BuildPipeline.BuildPlayer(scenePaths,outputPath,target,opt);
if (!string.IsNullOrEmpty(error))
Debug.LogError(error); //BuildFailed
EditorApplication.Exit(string.IsNullOrEmpty(error) ? 0 : 1);
}
//return Enabled Scene in BuildSettings's Scenes In Build
static string[] GetEnabledScenePaths() {
List<string> sceneList = new List<string>();
//Check Scenes Enabled
foreach(var scene in EditorBuildSettings.scenes){
if(scene.enabled)
sceneList.Add (scene.path);
}
return sceneList.ToArray();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment