diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Module/UIModule/UIModule.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Module/UIModule/UIModule.cs
index 11d9444b..c2d48931 100644
--- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Module/UIModule/UIModule.cs
+++ b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Module/UIModule/UIModule.cs
@@ -538,7 +538,7 @@ namespace GameLogic
private UIWindow CreateInstance(Type type)
{
- UIWindow window = EmitHelper.CreateInstance(type) as UIWindow;
+ UIWindow window = Activator.CreateInstance(type) as UIWindow;
WindowAttribute attribute = Attribute.GetCustomAttribute(type, typeof(WindowAttribute)) as WindowAttribute;
if (window == null)
diff --git a/UnityProject/Assets/TEngine/Runtime/Core/MemoryPool/MemoryPool.MemoryCollection.cs b/UnityProject/Assets/TEngine/Runtime/Core/MemoryPool/MemoryPool.MemoryCollection.cs
index 2d222e41..aba4bcf0 100644
--- a/UnityProject/Assets/TEngine/Runtime/Core/MemoryPool/MemoryPool.MemoryCollection.cs
+++ b/UnityProject/Assets/TEngine/Runtime/Core/MemoryPool/MemoryPool.MemoryCollection.cs
@@ -77,7 +77,7 @@ namespace TEngine
}
_addMemoryCount++;
- return (IMemory)EmitHelper.CreateInstance(_memoryType);
+ return (IMemory)Activator.CreateInstance(_memoryType);
}
public void Release(IMemory memory)
@@ -121,7 +121,7 @@ namespace TEngine
_addMemoryCount += count;
while (count-- > 0)
{
- _memories.Enqueue((IMemory)EmitHelper.CreateInstance(_memoryType));
+ _memories.Enqueue((IMemory)Activator.CreateInstance(_memoryType));
}
}
}
diff --git a/UnityProject/Assets/TEngine/Runtime/Core/ModuleSystem.cs b/UnityProject/Assets/TEngine/Runtime/Core/ModuleSystem.cs
index d7eb37e1..401590d4 100644
--- a/UnityProject/Assets/TEngine/Runtime/Core/ModuleSystem.cs
+++ b/UnityProject/Assets/TEngine/Runtime/Core/ModuleSystem.cs
@@ -106,7 +106,7 @@ namespace TEngine
/// 要创建的游戏框架模块。
private static Module CreateModule(Type moduleType)
{
- Module module = (Module)EmitHelper.CreateInstance(moduleType);
+ Module module = (Module)Activator.CreateInstance(moduleType);
if (module == null)
{
throw new GameFrameworkException(Utility.Text.Format("Can not create module '{0}'.", moduleType.FullName));
diff --git a/UnityProject/Assets/TEngine/Runtime/Core/Utility/EmitHelper.cs b/UnityProject/Assets/TEngine/Runtime/Core/Utility/EmitHelper.cs
deleted file mode 100644
index bf30026b..00000000
--- a/UnityProject/Assets/TEngine/Runtime/Core/Utility/EmitHelper.cs
+++ /dev/null
@@ -1,193 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using System.Reflection.Emit;
-
-namespace TEngine
-{
- public static class EmitHelper
- {
- private static readonly Dictionary _defaultCache = new Dictionary();
-
- private static readonly Dictionary _argCache = new Dictionary();
-
- public static T CreateInstance() where T : new()
- {
- var type = typeof(T);
-
- if (!_defaultCache.TryGetValue(type, out var factory))
- {
- if (!_defaultCache.TryGetValue(type, out factory))
- {
- factory = CreateFactory();
- _defaultCache.TryAdd(type, factory);
- }
- }
-
- return ((Func)factory)();
- }
-
- public static object CreateInstance(Type type)
- {
- if (!_defaultCache.TryGetValue(type, out var factory))
- {
- lock (_defaultCache)
- {
- if (!_defaultCache.TryGetValue(type, out factory))
- {
- var constructor = type.GetConstructor(
- BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
- null, Type.EmptyTypes, null);
-
- if (constructor == null)
- {
- throw new MissingMethodException($"No parameterless constructor defined for type '{type.FullName}'");
- }
-
- // 创建动态方法(关键优化点)
- var dynamicMethod = new DynamicMethod(
- name: $"CreateInstance_{type.FullName}",
- returnType: typeof(object),
- parameterTypes: Type.EmptyTypes,
- owner: typeof(object),
- skipVisibility: true);
-
- // 生成IL指令(核心逻辑)
- var il = dynamicMethod.GetILGenerator();
-
- // 处理值类型和引用类型的差异
- if (type.IsValueType)
- {
- il.DeclareLocal(type);
- il.Emit(OpCodes.Ldloca_S, 0);
- il.Emit(OpCodes.Initobj, type);
- il.Emit(OpCodes.Ldloc_0);
- il.Emit(OpCodes.Box, type); // 值类型需要装箱
- }
- else
- {
- il.Emit(OpCodes.Newobj, constructor);
- }
-
- il.Emit(OpCodes.Ret);
-
- factory = dynamicMethod.CreateDelegate(typeof(Func