我需要在运行时生成一个基于反射的快速方法。因此,我研究了动态方法。问题是我的知识有限。
这就是我需要使用动态方法调用的方法。
pattern = r"^[\d]{2}.*,[\d]{3}$"
data = re.findall(pattern, text)
for s in data:
print(s)
我坚持将实体和组件传递给方法的部分。 我只是找不到任何关于我们如何做到这一点的例子。
public struct EntityManager{
public void SetComponent<T>(Entity e, T component) where T : struct, IComponentData{
// Simplified
}
}
// The component to pass in it
public struct ComponentExample : IComponentData{}
我们究竟如何“发出”一个结构(实体)和一个对象到 DynamicMethod 中来执行它? 很高兴为您提供有关此主题的任何帮助!
答案 0 :(得分:0)
它必须是动态的,还是反射就足够了?
typeof(EntityManager)
.GetMethod(nameof(EntityManager.SetComponent))
.MakeGenericMethod(typeof(ComponentExample))
.Invoke(entityManager, new object[] { component });