modify
This commit is contained in:
parent
1c0cbb362c
commit
0c5aa1a69c
@ -6,10 +6,10 @@
|
||||
"GUID:75b6f2078d190f14dbda4a5b747d709c",
|
||||
"GUID:e34a5702dd353724aa315fb8011f08c3",
|
||||
"GUID:4d1926c9df5b052469a1c63448b7609a",
|
||||
"GUID:be2f20a77f3232f44b9711ef43234aac",
|
||||
"GUID:a19b414bea3b97240a91aeab9a8eab36",
|
||||
"GUID:acfef7cabed3b0a42b25edb1cd4fa259",
|
||||
"GUID:2765e68924a08a94ea0ea66b31c0168f"
|
||||
"GUID:2765e68924a08a94ea0ea66b31c0168f",
|
||||
"GUID:1619e00706139ce488ff80c0daeea8e7",
|
||||
"GUID:2373f786d14518f44b0f475db77ba4de"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
@ -20,6 +20,12 @@
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"versionDefines": [
|
||||
{
|
||||
"name": "com.code-philosophy.hybridclr",
|
||||
"expression": "",
|
||||
"define": "HYBIRDCLR_SUPPORT"
|
||||
}
|
||||
],
|
||||
"noEngineReferences": false
|
||||
}
|
8
Editor/HybridCLR.meta
Normal file
8
Editor/HybridCLR.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b1e3904628b58d742976a1f0512c441e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
154
Editor/HybridCLR/BuildDLLCommand.cs
Normal file
154
Editor/HybridCLR/BuildDLLCommand.cs
Normal file
@ -0,0 +1,154 @@
|
||||
#if HYBIRDCLR_SUPPORT
|
||||
|
||||
#if ENABLE_HYBRIDCLR
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using HybridCLR.Editor;
|
||||
using HybridCLR.Editor.Commands;
|
||||
#endif
|
||||
|
||||
using System.Reflection;
|
||||
using AlicizaX;
|
||||
using AlicizaX.Editor;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
[InitializeOnLoad]
|
||||
public static class BuildDLLCommand
|
||||
{
|
||||
private const string EnableHybridClrScriptingDefineSymbol = "ENABLE_HYBRIDCLR";
|
||||
public static string AssemblyTextAssetPath = Application.dataPath + "/" + "Bundles/DLL";
|
||||
|
||||
public static void SetCopyPath(string path)
|
||||
{
|
||||
AssemblyTextAssetPath = path;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 禁用HybridCLR宏定义。
|
||||
/// </summary>
|
||||
[MenuItem("HybridCLR/Tools/Define Symbols/Disable HybridCLR", false, 30)]
|
||||
public static void Disable()
|
||||
{
|
||||
ScriptingDefineSymbols.RemoveScriptingDefineSymbol(EnableHybridClrScriptingDefineSymbol);
|
||||
HybridCLR.Editor.SettingsUtil.Enable = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开启HybridCLR宏定义。
|
||||
/// </summary>
|
||||
[MenuItem("HybridCLR/Tools/Define Symbols/Enable HybridCLR", false, 31)]
|
||||
public static void Enable()
|
||||
{
|
||||
ScriptingDefineSymbols.RemoveScriptingDefineSymbol(EnableHybridClrScriptingDefineSymbol);
|
||||
ScriptingDefineSymbols.AddScriptingDefineSymbol(EnableHybridClrScriptingDefineSymbol);
|
||||
HybridCLR.Editor.SettingsUtil.Enable = true;
|
||||
}
|
||||
|
||||
#if ENABLE_HYBRIDCLR &&HYBIRDCLR_SUPPORT
|
||||
[MenuItem("HybridCLR/Tools/BuildAssets And CopyTo AssemblyTextAssetPath")]
|
||||
public static void BuildAndCopyDlls()
|
||||
{
|
||||
BuildTarget target = EditorUserBuildSettings.activeBuildTarget;
|
||||
CompileDllCommand.CompileDll(target);
|
||||
CopyAOTHotUpdateDlls(target);
|
||||
}
|
||||
|
||||
|
||||
public static void GenerateHybridCLRSome()
|
||||
{
|
||||
PrebuildCommand.GenerateAll();
|
||||
}
|
||||
|
||||
public static void BuildAndCopyDlls(BuildTarget target)
|
||||
{
|
||||
CompileDllCommand.CompileDll(target);
|
||||
CopyAOTHotUpdateDlls(target);
|
||||
}
|
||||
|
||||
public static void CopyAOTHotUpdateDlls(BuildTarget target)
|
||||
{
|
||||
CopyAOTAssembliesToAssetPath();
|
||||
CopyHotUpdateAssembliesToAssetPath();
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
public static void CopyAOTAssembliesToAssetPath()
|
||||
{
|
||||
IReadOnlyList<string> patchedAotAssembliesPath = GetStaticFieldValue();
|
||||
if (patchedAotAssembliesPath == null)
|
||||
{
|
||||
Debug.Log("请先生成AOT补充脚本");
|
||||
return;
|
||||
}
|
||||
|
||||
var target = EditorUserBuildSettings.activeBuildTarget;
|
||||
string aotAssembliesSrcDir = SettingsUtil.GetAssembliesPostIl2CppStripDir(target);
|
||||
string aotAssembliesDstDir = AssemblyTextAssetPath;
|
||||
|
||||
foreach (var dll in patchedAotAssembliesPath)
|
||||
{
|
||||
string srcDllPath = $"{aotAssembliesSrcDir}/{dll}";
|
||||
if (!System.IO.File.Exists(srcDllPath))
|
||||
{
|
||||
Debug.LogError(
|
||||
$"ab中添加AOT补充元数据dll:{srcDllPath} 时发生错误,文件不存在。裁剪后的AOT dll在BuildPlayer时才能生成,因此需要你先构建一次游戏App后再打包。");
|
||||
continue;
|
||||
}
|
||||
|
||||
string dllBytesPath = $"{aotAssembliesDstDir}/{dll}.bytes";
|
||||
System.IO.File.Copy(srcDllPath, dllBytesPath, true);
|
||||
Debug.Log($"[CopyAOTAssembliesToStreamingAssets] copy AOT dll {srcDllPath} -> {dllBytesPath}");
|
||||
}
|
||||
}
|
||||
|
||||
private static IReadOnlyList<string> GetStaticFieldValue()
|
||||
{
|
||||
var gs = SettingsUtil.HybridCLRSettings;
|
||||
string scriptPath = $"{Application.dataPath}/{gs.outputAOTGenericReferenceFile}";
|
||||
if (!File.Exists(scriptPath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
FileInfo info = new FileInfo(scriptPath);
|
||||
string scriptTypeName = info.Name.Replace(".cs", "");
|
||||
|
||||
Type targetType = Utility.Assembly.GetType(scriptTypeName);
|
||||
if (targetType == null)
|
||||
{
|
||||
Debug.LogError($"can not find script type: {scriptTypeName}");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 反射获取静态字段
|
||||
FieldInfo field = targetType.GetField("PatchedAOTAssemblyList",
|
||||
BindingFlags.Public | BindingFlags.Static);
|
||||
|
||||
if (field == null)
|
||||
{
|
||||
Debug.LogError($"Field 'PatchedAOTAssemblyList' not found in {targetType.Name}");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 获取字段值并打印
|
||||
return field.GetValue(null) as IReadOnlyList<string>;
|
||||
}
|
||||
|
||||
public static void CopyHotUpdateAssembliesToAssetPath()
|
||||
{
|
||||
var target = EditorUserBuildSettings.activeBuildTarget;
|
||||
|
||||
string hotfixDllSrcDir = SettingsUtil.GetHotUpdateDllsOutputDirByTarget(target);
|
||||
string hotfixAssembliesDstDir = AssemblyTextAssetPath;
|
||||
foreach (var dll in SettingsUtil.HotUpdateAssemblyFilesExcludePreserved)
|
||||
{
|
||||
string dllPath = $"{hotfixDllSrcDir}/{dll}";
|
||||
string dllBytesPath = $"{hotfixAssembliesDstDir}/{dll}.bytes";
|
||||
System.IO.File.Copy(dllPath, dllBytesPath, true);
|
||||
Debug.Log($"[CopyHotUpdateAssembliesToStreamingAssets] copy hotfix dll {dllPath} -> {dllBytesPath}");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
3
Editor/HybridCLR/BuildDLLCommand.cs.meta
Normal file
3
Editor/HybridCLR/BuildDLLCommand.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0761954ba63648b8b73f8ebb736bb9eb
|
||||
timeCreated: 1737524294
|
Loading…
Reference in New Issue
Block a user