This commit is contained in:
Mikhail 2023-04-24 17:44:37 +08:00
parent c2107dff1a
commit 765373ea4b

View File

@ -3,7 +3,7 @@ using System.Reflection;
namespace DCFApixels.DragonECS namespace DCFApixels.DragonECS
{ {
public abstract class EcsJoinQueryDI<TAttachComponent> : EcsJoinAttachQuery<TAttachComponent> public abstract class EcsJoinAttachQueryDI<TAttachComponent> : EcsJoinAttachQuery<TAttachComponent>
where TAttachComponent : struct, IEcsAttachComponent where TAttachComponent : struct, IEcsAttachComponent
{ {
protected override void Init(Builder b) => EcsQueryDIHelper.Fill(this, b); protected override void Init(Builder b) => EcsQueryDIHelper.Fill(this, b);
@ -22,8 +22,6 @@ namespace DCFApixels.DragonECS
MethodInfo excludeMethod = builderType.GetMethod("Exclude", BindingFlags.Instance | BindingFlags.Public); MethodInfo excludeMethod = builderType.GetMethod("Exclude", BindingFlags.Instance | BindingFlags.Public);
MethodInfo optionalMethod = builderType.GetMethod("Optional", BindingFlags.Instance | BindingFlags.Public); MethodInfo optionalMethod = builderType.GetMethod("Optional", BindingFlags.Instance | BindingFlags.Public);
//PropertyInfo componentTypeProp = builderType.GetProperty("ComponentType", BindingFlags.Instance | BindingFlags.Public);
Type thisType = q.GetType(); Type thisType = q.GetType();
FieldInfo[] fieldInfos = thisType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); FieldInfo[] fieldInfos = thisType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
foreach (FieldInfo fieldInfo in fieldInfos) foreach (FieldInfo fieldInfo in fieldInfos)
@ -31,12 +29,9 @@ namespace DCFApixels.DragonECS
Type fieldType = fieldInfo.FieldType; Type fieldType = fieldInfo.FieldType;
if (fieldType.IsSubclassOf(typeof(EcsPoolBase)) == false) if (fieldType.IsSubclassOf(typeof(EcsPoolBase)) == false)
continue; continue;
if (fieldType.IsGenericType == false) if (fieldType.IsGenericType == false)
continue; continue;
//Type fiedlTypeDefinition = fieldType.GetGenericTypeDefinition();
//Type componentType = ((EcsPoolBase)componentTypeProp.GetValue(fieldInfo.GetValue(q))).ComponentType;
Type componentType = fieldType.GenericTypeArguments[0]; Type componentType = fieldType.GenericTypeArguments[0];
if (fieldInfo.GetCustomAttribute<IncAttribute>() != null) if (fieldInfo.GetCustomAttribute<IncAttribute>() != null)
@ -49,7 +44,11 @@ namespace DCFApixels.DragonECS
fieldInfo.SetValue(q, excludeMethod.MakeGenericMethod(componentType, fieldType).Invoke(b, null)); fieldInfo.SetValue(q, excludeMethod.MakeGenericMethod(componentType, fieldType).Invoke(b, null));
continue; continue;
} }
fieldInfo.SetValue(q, optionalMethod.MakeGenericMethod(componentType, fieldType).Invoke(b, null)); if (fieldInfo.GetCustomAttribute<OptAttribute>() != null)
{
fieldInfo.SetValue(q, optionalMethod.MakeGenericMethod(componentType, fieldType).Invoke(b, null));
continue;
}
} }
} }
} }