public static void Build(bool encrypt = false) { //每次打包前一定要调用一次这个方法,这个方法会对配置过的代码做预处理,之后才能加载补丁代码 IFixEditor.InjectAssemblys(); //addressable打包和assetBundle打包,调用不同的接口 if (FrameConstr.UseAssetAddress == AssetAddress.Addressable) { AddressableAssetSettings.BuildPlayerContent(); } else { //打ab包 if (encrypt) { BundleEditor.EncryptionBuild(); } else { BundleEditor.NormalBuild(); } } //写入版本号 SaveVersion(PlayerSettings.bundleVersion, PlayerSettings.applicationIdentifier, encrypt); //生成可执行程序 string savePath = ""; if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android) { //PlayerSettings.Android.keystorePass = "******"; //PlayerSettings.Android.keyaliasPass = "******"; //PlayerSettings.Android.keyaliasName = "android.keystore"; //PlayerSettings.Android.keystoreName = Application.dataPath.Replace("/Assets", "") + "/improve.keystore"; savePath = m_AndroidPath + m_AppName + "_" + EditorUserBuildSettings.activeBuildTarget + string.Format("_{0:yyyy_MM_dd_HH_mm}", DateTime.Now) + ".apk"; } else if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.iOS) { savePath = m_IOSPath + m_AppName + "_" + EditorUserBuildSettings.activeBuildTarget + string.Format("_{0:yyyy_MM_dd_HH_mm}", DateTime.Now); } else if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneWindows || EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneWindows64) { savePath = m_WindowsPath + m_AppName + "_" + EditorUserBuildSettings.activeBuildTarget + string.Format("_{0:yyyy_MM_dd_HH_mm}/{1}.exe", DateTime.Now, m_AppName); } BuildPipeline.BuildPlayer(FindEnableEditorrScenes(), savePath, EditorUserBuildSettings.activeBuildTarget, BuildOptions.None); if (FrameConstr.UseAssetAddress != AssetAddress.Addressable) { //删除 DeleteDir(Application.streamingAssetsPath); } }
static void BuildHandle(PlatformType type, BuildOptions buildOptions, bool isBuildExe, bool clearFolder, bool isInject) { BuildTarget buildTarget = BuildTarget.StandaloneWindows; string programName = "ET"; string exeName = programName; string platform = ""; switch (type) { case PlatformType.PC: buildTarget = BuildTarget.StandaloneWindows64; exeName += ".exe"; IFixEditor.Patch(); platform = "pc"; break; case PlatformType.Android: KeystoreSetting(); buildTarget = BuildTarget.Android; exeName += ".apk"; IFixEditor.CompileToAndroid(); platform = "android"; break; case PlatformType.IOS: buildTarget = BuildTarget.iOS; IFixEditor.CompileToIOS(); platform = "ios"; break; case PlatformType.MacOS: buildTarget = BuildTarget.StandaloneOSX; IFixEditor.Patch(); platform = "pc"; break; } //打程序集 BuildAssemblieEditor.BuildCodeRelease(); if (isInject) { //Inject IFixEditor.InjectAssemblys(); } HandleProject(); //string fold = string.Format(BuildFolder, type); if (clearFolder && Directory.Exists(relativeDirPrefix)) { Directory.Delete(relativeDirPrefix, true); Directory.CreateDirectory(relativeDirPrefix); } else { Directory.CreateDirectory(relativeDirPrefix); } if (isBuildExe) { AssetDatabase.Refresh(); string[] levels = { "Assets/AssetsPackage/Scenes/InitScene/Init.unity", }; UnityEngine.Debug.Log("开始EXE打包"); BuildPipeline.BuildPlayer(levels, $"{relativeDirPrefix}/{exeName}", buildTarget, buildOptions); UnityEngine.Debug.Log("完成exe打包"); } string jstr = File.ReadAllText("Assets/AssetsPackage/config.bytes"); var obj = LitJson.JsonMapper.ToObject <Dictionary <string, string> >(jstr); string version = obj["ResVer"]; var settings = AASUtility.GetSettings(); string fold = Directory.GetParent(settings.RemoteCatalogBuildPath.GetValue(settings)).FullName; string targetPath = Path.Combine(relativeDirPrefix, $"{version}_{platform}"); if (!Directory.Exists(targetPath)) { Directory.CreateDirectory(targetPath); } FileHelper.CleanDirectory(targetPath); FileHelper.CopyFiles(fold, targetPath); UnityEngine.Debug.Log("完成cdn资源打包"); }