using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; using UnityEditor.Build.Reporting; public class MenuToolEditor : MonoBehaviour { [MenuItem("Tool/Build XXX")] public static void BuildBigDipper() { Debug.Log("Build XXX"); //设置产品名称 PlayerSettings.productName = "XXX"; //设置包名 PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, Config.BIG_DIPPER_IDENTIFIER); //设置AppIcon string[] appIconNames = { "192", "144", "96", "72", "48", "36" }; Texture2D[] icons = new Texture2D[appIconNames.Length]; for (int i=0; i<icons.Length; i++) { string path = string.Format("UI/Sprite/海岛/AppIcon/{0}", appIconNames[i]); icons[i] = Resources.Load<Texture2D>(path); } PlayerSettings.SetIconsForTargetGroup(BuildTargetGroup.Android, icons); //设置闪屏Logo var logo = Resources.Load<Sprite>("UI/Sprite/Logo/logo_new"); var screenLogo = PlayerSettings.SplashScreenLogo.Create(2, logo); PlayerSettings.SplashScreen.logos = new PlayerSettings.SplashScreenLogo[] { screenLogo }; //打包APK BuildAndroid(); } [MenuItem("Tool/Build YYY")] public static void BuildMicrowave() { Debug.Log("Build YYY"); //设置产品名称 PlayerSettings.productName = "YYY"; //设置包名 PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, Config.MICROWAVE_IDENTIFIER); //设置AppIcon string[] appIconNames = { "192", "144", "96", "72", "48", "36" }; Texture2D[] icons = new Texture2D[appIconNames.Length]; for (int i = 0; i < icons.Length; i++) { string path = string.Format("UI/Sprite/城市/AppIcon/{0}", appIconNames[i]); icons[i] = Resources.Load<Texture2D>(path); } PlayerSettings.SetIconsForTargetGroup(BuildTargetGroup.Android, icons); //设置闪屏Logo var logo = Resources.Load<Sprite>("UI/Sprite/Logo/logo_new"); var screenLogo = PlayerSettings.SplashScreenLogo.Create(2, logo); PlayerSettings.SplashScreen.logos = new PlayerSettings.SplashScreenLogo[] { screenLogo }; //打包APK BuildAndroid(); } //生成APK public static void BuildAndroid() { PlayerSettings.Android.keystorePass = "123456"; PlayerSettings.Android.keyaliasPass = "123456"; List<string> levels = new List<string>(); foreach (EditorBuildSettingsScene scene in EditorBuildSettings.scenes) { if (!scene.enabled) continue; levels.Add(scene.path); } EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Android, BuildTarget.Android); BuildReport report = BuildPipeline.BuildPlayer(levels.ToArray(), "APK/MilitaryTopics.apk", BuildTarget.Android, BuildOptions.None); if (report.summary.result == BuildResult.Succeeded) Debug.Log("Build Succeeded"); else Debug.LogErrorFormat("Build {0}", report.summary.result); } }