Last active
June 8, 2018 06:19
-
-
Save neon-izm/8d1c3f2ce322af2d27846cd234ced651 to your computer and use it in GitHub Desktop.
UnityCloudBuild上で無理やり圧縮オプションをLZ4に変更する事が出来るか!? ref: https://qiita.com/neon-izm/items/7ba9e52a5970345aee37
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
public class Preprocess : IPreprocessBuild { | |
// ビルド前処理 | |
public void OnPreprocessBuild (UnityEditor.BuildTarget buildTarget, string path) | |
{ | |
if (buildTarget == BuildTarget.Android) | |
{ | |
Debug.Log("[PREPROCESS] find Android Build"); | |
Console.WriteLine("[PREPROCESS] find Android Build"); | |
//https://github.com/Unity-Technologies/UnityCsReference/blob/master/Editor/Mono/BuildPlayerWindow.cs#L770 | |
MethodInfo setCompressionTypeMethodInfo = | |
typeof(EditorUserBuildSettings).GetMethod("SetCompressionType", | |
BindingFlags.NonPublic | BindingFlags.Static); | |
try | |
{ | |
/* Invokeで実行するとき、staticクラスだったら第一引数はnull | |
* 第二引数は普通にpublicなenum でplatform | |
* 第三引数が内部定義されたenumなので、該当のint数値を直接突っ込んでいます | |
*/ | |
/* 第三引数はこんな感じで定義されています | |
namespace UnityEditor | |
{ | |
internal enum Compression | |
{ | |
None = 0, | |
Lz4 = 2, | |
Lz4HC = 3, | |
} | |
} | |
*/ | |
var invoke = setCompressionTypeMethodInfo.Invoke(null, new object[] {BuildTargetGroup.Android, 2}); | |
} | |
catch (Exception e) | |
{ | |
Debug.Log(e); | |
Console.WriteLine(e); | |
throw; | |
} | |
MethodInfo getCompressionTypeMethodInfo = | |
typeof(EditorUserBuildSettings).GetMethod("GetCompressionType", | |
BindingFlags.NonPublic | BindingFlags.Static); | |
var obj = getCompressionTypeMethodInfo.Invoke(null, new object[] {BuildTargetGroup.Android}); | |
Debug.Log("[REPROCESS] current compression type:" + obj); | |
Console.WriteLine("[PREPROCESS] current compression type:" + obj); | |
} | |
} | |
// 実行順 | |
public int callbackOrder { get { return 0; } } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment