Update LoadDll.cs

This commit is contained in:
ALEXTANG
2022-05-26 20:23:17 +08:00
parent 2f9d40b686
commit a802cddeed

View File

@@ -19,14 +19,14 @@ public class LoadDll : MonoBehaviour
private void LoadGameDll() private void LoadGameDll()
{ {
#if !UNITY_EDITOR
#if UNITY_EDITOR TextAsset dllBytes2 = TResources.Load<TextAsset>("DLL/TEngineHotUpdate.dll.bytes");
TextAsset dllBytes2 = TResources.Load<TextAsset>("DLL/GameLogic.dll.bytes"); //生产模式从bytes加载
gameLogic = System.Reflection.Assembly.Load(dllBytes2.bytes); gameLogic = System.Reflection.Assembly.Load(dllBytes2.bytes);
#else #else
gameLogic = AppDomain.CurrentDomain.GetAssemblies().First(assembly => assembly.GetName().Name == "GameLogic"); //编辑器模式从dll反射加载
gameLogic = AppDomain.CurrentDomain.GetAssemblies().First(assembly => assembly.GetName().Name == "TEngineHotUpdate");
#endif #endif
} }
private void RunMain() private void RunMain()
@@ -37,20 +37,29 @@ public class LoadDll : MonoBehaviour
return; return;
} }
Type appType = gameLogic.GetType("GameMain"); AddMyComponent("TEngineCore.TEngineDemo", this.gameObject);
MethodInfo mainMethod = appType.GetMethod("RunMain");
mainMethod?.Invoke(null, null);
updateMethod = appType.GetMethod("Update"); //Type appType = gameLogic.GetType("TEngineCore.TEngine");
var updateDel = System.Delegate.CreateDelegate(typeof(Action<float>), null, updateMethod); //MethodInfo mainMethod = appType.GetMethod("InitLibImp");
//mainMethod?.Invoke(null, null);
//updateMethod = appType.GetMethod("Update");
//var updateDel = System.Delegate.CreateDelegate(typeof(Action<float>), null, updateMethod);
} }
void AddMyComponent(string className, GameObject obj)
{
Type type = gameLogic.GetType(className);
obj.AddComponent(type);
}
void Update() void Update()
{ {
if (gameLogic == null) //if (gameLogic == null)
{ //{
return; // return;
} //}
updateMethod?.Invoke(Time.deltaTime,null); //updateMethod?.Invoke(Time.deltaTime,null);
} }
} }