-
-
Save Nitudon/8b9756100ed07c17cafd09698e25161f 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
#if UNITY_EDITOR | |
using UnityEditor; | |
using UnityEngine; | |
using System.Linq; | |
using System; | |
using System.IO; | |
// 公式の提供しているビルドスクリプトのサンプルを少しいじったもの | |
class BitriseUnity | |
{ | |
// ビルドの実処理 | |
public static void Build() | |
{ | |
BitriseTools tools = new BitriseTools(); | |
tools.PrintInputs(); | |
BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions(); | |
buildPlayerOptions.scenes = tools.GetActiveScenes(); | |
buildPlayerOptions.locationPathName = tools.inputs.buildOutput; | |
// Android用の設定 | |
if (tools.inputs.buildPlatform == BitriseTools.BuildPlatform.android) | |
{ | |
// Android SDKのパス指定とkeystore周りの処理を行っている、必要に応じてNDK等の処理もここで行う | |
EditorPrefs.SetString("AndroidSdkRoot", tools.inputs.androidSdkPath); | |
EditorPrefs.SetString("JdkPath", tools.inputs.androidJdkPath); | |
buildPlayerOptions.target = BuildTarget.Android; | |
PlayerSettings.Android.keystoreName = tools.inputs.androidKeystorePath; | |
PlayerSettings.Android.keystorePass = tools.inputs.androidKeystorePassword; | |
PlayerSettings.Android.keyaliasName = tools.inputs.androidKeystoreAlias; | |
PlayerSettings.Android.keyaliasPass = tools.inputs.androidKeystoreAliasPassword; | |
} | |
// iOS用の設定 | |
else if (tools.inputs.buildPlatform == BitriseTools.BuildPlatform.ios) | |
{ | |
// iOSに必要な設定をここで行う | |
buildPlayerOptions.target = BuildTarget.iOS; | |
} | |
// プラットフォームが不正 | |
else | |
{ | |
tools.log.Fail("Invalid buildPlatform: " + tools.inputs.buildPlatform.ToString()); | |
} | |
// ビルドオプション、Developmentビルドを行う場合などはこれに代入する | |
buildPlayerOptions.options = BuildOptions.None; | |
// ビルド実行 | |
BuildPipeline.BuildPlayer(buildPlayerOptions); | |
} | |
} | |
public class BitriseTools | |
{ | |
public Inputs inputs; | |
public Logging log; | |
public enum BuildPlatform | |
{ | |
unknown, | |
android, | |
ios, | |
} | |
public BitriseTools() | |
{ | |
inputs = new Inputs(); | |
log = new Logging(); | |
} | |
public string[] GetActiveScenes() | |
{ | |
return EditorBuildSettings.scenes.Where(s => s.enabled).Select(s => s.path).ToArray(); | |
} | |
//ビルド時に渡すパラメータ | |
public class Inputs | |
{ | |
// Android SDKのパス | |
public string androidSdkPath; | |
// 成果物を書き出すパス | |
public string buildOutput; | |
// キーストア関連 | |
public string androidKeystorePath; | |
public string androidKeystoreAlias; | |
public string androidKeystorePassword; | |
public string androidKeystoreAliasPassword; | |
// 対象のプラットフォーム | |
public BuildPlatform buildPlatform; | |
// 引数の読み取り | |
public Inputs() | |
{ | |
string[] cmdArgs = Environment.GetCommandLineArgs(); | |
for (int i = 0; i < cmdArgs.Length; i++) | |
{ | |
if (cmdArgs[i].Equals("-buildPlatform")) | |
buildPlatform = (BuildPlatform)Enum.Parse(typeof(BuildPlatform), cmdArgs[i + 1]); | |
if (cmdArgs[i].Equals("-androidSdkPath")) | |
androidSdkPath = cmdArgs[i + 1]; | |
if (cmdArgs[i].Equals("-buildOutput")) | |
buildOutput = cmdArgs[i + 1]; | |
if (cmdArgs[i].Equals("-androidKeystorePath")) | |
androidKeystorePath = cmdArgs[i + 1]; | |
if (cmdArgs[i].Equals("-androidKeystoreAlias")) | |
androidKeystoreAlias = cmdArgs[i + 1]; | |
if (cmdArgs[i].Equals("-androidKeystorePassword")) | |
androidKeystorePassword = cmdArgs[i + 1]; | |
if (cmdArgs[i].Equals("-androidKeystoreAliasPassword")) | |
androidKeystoreAliasPassword = cmdArgs[i + 1]; | |
} | |
} | |
} | |
// ログ | |
public class Logging | |
{ | |
bool initialized = false; | |
void _init() | |
{ | |
if (!initialized) | |
{ | |
StreamWriter sw = new StreamWriter(Console.OpenStandardOutput(), System.Text.Encoding.ASCII); | |
sw.AutoFlush = true; | |
Console.SetOut(sw); | |
initialized = true; | |
} | |
} | |
public void Fail(string message) { _init(); Console.WriteLine("\x1b[31m" + message + "\x1b[0m"); } | |
public void Done(string message) { _init(); Console.WriteLine("\x1b[32m" + message + "\x1b[0m"); } | |
public void Info(string message) { _init(); Console.WriteLine("\x1b[34m" + message + "\x1b[0m"); } | |
public void Warn(string message) { _init(); Console.WriteLine("\x1b[33m" + message + "\x1b[0m"); } | |
public void Print(string message) { _init(); Console.WriteLine(message); } | |
} | |
// 渡す引数のコンソール吐き出し | |
public void PrintInputs() | |
{ | |
log.Info("Bitrise Unity build script inputs:"); | |
log.Print(" -buildOutput: " + inputs.buildOutput); | |
log.Print(" -buildPlatform: " + inputs.buildPlatform.ToString()); | |
log.Print(" -androidSdkPath: " + inputs.androidSdkPath); | |
log.Print(" -androidKeystorePath: " + inputs.androidKeystorePath); | |
log.Print(" -androidKeystoreAlias: " + (string.IsNullOrEmpty(inputs.androidKeystoreAlias) ? "" : "***")); | |
log.Print(" -androidKeystorePassword: " + (string.IsNullOrEmpty(inputs.androidKeystorePassword) ? "" : "***")); | |
log.Print(" -androidKeystoreAliasPassword: " + (string.IsNullOrEmpty(inputs.androidKeystoreAliasPassword) ? "" : "***")); | |
log.Print(""); | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment