Unity安卓IOS一键打包
添加菜单构建按钮,使用下面API进行构建,注意设置和配置等
using System; using System.IO; using AssetBundles; using LiXiaoQian.Common.Editor.Tools; using UnityEditor; using UnityEngine; /// 打包工具 public class BuildTool { [MenuItem("Tools/构建/Android平台")] public static void BuildAndroid() { var buildTarget = BuildTarget.Android; string rootPath = "Build"; //string build = $"{DateTime.Now:yyMMddHHmmss}"; string outputPath = Path.Combine(rootPath, Utility.GetPlatformForAssetBundles(buildTarget)); string filename = outputPath + $"\\SunlightRock.apk"; if (File.Exists(filename)) { File.Delete(filename); } Directory.CreateDirectory(outputPath); EditorUserBuildSettings.androidBuildSystem = AndroidBuildSystem.Gradle; PlayerSettings.Android.keystoreName = "Lixiaoqian.keystore"; PlayerSettings.Android.keystorePass = "lxq123456"; PlayerSettings.Android.keyaliasName = "lixiaoqian"; PlayerSettings.Android.keyaliasPass = "lxq123456"; SetVersionMode.SetBuildVersion(); BuildPipeline.BuildPlayer(EditorBuildSettings.scenes, filename, buildTarget, BuildOptions.None); Debug.Log(buildTarget + "平台构建完成. 文件位于" + filename); } [MenuItem("Tools/构建/iOS平台")] public static void BuildiOS() { var buildTarget = BuildTarget.iOS; string rootPath = "Build"; //string build = $"{DateTime.Now:yyMMddHHmmss}"; string outputPath = Path.Combine(rootPath, Utility.GetPlatformForAssetBundles(buildTarget)); if (Directory.Exists(outputPath)) { Directory.Delete(outputPath, true); } Directory.CreateDirectory(outputPath); SetVersionMode.SetBuildVersion(); BuildPipeline.BuildPlayer(EditorBuildSettings.scenes, outputPath, buildTarget, BuildOptions.None); Debug.Log(buildTarget + "平台构建完成. 文件位于" + outputPath); } }