229 lines
7.8 KiB
C#
229 lines
7.8 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.IO;
|
|||
|
|
using AutoBuild.Helper;
|
|||
|
|
using HybridCLR.Editor;
|
|||
|
|
using HybridCLR.Editor.Commands;
|
|||
|
|
using HybridCLR.Editor.Installer;
|
|||
|
|
using PhxhSDK.AOT.VersionUpdate;
|
|||
|
|
using UnityEditor;
|
|||
|
|
using UnityEditor.SceneManagement;
|
|||
|
|
using UnityEngine;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 编辑器下打包
|
|||
|
|
/// </summary>
|
|||
|
|
class BuildLauncher
|
|||
|
|
{
|
|||
|
|
private const string HybirdCLRGenerateDir = "/HybridCLRGenerate";
|
|||
|
|
private const string HybirdCLRGenerateLinkPath = "Assets/HybridCLRGenerate/link.xml";
|
|||
|
|
private const string GameLauncherSceneName = "Assets/Scenes/GameLauncher.unity";
|
|||
|
|
|
|||
|
|
private static bool enableHotUpdate;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 开启热更
|
|||
|
|
/// </summary>
|
|||
|
|
public static void SetEnableHotUpdate(bool isEnable)
|
|||
|
|
{
|
|||
|
|
Debug.Log($"是否开启热更新:{isEnable}");
|
|||
|
|
var gameLauncherScene = EditorSceneManager.OpenScene(GameLauncherSceneName, OpenSceneMode.Additive);
|
|||
|
|
if (!gameLauncherScene.IsValid())
|
|||
|
|
{
|
|||
|
|
Debug.LogError($"无法加载场景{GameLauncherSceneName}");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var gameLauncher = UnityEngine.Object.FindObjectOfType<GameLauncher>();
|
|||
|
|
if (gameLauncher == null)
|
|||
|
|
{
|
|||
|
|
Debug.LogError("找不到GameLauncher");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
gameLauncher.enableHotUpdate = isEnable;
|
|||
|
|
EditorSceneManager.MarkSceneDirty(gameLauncherScene);
|
|||
|
|
EditorSceneManager.SaveScene(gameLauncherScene);
|
|||
|
|
EditorSceneManager.CloseScene(gameLauncherScene, false);
|
|||
|
|
HybridCLR.Editor.SettingsUtil.Enable = isEnable;
|
|||
|
|
if (!isEnable)
|
|||
|
|
{
|
|||
|
|
//删除HybirdCLR生成的link文件
|
|||
|
|
AssetDatabase.DeleteAsset(HybirdCLRGenerateLinkPath);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 构建热更
|
|||
|
|
/// </summary>
|
|||
|
|
public static void BuildHotUpdateDlls()
|
|||
|
|
{
|
|||
|
|
var controller = new InstallerController();
|
|||
|
|
if (!controller.HasInstalledHybridCLR())
|
|||
|
|
controller.InstallDefaultHybridCLR();
|
|||
|
|
BuildUtils.SetFileReadable(Application.dataPath + HybirdCLRGenerateDir);
|
|||
|
|
PrebuildCommand.GenerateAll();
|
|||
|
|
HotUpadeEditorHelper.CopyHotUpdateDll();
|
|||
|
|
HotUpadeEditorHelper.CopyMetaDataDll();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 打包面板初始化
|
|||
|
|
/// </summary>
|
|||
|
|
public static void Init(BuildTarget buildTarget,
|
|||
|
|
string workSpace,
|
|||
|
|
string appVersion,
|
|||
|
|
string profileName,
|
|||
|
|
bool developmentBuild,
|
|||
|
|
bool hotUpdate)
|
|||
|
|
{
|
|||
|
|
EditorUserBuildSettings.development = developmentBuild;
|
|||
|
|
YooAssetBuildBase.BuildTargetPlatform = buildTarget;
|
|||
|
|
YooAssetBuildBase.profileName = profileName;
|
|||
|
|
YooAssetBuildBase.JudgmentPlatform(buildTarget.ToString());
|
|||
|
|
YooAssetBuildBase.workSpace = string.IsNullOrEmpty(workSpace) ? "WorkSpace" : workSpace;
|
|||
|
|
PlayerSettings.bundleVersion = appVersion;
|
|||
|
|
YooAssetBuildBase.appVersion = appVersion;
|
|||
|
|
enableHotUpdate = hotUpdate;
|
|||
|
|
|
|||
|
|
if (profileName.Equals("AllLocal"))
|
|||
|
|
{
|
|||
|
|
List<string> appendDefineList = new() { "AllLocal" };
|
|||
|
|
var currentTargetGroup = BuildPipeline.GetBuildTargetGroup(EditorUserBuildSettings.activeBuildTarget);
|
|||
|
|
var oldDefines = PlayerSettings.GetScriptingDefineSymbolsForGroup(currentTargetGroup);
|
|||
|
|
BatchBuild._oldDefines = oldDefines;
|
|||
|
|
|
|||
|
|
var newDefineList = new List<string>();
|
|||
|
|
newDefineList.AddRange(oldDefines.Split(';'));
|
|||
|
|
for (var i = 0; i < newDefineList.Count; i++)
|
|||
|
|
{
|
|||
|
|
var define = newDefineList[i];
|
|||
|
|
if (string.IsNullOrEmpty(define))
|
|||
|
|
continue;
|
|||
|
|
|
|||
|
|
if (appendDefineList.Contains(define))
|
|||
|
|
appendDefineList.Remove(define);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
newDefineList.AddRange(appendDefineList);
|
|||
|
|
PlayerSettings.SetScriptingDefineSymbolsForGroup(currentTargetGroup, string.Join(";", newDefineList));
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 编辑器下构建资源
|
|||
|
|
/// </summary>
|
|||
|
|
public static void BuildResource()
|
|||
|
|
{
|
|||
|
|
var info = new UpdateLocalInfo();
|
|||
|
|
info.workSpace = YooAssetBuildBase.workSpace;
|
|||
|
|
info.version = YooAssetBuildBase.appVersion;
|
|||
|
|
info.isOss = YooAssetBuildBase.isOss;
|
|||
|
|
info.buildTicks = DateTime.Now.Ticks;
|
|||
|
|
PackDataInst.CreateResourceJson(info);
|
|||
|
|
|
|||
|
|
ExtBuildInfoHelper.CreateFirstExtBuildInfo(info.buildTicks, info.workSpace, info.version);
|
|||
|
|
|
|||
|
|
|
|||
|
|
SetEnableHotUpdate(enableHotUpdate);
|
|||
|
|
if (enableHotUpdate)
|
|||
|
|
{
|
|||
|
|
BuildHotUpdateDlls();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
YooAssetBuildBase.BuildResourceInEditor();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 编辑器下构建资源和Player
|
|||
|
|
/// </summary>
|
|||
|
|
public static void BuildResourceAndPlayer()
|
|||
|
|
{
|
|||
|
|
var info = new UpdateLocalInfo
|
|||
|
|
{
|
|||
|
|
workSpace = YooAssetBuildBase.workSpace,
|
|||
|
|
version = YooAssetBuildBase.appVersion,
|
|||
|
|
isOss = YooAssetBuildBase.isOss,
|
|||
|
|
buildTicks = DateTime.Now.Ticks
|
|||
|
|
};
|
|||
|
|
PackDataInst.CreateResourceJson(info);
|
|||
|
|
|
|||
|
|
ExtBuildInfoHelper.CreateFirstExtBuildInfo(info.buildTicks, info.workSpace, info.version);
|
|||
|
|
|
|||
|
|
SetEnableHotUpdate(enableHotUpdate);
|
|||
|
|
if (enableHotUpdate)
|
|||
|
|
{
|
|||
|
|
BuildHotUpdateDlls();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
YooAssetBuildBase.BuildContentAndPlayerInEditor();
|
|||
|
|
|
|||
|
|
ExtBuildInfoHelper.CreateVertifyBuildInfo(info.workSpace, info.version);
|
|||
|
|
|
|||
|
|
|
|||
|
|
if (!string.IsNullOrEmpty(BatchBuild._oldDefines))
|
|||
|
|
BatchBuild._RevertScriptDefines();
|
|||
|
|
|
|||
|
|
var aotDllStorePath = BatchBuild.GetAotDllStorePath(info.version);
|
|||
|
|
var aotDllPath = SettingsUtil.GetAssembliesPostIl2CppStripDir(EditorUserBuildSettings.activeBuildTarget);
|
|||
|
|
DirectoryInfo dir = new(aotDllPath);
|
|||
|
|
if (Directory.Exists(aotDllStorePath))
|
|||
|
|
Directory.Delete(aotDllStorePath, true);
|
|||
|
|
|
|||
|
|
Directory.CreateDirectory(aotDllStorePath);
|
|||
|
|
|
|||
|
|
FileInfo[] files = dir.GetFiles();
|
|||
|
|
foreach (FileInfo file in files)
|
|||
|
|
{
|
|||
|
|
file.CopyTo(Path.Combine(aotDllStorePath, file.Name), false);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 只构建Player
|
|||
|
|
/// </summary>
|
|||
|
|
public static void BuildPlayer()
|
|||
|
|
{
|
|||
|
|
YooAssetBuildBase.BuildPlayerInEditor();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 编辑器下热更
|
|||
|
|
/// </summary>
|
|||
|
|
public static void UpdatePreviousBuild(string workSpace, string version, BuildTarget buildTarget)
|
|||
|
|
{
|
|||
|
|
ExtBuildInfoHelper.VertifyExitBuildInfo(YooAssetBuildBase.workSpace, YooAssetBuildBase.appVersion);
|
|||
|
|
|
|||
|
|
Debug.Log("开始检查AOT版本");
|
|||
|
|
if (BatchBuild.CheckAotOutDate(YooAssetBuildBase.appVersion))
|
|||
|
|
{
|
|||
|
|
Debug.Log("AOT版本检查通过");
|
|||
|
|
BuildHotUpdateDlls();
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
Debug.LogError("AOT版本不匹配,请重新打AOT包");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 写入打包信息到Yoo_Build_Cache
|
|||
|
|
ExtBuildInfoHelper.UpdateExtBuildInfo(YooAssetBuildBase.workSpace, YooAssetBuildBase.appVersion);
|
|||
|
|
YooAssetBuildBase.BuildOnlyResUpdate();
|
|||
|
|
ExtBuildInfoHelper.CreateVertifyBuildInfo(YooAssetBuildBase.workSpace, YooAssetBuildBase.appVersion);
|
|||
|
|
|
|||
|
|
YooAssetBuildBase.UploadToServerYooAsset(workSpace, version, buildTarget);
|
|||
|
|
/*try
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
catch (Exception e)
|
|||
|
|
{
|
|||
|
|
DebugUtil.LogError($"[Build Exception]:{e.Message} \r\n {e.StackTrace}");
|
|||
|
|
throw;
|
|||
|
|
}*/
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public static void UploadToServer(string workSpace, string version, BuildTarget buildTarget)
|
|||
|
|
{
|
|||
|
|
YooAssetBuildBase.UploadToServerYooAsset(workSpace, version, buildTarget);
|
|||
|
|
}
|
|||
|
|
}
|