Skip to content

Commit 848839c

Browse files
author
DESKTOP-UBV38B7\codingworks
committed
dll中ilrt不支持带参数的Activator生成对象,更改为反射直接调用构造函数生成
1 parent d022f4f commit 848839c

File tree

9 files changed

+8
-1
lines changed

9 files changed

+8
-1
lines changed

Assets/Game/HotFix/HotFix.dll.bytes

-1.5 KB
Binary file not shown.

Assets/Game/HotFix/HotFix.pdb.bytes

-2 KB
Binary file not shown.

HotFix/HotFix/GameFramework/UI/UIManager.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
using System;
1212
using System.Collections.Generic;
13+
using System.Reflection;
1314
using UnityEngine;
1415

1516
namespace HotFix.Taurus
@@ -154,7 +155,13 @@ private UIView GetUiView<T>(UiAsset uiAsset) where T:UIView
154155
if (uiViewSource == null)
155156
return null;
156157
GameObject uiViewClone = GameObject.Instantiate(uiViewSource);
157-
uiView= (UIView)Activator.CreateInstance(typeof(T), new object[] { uiViewClone });
158+
//ILRuntime不支持带参数构造函数的生成
159+
// uiView= (UIView)Activator.CreateInstance(typeof(T), new object[] { uiViewClone });
160+
//用反射调用构造函数生成对象
161+
//根据参数类型获取构造函数
162+
ConstructorInfo ci = typeof(T).GetConstructor(new Type[]{typeof(GameObject)});
163+
object[] obj = new object[1] { uiViewClone };
164+
if (ci != null) uiView = ci.Invoke(obj) as UIView;
158165
if (uiView == null)
159166
return null;
160167
_allUiViews[uiAsset] = uiView;
18 KB
Binary file not shown.

HotFix/HotFix/bin/Debug/HotFix.dll

0 Bytes
Binary file not shown.

HotFix/HotFix/bin/Debug/HotFix.pdb

0 Bytes
Binary file not shown.
-16 KB
Binary file not shown.

HotFix/HotFix/bin/Release/HotFix.dll

-5 KB
Binary file not shown.

HotFix/HotFix/bin/Release/HotFix.pdb

45.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)