【发布时间】:2019-12-12 13:37:39
【问题描述】:
您好,我为对象中的搜索类型创建了类型数组,如果对象具有该结构(或组件),则从对象中删除结构(或组件)。
这是我的代码的概念,但我得到错误“'结构'是一个变量但是 从行中像类型一样使用
if (entityManager.HasComponent<structure>(entity))
下面是我的脚本。
public struct ECS : IComponentData{}
...
static Type[] componentArray = new Type[] { typeof(ECS), typeof(JECS), typeof(JECS2), typeof(JECS3), typeof(JECS4) };
static void ResetComponent(Entity entity, EntityManager entityManager) {
foreach (Type structure in componentArray)
{
if (entityManager.HasComponent<structure>(entity))
{
entityManager.RemoveComponent(entity, structure);
}
}
}
在我看来,我需要将类型转换为泛型,但我不知道如何。
请找出我的问题。
【问题讨论】:
-
你不能像这样使用泛型,它们是预编译的。什么是
entityManager,什么是HasComponent? -
entityManger 是类,hascomponent 是检查实体(对象)是否具有结构组件并返回 bool 值的方法。所有这些都来自 Unity DOTS。