mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 10:46:17 +00:00
提交
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
using System.IO;
|
||||
using HybridCLR.Editor;
|
||||
using HybridCLR.Editor.Commands;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SHFrame.Editor
|
||||
{
|
||||
public static class BuildAssetsCommand
|
||||
{
|
||||
public static string HybridCLRBuildCacheDir => Application.dataPath + "/HybridCLRBuildCache";
|
||||
|
||||
public static string AssetBundleOutputDir => $"{HybridCLRBuildCacheDir}/AssetBundleOutput";
|
||||
|
||||
public static string DllBytesDir => $"{Application.dataPath}/HotAssets/HotDlls";
|
||||
|
||||
public static string GetAssetBundleOutputDirByTarget(BuildTarget target)
|
||||
{
|
||||
return $"{AssetBundleOutputDir}/{target}";
|
||||
}
|
||||
|
||||
public static string ToRelativeAssetPath(string s)
|
||||
{
|
||||
return s.Substring(s.IndexOf("Assets/"));
|
||||
}
|
||||
|
||||
[MenuItem("HybridCLR/Build/泛型补充dll与热更新dll导出")]
|
||||
public static void BuildAndCopyABAOTHotUpdateDlls()
|
||||
{
|
||||
BuildTarget target = EditorUserBuildSettings.activeBuildTarget;
|
||||
CompileDllCommand.CompileDll(target);
|
||||
CopyABAOTHotUpdateDlls(target);
|
||||
}
|
||||
|
||||
public static void CopyABAOTHotUpdateDlls(BuildTarget target)
|
||||
{
|
||||
CopyAssetBundlesToStreamingAssets(target);
|
||||
|
||||
ClearEmptyFolder(DllBytesDir);
|
||||
|
||||
CopyAOTAssembliesToStreamingAssets();
|
||||
CopyHotUpdateAssembliesToStreamingAssets();
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
public static void CopyAOTAssembliesToStreamingAssets()
|
||||
{
|
||||
var target = EditorUserBuildSettings.activeBuildTarget;
|
||||
string aotAssembliesSrcDir = SettingsUtil.GetAssembliesPostIl2CppStripDir(target);
|
||||
//string aotAssembliesDstDir = "D:\\User\\Dou\\Unitys\\2023fars\\Assets\\HotAsset\\HotDlls";
|
||||
string aotAssembliesDstDir = Application.streamingAssetsPath;
|
||||
|
||||
foreach (var dll in SettingsUtil.AOTAssemblyNames)
|
||||
{
|
||||
string srcDllPath = $"{aotAssembliesSrcDir}/{dll}.dll";
|
||||
if (!File.Exists(srcDllPath))
|
||||
{
|
||||
Debug.LogError($"ab中添加AOT补充元数据dll:{srcDllPath} 时发生错误,文件不存在。裁剪后的AOT dll在BuildPlayer时才能生成,因此需要你先构建一次游戏App后再打包。");
|
||||
continue;
|
||||
}
|
||||
string dllBytesPath = $"{DllBytesDir}/{dll}.dll.bytes";
|
||||
File.Copy(srcDllPath, dllBytesPath, true);
|
||||
Debug.Log($"[CopyAOTAssembliesToStreamingAssets] copy AOT dll {srcDllPath} -> {dllBytesPath}");
|
||||
}
|
||||
}
|
||||
|
||||
public static void CopyHotUpdateAssembliesToStreamingAssets()
|
||||
{
|
||||
var target = EditorUserBuildSettings.activeBuildTarget;
|
||||
|
||||
string hotfixDllSrcDir = SettingsUtil.GetHotUpdateDllsOutputDirByTarget(target);
|
||||
//string hotfixAssembliesDstDir = "D:\\User\\Dou\\Unitys\\2023fars\\Assets\\HotAsset\\HotDlls";
|
||||
string hotfixAssembliesDstDir = Application.streamingAssetsPath;
|
||||
|
||||
foreach (var dll in SettingsUtil.HotUpdateAssemblyFilesExcludePreserved)
|
||||
{
|
||||
string dllPath = $"{hotfixDllSrcDir}/{dll}";
|
||||
string dllBytesPath = $"{DllBytesDir}/{dll}.bytes";
|
||||
File.Copy(dllPath, dllBytesPath, true);
|
||||
Debug.Log($"[CopyHotUpdateAssembliesToStreamingAssets] copy hotfix dll {dllPath} -> {dllBytesPath}");
|
||||
}
|
||||
}
|
||||
|
||||
public static void CopyAssetBundlesToStreamingAssets(BuildTarget target)
|
||||
{
|
||||
string streamingAssetPathDst = Application.streamingAssetsPath;
|
||||
Directory.CreateDirectory(streamingAssetPathDst);
|
||||
string outputDir = GetAssetBundleOutputDirByTarget(target);
|
||||
var abs = new string[] { "prefabs" };
|
||||
foreach (var ab in abs)
|
||||
{
|
||||
string srcAb = ToRelativeAssetPath($"{outputDir}/{ab}");
|
||||
string dstAb = ToRelativeAssetPath($"{streamingAssetPathDst}/{ab}");
|
||||
Debug.Log($"[CopyAssetBundlesToStreamingAssets] copy assetbundle {srcAb} -> {dstAb}");
|
||||
AssetDatabase.CopyAsset(srcAb, dstAb);
|
||||
}
|
||||
}
|
||||
private static void ClearEmptyFolder(string folderPath)
|
||||
{
|
||||
DirectoryInfo dir = new DirectoryInfo(folderPath);
|
||||
DirectoryInfo[] subDirs = dir.GetDirectories("*.*", SearchOption.AllDirectories);
|
||||
foreach (DirectoryInfo subDir in subDirs)
|
||||
{
|
||||
FileSystemInfo[] subFiles = subDir.GetFileSystemInfos();
|
||||
if (subFiles.Length == 0)
|
||||
{
|
||||
File.Delete(subDir.FullName + ".meta");
|
||||
subDir.Delete();
|
||||
}
|
||||
}
|
||||
|
||||
FileInfo[] files = dir.GetFiles();
|
||||
foreach (FileInfo file in files)
|
||||
{
|
||||
File.Delete(file.FullName);
|
||||
}
|
||||
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a8357532218e6f49a9bb9401382d6d4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,84 @@
|
||||
using System.IO;
|
||||
using HybridCLR.Editor;
|
||||
using HybridCLR.Editor.Commands;
|
||||
using HybridCLR.Editor.Installer;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SHFrame.Editor
|
||||
{
|
||||
public class BuildPlayerCommand
|
||||
{
|
||||
public static void CopyAssets(string outputDir)
|
||||
{
|
||||
Directory.CreateDirectory(outputDir);
|
||||
|
||||
foreach (var srcFile in Directory.GetFiles(Application.streamingAssetsPath))
|
||||
{
|
||||
string dstFile = $"{outputDir}/{Path.GetFileName(srcFile)}";
|
||||
File.Copy(srcFile, dstFile, true);
|
||||
}
|
||||
}
|
||||
|
||||
public static void InstallFromRepo()
|
||||
{
|
||||
var ic = new InstallerController();
|
||||
ic.InstallDefaultHybridCLR();
|
||||
}
|
||||
|
||||
public static void InstallBuildWin64()
|
||||
{
|
||||
InstallFromRepo();
|
||||
Build_Win64(true);
|
||||
}
|
||||
|
||||
[MenuItem("HybridCLR/Build/Win64")]
|
||||
public static void Build_Win64()
|
||||
{
|
||||
Build_Win64(false);
|
||||
}
|
||||
|
||||
public static void Build_Win64(bool existWhenCompleted)
|
||||
{
|
||||
BuildTarget target = BuildTarget.StandaloneWindows64;
|
||||
BuildTarget activeTarget = EditorUserBuildSettings.activeBuildTarget;
|
||||
if (activeTarget != BuildTarget.StandaloneWindows64 && activeTarget != BuildTarget.StandaloneWindows)
|
||||
{
|
||||
Debug.LogError("请先切到Win平台再打包");
|
||||
return;
|
||||
}
|
||||
// Get filename.
|
||||
string outputPath = $"{SettingsUtil.ProjectDir}/Release-Win64";
|
||||
|
||||
var buildOptions = BuildOptions.CompressWithLz4;
|
||||
|
||||
string location = $"{outputPath}/HybridCLRTrial.exe";
|
||||
|
||||
PrebuildCommand.GenerateAll();
|
||||
Debug.Log("====> Build App");
|
||||
BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions()
|
||||
{
|
||||
scenes = new string[] { "Assets/Scenes/main.unity" },
|
||||
locationPathName = location,
|
||||
options = buildOptions,
|
||||
target = target,
|
||||
targetGroup = BuildTargetGroup.Standalone,
|
||||
};
|
||||
|
||||
var report = BuildPipeline.BuildPlayer(buildPlayerOptions);
|
||||
if (report.summary.result != UnityEditor.Build.Reporting.BuildResult.Succeeded)
|
||||
{
|
||||
Debug.LogError("打包失败");
|
||||
if (existWhenCompleted)
|
||||
{
|
||||
EditorApplication.Exit(1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.Log("====> 复制热更新资源和代码");
|
||||
BuildAssetsCommand.BuildAndCopyABAOTHotUpdateDlls();
|
||||
BashUtil.CopyDir(Application.streamingAssetsPath, $"{outputPath}/HybridCLRTrial_Data/StreamingAssets", true);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7796c8df856ac4a4a9d644329c1f0958
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user