一、若是想讓unity在打包的過程當中,執行一些邏輯,那麼該如何作呢?代碼以下:app
using UnityEditor; using UnityEditor.Build; using UnityEngine; public class NewBehaviourScript : IPreprocessBuild { public int callbackOrder { get { return 0; } } public void OnPreprocessBuild(BuildTarget target, string path) { Debug.Log("OnPreprocessBuild"); } }
執行結果:ui
該腳本須要放在Editor目錄下,以下:spa
在此,須要注意一下,若是須要放在Editor目錄下執行的腳本,沒有放在Editor目錄下,會出現如下問題:code
二、在這裏對以上的筆記作個實例:blog
在打apk的時候,用一個已存在的 keystore 對 PlayerSetting 裏面板的一些參數進行設置,包括對包名的設置,均可以再以上的邏輯中執行:ip
假如 keystore 文件放在以下的目錄下:get
具體代碼以下:string
using UnityEditor; using UnityEditor.Build; using UnityEngine; public class NewBehaviourScript : IPreprocessBuild { public int callbackOrder { get { return 0; } } public void OnPreprocessBuild(BuildTarget target, string path) { string keystorePath = Application.dataPath + "/Plugins/Android/lgs.keystore"; PlayerSettings.Android.keystoreName = keystorePath; PlayerSettings.Android.keystorePass = "123456"; PlayerSettings.Android.keyaliasName = "luguoshuai"; PlayerSettings.Android.keyaliasPass = "123456"; PlayerSettings.applicationIdentifier = "com.niuchicao.luguoshuai"; } }
執行結果:it