mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
更新HybirdCLR Procedure
更新HybirdCLR Procedure
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 786fadd7944e4da47b5272e501edc067
|
guid: 2e3556191f5868b45bdae236bf486400
|
||||||
AssemblyDefinitionImporter:
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
userData:
|
userData:
|
||||||
assetBundleName:
|
assetBundleName:
|
8
Assets/GameMain/Scripts.meta
Normal file
8
Assets/GameMain/Scripts.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 87b670c48f0b7184bbcdbab5636fecce
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@@ -29,7 +29,7 @@ namespace TEngine.Runtime
|
|||||||
UILoadMgr.Show(UIDefine.UILoadUpdate);
|
UILoadMgr.Show(UIDefine.UILoadUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected internal override void OnEnter(IFsm<IProcedureManager> procedureOwner)
|
protected override void OnEnter(IFsm<IProcedureManager> procedureOwner)
|
||||||
{
|
{
|
||||||
base.OnEnter(procedureOwner);
|
base.OnEnter(procedureOwner);
|
||||||
m_CheckVersionComplete = false;
|
m_CheckVersionComplete = false;
|
||||||
@@ -163,7 +163,7 @@ namespace TEngine.Runtime
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected internal override void OnUpdate(IFsm<IProcedureManager> procedureOwner, float elapseSeconds, float realElapseSeconds)
|
protected override void OnUpdate(IFsm<IProcedureManager> procedureOwner, float elapseSeconds, float realElapseSeconds)
|
||||||
{
|
{
|
||||||
base.OnUpdate(procedureOwner, elapseSeconds, realElapseSeconds);
|
base.OnUpdate(procedureOwner, elapseSeconds, realElapseSeconds);
|
||||||
if (m_result == null || !m_result.isDone)
|
if (m_result == null || !m_result.isDone)
|
@@ -1,5 +1,7 @@
|
|||||||
using System.Linq;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using HybridCLR;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace TEngine.Runtime
|
namespace TEngine.Runtime
|
||||||
@@ -9,6 +11,39 @@ namespace TEngine.Runtime
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ProcedureCodeInit : ProcedureBase
|
public class ProcedureCodeInit : ProcedureBase
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public static List<string> AOTMetaAssemblyNames { get; } = new List<string>()
|
||||||
|
{
|
||||||
|
"mscorlib.dll",
|
||||||
|
"System.dll",
|
||||||
|
"System.Core.dll",
|
||||||
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 为aot assembly加载原始metadata, 这个代码放aot或者热更新都行。
|
||||||
|
/// 一旦加载后,如果AOT泛型函数对应native实现不存在,则自动替换为解释模式执行
|
||||||
|
/// </summary>
|
||||||
|
private static void LoadMetadataForAOTAssemblies()
|
||||||
|
{
|
||||||
|
// 可以加载任意aot assembly的对应的dll。但要求dll必须与unity build过程中生成的裁剪后的dll一致,而不能直接使用原始dll。
|
||||||
|
// 我们在BuildProcessors里添加了处理代码,这些裁剪后的dll在打包时自动被复制到 {项目目录}/HybridCLRData/AssembliesPostIl2CppStrip/{Target} 目录。
|
||||||
|
|
||||||
|
// 注意,补充元数据是给AOT dll补充元数据,而不是给热更新dll补充元数据。
|
||||||
|
// 热更新dll不缺元数据,不需要补充,如果调用LoadMetadataForAOTAssembly会返回错误
|
||||||
|
foreach (var aotDllName in AOTMetaAssemblyNames)
|
||||||
|
{
|
||||||
|
byte[] dllBytes = TResources.Load<TextAsset>(aotDllName).bytes;
|
||||||
|
if (dllBytes == null)
|
||||||
|
{
|
||||||
|
Log.Fatal($"{aotDllName} is null");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 加载assembly对应的dll,会自动为它hook。一旦aot泛型函数的native函数不存在,用解释器版本代码
|
||||||
|
LoadImageErrorCode err = RuntimeApi.LoadMetadataForAOTAssembly(dllBytes);
|
||||||
|
Log.Info($"LoadMetadataForAOTAssembly:{aotDllName}. ret:{err}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否需要加载热更新DLL
|
/// 是否需要加载热更新DLL
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -16,7 +51,7 @@ namespace TEngine.Runtime
|
|||||||
|
|
||||||
private IFsm<IProcedureManager> m_procedureOwner;
|
private IFsm<IProcedureManager> m_procedureOwner;
|
||||||
|
|
||||||
protected internal override void OnEnter(IFsm<IProcedureManager> procedureOwner)
|
protected override void OnEnter(IFsm<IProcedureManager> procedureOwner)
|
||||||
{
|
{
|
||||||
base.OnEnter(procedureOwner);
|
base.OnEnter(procedureOwner);
|
||||||
|
|
||||||
@@ -28,8 +63,10 @@ namespace TEngine.Runtime
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LoadMetadataForAOTAssemblies();
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
Assembly hotfixAssembly = System.AppDomain.CurrentDomain.GetAssemblies().First(assembly => assembly.GetName().Name == "HotFix");
|
Assembly hotfixAssembly = System.AppDomain.CurrentDomain.GetAssemblies().First(assembly => assembly.GetName().Name == "Assembly-CSharp");
|
||||||
StartHotfix(hotfixAssembly);
|
StartHotfix(hotfixAssembly);
|
||||||
#else
|
#else
|
||||||
TResources.LoadAsync<TextAsset>("Dll/HotFix.dll.bytes", (data =>
|
TResources.LoadAsync<TextAsset>("Dll/HotFix.dll.bytes", (data =>
|
||||||
@@ -57,7 +94,7 @@ namespace TEngine.Runtime
|
|||||||
private void OnLoadAssetSuccess(TextAsset asset)
|
private void OnLoadAssetSuccess(TextAsset asset)
|
||||||
{
|
{
|
||||||
TextAsset dll = (TextAsset)asset;
|
TextAsset dll = (TextAsset)asset;
|
||||||
Assembly hotfixAssembly = Assembly.Load(dll.bytes);
|
Assembly hotfixAssembly = System.Reflection.Assembly.Load(dll.bytes);
|
||||||
Log.Info("Load hotfix dll OK.");
|
Log.Info("Load hotfix dll OK.");
|
||||||
StartHotfix(hotfixAssembly);
|
StartHotfix(hotfixAssembly);
|
||||||
}
|
}
|
15
Assets/GameMain/Scripts/GameProcedure/ProcedureLaunch.cs
Normal file
15
Assets/GameMain/Scripts/GameProcedure/ProcedureLaunch.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
namespace TEngine.Runtime
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 流程加载器 - 开始起点
|
||||||
|
/// </summary>
|
||||||
|
public class ProcedureLaunch : ProcedureBase
|
||||||
|
{
|
||||||
|
|
||||||
|
protected override void OnUpdate(IFsm<IProcedureManager> procedureOwner, float elapseSeconds, float realElapseSeconds)
|
||||||
|
{
|
||||||
|
base.OnUpdate(procedureOwner, elapseSeconds, realElapseSeconds);
|
||||||
|
ChangeState<ProcedureSplash>(procedureOwner);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -9,12 +9,7 @@ namespace TEngine.Runtime
|
|||||||
{
|
{
|
||||||
private bool m_initResourceComplete = false;
|
private bool m_initResourceComplete = false;
|
||||||
|
|
||||||
protected internal override void OnInit(IFsm<IProcedureManager> procedureOwner)
|
protected override void OnEnter(IFsm<IProcedureManager> procedureOwner)
|
||||||
{
|
|
||||||
base.OnInit(procedureOwner);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected internal override void OnEnter(IFsm<IProcedureManager> procedureOwner)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
base.OnEnter(procedureOwner);
|
base.OnEnter(procedureOwner);
|
||||||
@@ -26,7 +21,7 @@ namespace TEngine.Runtime
|
|||||||
}),new WaitForSeconds(1f));
|
}),new WaitForSeconds(1f));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected internal override void OnUpdate(IFsm<IProcedureManager> procedureOwner, float elapseSeconds, float realElapseSeconds)
|
protected override void OnUpdate(IFsm<IProcedureManager> procedureOwner, float elapseSeconds, float realElapseSeconds)
|
||||||
{
|
{
|
||||||
base.OnUpdate(procedureOwner, elapseSeconds, realElapseSeconds);
|
base.OnUpdate(procedureOwner, elapseSeconds, realElapseSeconds);
|
||||||
|
|
||||||
@@ -37,17 +32,12 @@ namespace TEngine.Runtime
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected internal override void OnLeave(IFsm<IProcedureManager> procedureOwner, bool isShutdown)
|
protected override void OnLeave(IFsm<IProcedureManager> procedureOwner, bool isShutdown)
|
||||||
{
|
{
|
||||||
base.OnLeave(procedureOwner, isShutdown);
|
base.OnLeave(procedureOwner, isShutdown);
|
||||||
GameEventMgr.Instance.RemoveEventListener("OnInitResourceComplete", OnInitResourceComplete);
|
GameEventMgr.Instance.RemoveEventListener("OnInitResourceComplete", OnInitResourceComplete);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected internal override void OnDestroy(IFsm<IProcedureManager> procedureOwner)
|
|
||||||
{
|
|
||||||
base.OnDestroy(procedureOwner);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnInitResourceComplete()
|
private void OnInitResourceComplete()
|
||||||
{
|
{
|
||||||
m_initResourceComplete = true;
|
m_initResourceComplete = true;
|
@@ -14,7 +14,7 @@ namespace TEngine.Runtime
|
|||||||
private IFsm<IProcedureManager> _procedureOwner;
|
private IFsm<IProcedureManager> _procedureOwner;
|
||||||
private bool _dllLoad = false;
|
private bool _dllLoad = false;
|
||||||
|
|
||||||
protected internal override void OnEnter(IFsm<IProcedureManager> procedureOwner)
|
protected override void OnEnter(IFsm<IProcedureManager> procedureOwner)
|
||||||
{
|
{
|
||||||
base.OnEnter(procedureOwner);
|
base.OnEnter(procedureOwner);
|
||||||
|
|
@@ -8,17 +8,7 @@ namespace TEngine.Runtime
|
|||||||
{
|
{
|
||||||
private bool m_VerifyResourcesComplete = false;
|
private bool m_VerifyResourcesComplete = false;
|
||||||
|
|
||||||
protected internal override void OnEnter(IFsm<IProcedureManager> procedureOwner)
|
protected override void OnUpdate(IFsm<IProcedureManager> procedureOwner, float elapseSeconds, float realElapseSeconds)
|
||||||
{
|
|
||||||
base.OnEnter(procedureOwner);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected internal override void OnLeave(IFsm<IProcedureManager> procedureOwner, bool isShutdown)
|
|
||||||
{
|
|
||||||
base.OnLeave(procedureOwner, isShutdown);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected internal override void OnUpdate(IFsm<IProcedureManager> procedureOwner, float elapseSeconds, float realElapseSeconds)
|
|
||||||
{
|
{
|
||||||
base.OnUpdate(procedureOwner, elapseSeconds, realElapseSeconds);
|
base.OnUpdate(procedureOwner, elapseSeconds, realElapseSeconds);
|
||||||
|
|
@@ -11,17 +11,18 @@ namespace TEngine.Runtime
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ProcedureSplash : ProcedureBase
|
public class ProcedureSplash : ProcedureBase
|
||||||
{
|
{
|
||||||
protected internal override void OnInit(IFsm<IProcedureManager> procedureOwner)
|
protected override void OnInit(IFsm<IProcedureManager> procedureOwner)
|
||||||
{
|
{
|
||||||
base.OnInit(procedureOwner);
|
base.OnInit(procedureOwner);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected internal override void OnEnter(IFsm<IProcedureManager> procedureOwner)
|
protected override void OnEnter(IFsm<IProcedureManager> procedureOwner)
|
||||||
{
|
{
|
||||||
base.OnEnter(procedureOwner);
|
base.OnEnter(procedureOwner);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected internal override void OnUpdate(IFsm<IProcedureManager> procedureOwner, float elapseSeconds, float realElapseSeconds)
|
protected override void OnUpdate(IFsm<IProcedureManager> procedureOwner, float elapseSeconds,
|
||||||
|
float realElapseSeconds)
|
||||||
{
|
{
|
||||||
base.OnUpdate(procedureOwner, elapseSeconds, realElapseSeconds);
|
base.OnUpdate(procedureOwner, elapseSeconds, realElapseSeconds);
|
||||||
|
|
||||||
@@ -38,15 +39,5 @@ namespace TEngine.Runtime
|
|||||||
ChangeState<ProcedureCheckVersion>(procedureOwner);
|
ChangeState<ProcedureCheckVersion>(procedureOwner);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected internal override void OnLeave(IFsm<IProcedureManager> procedureOwner, bool isShutdown)
|
|
||||||
{
|
|
||||||
base.OnLeave(procedureOwner, isShutdown);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected internal override void OnDestroy(IFsm<IProcedureManager> procedureOwner)
|
|
||||||
{
|
|
||||||
base.OnDestroy(procedureOwner);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
19
Assets/GameMain/Scripts/GameProcedure/ProcedureStartGame.cs
Normal file
19
Assets/GameMain/Scripts/GameProcedure/ProcedureStartGame.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
namespace TEngine.Runtime
|
||||||
|
{
|
||||||
|
public static partial class TEngineEvent
|
||||||
|
{
|
||||||
|
public static readonly int OnStartGame = StringId.StringToHash("TEngineEvent.OnStartGame");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 流程加载器 - 终点StartGame
|
||||||
|
/// </summary>
|
||||||
|
public class ProcedureStartGame : ProcedureBase
|
||||||
|
{
|
||||||
|
protected override void OnEnter(IFsm<IProcedureManager> procedureOwner)
|
||||||
|
{
|
||||||
|
base.OnEnter(procedureOwner);
|
||||||
|
GameEventMgr.Instance.Send(TEngineEvent.OnStartGame);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,18 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "TEngine.Demo",
|
|
||||||
"rootNamespace": "",
|
|
||||||
"references": [
|
|
||||||
"GUID:f4ecd6f7bd8993043b6cec60dd0cf2b2"
|
|
||||||
],
|
|
||||||
"includePlatforms": [
|
|
||||||
"Editor"
|
|
||||||
],
|
|
||||||
"excludePlatforms": [],
|
|
||||||
"allowUnsafeCode": false,
|
|
||||||
"overrideReferences": false,
|
|
||||||
"precompiledReferences": [],
|
|
||||||
"autoReferenced": true,
|
|
||||||
"defineConstraints": [],
|
|
||||||
"versionDefines": [],
|
|
||||||
"noEngineReferences": false
|
|
||||||
}
|
|
@@ -1,24 +0,0 @@
|
|||||||
namespace TEngine.Runtime
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 流程加载器 - 开始起点
|
|
||||||
/// </summary>
|
|
||||||
public class ProcedureLaunch : ProcedureBase
|
|
||||||
{
|
|
||||||
protected internal override void OnInit(IFsm<IProcedureManager> procedureOwner)
|
|
||||||
{
|
|
||||||
base.OnInit(procedureOwner);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected internal override void OnEnter(IFsm<IProcedureManager> procedureOwner)
|
|
||||||
{
|
|
||||||
base.OnEnter(procedureOwner);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected internal override void OnUpdate(IFsm<IProcedureManager> procedureOwner, float elapseSeconds, float realElapseSeconds)
|
|
||||||
{
|
|
||||||
base.OnUpdate(procedureOwner, elapseSeconds, realElapseSeconds);
|
|
||||||
ChangeState<ProcedureSplash>(procedureOwner);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,34 +0,0 @@
|
|||||||
namespace TEngine.Runtime
|
|
||||||
{
|
|
||||||
public static partial class TEngineEvent
|
|
||||||
{
|
|
||||||
public static readonly int OnStartGame = StringId.StringToHash("TEngineEvent.OnStartGame");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 流程加载器 - 终点StartGame
|
|
||||||
/// </summary>
|
|
||||||
public class ProcedureStartGame : ProcedureBase
|
|
||||||
{
|
|
||||||
protected internal override void OnInit(IFsm<IProcedureManager> procedureOwner)
|
|
||||||
{
|
|
||||||
base.OnInit(procedureOwner);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected internal override void OnEnter(IFsm<IProcedureManager> procedureOwner)
|
|
||||||
{
|
|
||||||
base.OnEnter(procedureOwner);
|
|
||||||
GameEventMgr.Instance.Send(TEngineEvent.OnStartGame);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected internal override void OnLeave(IFsm<IProcedureManager> procedureOwner, bool isShutdown)
|
|
||||||
{
|
|
||||||
base.OnLeave(procedureOwner, isShutdown);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected internal override void OnDestroy(IFsm<IProcedureManager> procedureOwner)
|
|
||||||
{
|
|
||||||
base.OnDestroy(procedureOwner);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -73,7 +73,7 @@ namespace TEngine.Runtime.HotUpdate
|
|||||||
get { return _instance ?? (_instance = new LoadText()); }
|
get { return _instance ?? (_instance = new LoadText()); }
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void InitConfigData(TextAsset asset)
|
public void InitConfigData(TextAsset asset)
|
||||||
{
|
{
|
||||||
if (asset == null)
|
if (asset == null)
|
||||||
return;
|
return;
|
||||||
|
Reference in New Issue
Block a user