mirror of
https://github.com/DCFApixels/DragonECS-AutoInjections.git
synced 2025-09-18 05:04:35 +08:00
Compare commits
No commits in common. "f50021007b4de5e7ce4ec9317db58dbf568ed830" and "443a69615a4baceb650990a27d2ac6b15b0c839b" have entirely different histories.
f50021007b
...
443a69615a
@ -8,7 +8,7 @@
|
|||||||
"displayName": "DragonECS-AutoInjections",
|
"displayName": "DragonECS-AutoInjections",
|
||||||
"description": "Auto Injections for DragonECS",
|
"description": "Auto Injections for DragonECS",
|
||||||
"unity": "2020.3",
|
"unity": "2020.3",
|
||||||
"version": "0.9.18",
|
"version": "0.9.17",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/DCFApixels/DragonECS-AutoInjections.git"
|
"url": "https://github.com/DCFApixels/DragonECS-AutoInjections.git"
|
||||||
|
@ -24,19 +24,26 @@ namespace DCFApixels.DragonECS
|
|||||||
private static readonly MethodInfo _incluedMethod;
|
private static readonly MethodInfo _incluedMethod;
|
||||||
private static readonly MethodInfo _excludeMethod;
|
private static readonly MethodInfo _excludeMethod;
|
||||||
private static readonly MethodInfo _optionalMethod;
|
private static readonly MethodInfo _optionalMethod;
|
||||||
|
private static readonly MethodInfo _includeImplicitMethod;
|
||||||
|
private static readonly MethodInfo _excludeImplicitMethod;
|
||||||
private static readonly MethodInfo _combineMethod;
|
private static readonly MethodInfo _combineMethod;
|
||||||
private const BindingFlags REFL_FLAGS = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
|
|
||||||
static EcsAspectAutoHelper()
|
static EcsAspectAutoHelper()
|
||||||
{
|
{
|
||||||
|
const BindingFlags REFL_FLAGS = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
|
||||||
|
|
||||||
Type builderType = typeof(EcsAspect.Builder);
|
Type builderType = typeof(EcsAspect.Builder);
|
||||||
|
|
||||||
_incluedMethod = builderType.GetMethod("IncludePool", REFL_FLAGS);
|
_incluedMethod = builderType.GetMethod("IncludePool", REFL_FLAGS);
|
||||||
_excludeMethod = builderType.GetMethod("ExcludePool", REFL_FLAGS);
|
_excludeMethod = builderType.GetMethod("ExcludePool", REFL_FLAGS);
|
||||||
_optionalMethod = builderType.GetMethod("OptionalPool", REFL_FLAGS);
|
_optionalMethod = builderType.GetMethod("OptionalPool", REFL_FLAGS);
|
||||||
|
_includeImplicitMethod = builderType.GetMethod("IncludeImplicit", REFL_FLAGS);
|
||||||
|
_excludeImplicitMethod = builderType.GetMethod("ExcludeImplicit", REFL_FLAGS);
|
||||||
_combineMethod = builderType.GetMethod("Combine", REFL_FLAGS);
|
_combineMethod = builderType.GetMethod("Combine", REFL_FLAGS);
|
||||||
}
|
}
|
||||||
public static void FillMaskFields(object aspect, EcsMask mask)
|
public static void FillMaskFields(object aspect, EcsMask mask)
|
||||||
{
|
{
|
||||||
|
const BindingFlags REFL_FLAGS = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
|
||||||
|
|
||||||
foreach (FieldInfo fieldInfo in aspect.GetType().GetFields(REFL_FLAGS))
|
foreach (FieldInfo fieldInfo in aspect.GetType().GetFields(REFL_FLAGS))
|
||||||
{
|
{
|
||||||
if (fieldInfo.GetCustomAttribute<MaskAttribute>() == null)
|
if (fieldInfo.GetCustomAttribute<MaskAttribute>() == null)
|
||||||
@ -56,6 +63,9 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
public static void FillFields(object aspect, EcsAspect.Builder builder)
|
public static void FillFields(object aspect, EcsAspect.Builder builder)
|
||||||
{
|
{
|
||||||
|
const BindingFlags REFL_FLAGS = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
|
||||||
|
|
||||||
|
|
||||||
Type aspectType = aspect.GetType();
|
Type aspectType = aspect.GetType();
|
||||||
|
|
||||||
var implicitInjectAttributes = (IEnumerable<ImplicitInjectAttribute>)aspectType.GetCustomAttributes<ImplicitInjectAttribute>();
|
var implicitInjectAttributes = (IEnumerable<ImplicitInjectAttribute>)aspectType.GetCustomAttributes<ImplicitInjectAttribute>();
|
||||||
@ -71,47 +81,24 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
IEcsPool pool;
|
|
||||||
switch (injectAttribute)
|
switch (injectAttribute)
|
||||||
{
|
{
|
||||||
case IncAttribute incAtr:
|
case IncAttribute atr:
|
||||||
if (builder.World.TryFindPoolInstance(fieldType, out pool))
|
var x1 = _incluedMethod;
|
||||||
{
|
fieldInfo.SetValue(aspect, _incluedMethod.MakeGenericMethod(fieldType).Invoke(builder, null));
|
||||||
builder.SetMaskInclude(fieldType);
|
|
||||||
fieldInfo.SetValue(aspect, pool);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pool = (IEcsPool)_incluedMethod.MakeGenericMethod(fieldType).Invoke(builder, null);
|
|
||||||
}
|
|
||||||
fieldInfo.SetValue(aspect, pool);
|
|
||||||
break;
|
break;
|
||||||
case ExcAttribute extAtr:
|
case ExcAttribute atr:
|
||||||
if (builder.World.TryFindPoolInstance(fieldType, out pool))
|
var x2 = _excludeMethod;
|
||||||
{
|
fieldInfo.SetValue(aspect, _excludeMethod.MakeGenericMethod(fieldType).Invoke(builder, null));
|
||||||
builder.SetMaskExclude(fieldType);
|
|
||||||
fieldInfo.SetValue(aspect, pool);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pool = (IEcsPool)_excludeMethod.MakeGenericMethod(fieldType).Invoke(builder, null);
|
|
||||||
}
|
|
||||||
fieldInfo.SetValue(aspect, pool);
|
|
||||||
break;
|
break;
|
||||||
case OptAttribute optAtr:
|
case OptAttribute atr:
|
||||||
if (builder.World.TryFindPoolInstance(fieldType, out pool))
|
var x3 = _optionalMethod;
|
||||||
{
|
fieldInfo.SetValue(aspect, _optionalMethod.MakeGenericMethod(fieldType).Invoke(builder, null));
|
||||||
fieldInfo.SetValue(aspect, pool);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pool = (IEcsPool)_optionalMethod.MakeGenericMethod(fieldType).Invoke(builder, null);
|
|
||||||
}
|
|
||||||
fieldInfo.SetValue(aspect, pool);
|
|
||||||
break;
|
break;
|
||||||
case CombineAttribute combineAtr:
|
case CombineAttribute atr:
|
||||||
pool = builder.World.FindPoolInstance(fieldType);
|
var x4 = _combineMethod;
|
||||||
fieldInfo.SetValue(aspect, _combineMethod.MakeGenericMethod(fieldType).Invoke(builder, new object[] { combineAtr.Order }));
|
fieldInfo.SetValue(aspect, _combineMethod.MakeGenericMethod(fieldType).Invoke(builder, new object[] { atr.Order }));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -119,16 +106,27 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Inject(ImplicitInjectAttribute atr_, MethodInfo method_, MethodInfo implicitMethod_)
|
||||||
|
{
|
||||||
|
if (atr_.IsPool)
|
||||||
|
{
|
||||||
|
method_.MakeGenericMethod(atr_.Type).Invoke(builder, null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
implicitMethod_.Invoke(builder, new object[] { atr_.Type });
|
||||||
|
}
|
||||||
|
}
|
||||||
foreach (var attribute in implicitInjectAttributes)
|
foreach (var attribute in implicitInjectAttributes)
|
||||||
{
|
{
|
||||||
if (attribute is IncImplicitAttribute incImplicitAtr)
|
if (attribute is IncImplicitAttribute incImplicit)
|
||||||
{
|
{
|
||||||
builder.SetMaskInclude(incImplicitAtr.ComponentType);
|
Inject(incImplicit, _incluedMethod, _includeImplicitMethod);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (attribute is ExcImplicitAttribute excImplicitAtr)
|
if (attribute is ExcImplicitAttribute excImplicit)
|
||||||
{
|
{
|
||||||
builder.SetMaskExclude(excImplicitAtr.ComponentType);
|
Inject(excImplicit, _excludeMethod, _excludeImplicitMethod);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,10 +26,12 @@ namespace DCFApixels.DragonECS
|
|||||||
|
|
||||||
public abstract class ImplicitInjectAttribute : Attribute
|
public abstract class ImplicitInjectAttribute : Attribute
|
||||||
{
|
{
|
||||||
public readonly Type ComponentType;
|
public readonly Type Type;
|
||||||
public ImplicitInjectAttribute(Type componentType)
|
public readonly bool IsPool;
|
||||||
|
public ImplicitInjectAttribute(Type type)
|
||||||
{
|
{
|
||||||
ComponentType = componentType;
|
Type = type;
|
||||||
|
IsPool = type.GetInterfaces().Any(o => o == typeof(IEcsPoolImplementation));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Class, Inherited = false, AllowMultiple = true)]
|
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Class, Inherited = false, AllowMultiple = true)]
|
||||||
|
@ -101,7 +101,10 @@ namespace DCFApixels.DragonECS
|
|||||||
private Type[] _relatedTypesBuffer;
|
private Type[] _relatedTypesBuffer;
|
||||||
public void Inject(Type fieldType, object obj)
|
public void Inject(Type fieldType, object obj)
|
||||||
{
|
{
|
||||||
|
if (_isPreInitInjectionComplete == false)
|
||||||
|
{
|
||||||
|
_notInjected.Remove(fieldType);
|
||||||
|
}
|
||||||
if (_relatedTypesBuffer == null || _relatedTypesBuffer.Length < _injectedTypeToPropertiesMap.Count)
|
if (_relatedTypesBuffer == null || _relatedTypesBuffer.Length < _injectedTypeToPropertiesMap.Count)
|
||||||
{
|
{
|
||||||
_relatedTypesBuffer = new Type[_injectedTypeToPropertiesMap.Count];
|
_relatedTypesBuffer = new Type[_injectedTypeToPropertiesMap.Count];
|
||||||
@ -129,10 +132,6 @@ namespace DCFApixels.DragonECS
|
|||||||
string propertyName = item.Attribute.NamedInjection;
|
string propertyName = item.Attribute.NamedInjection;
|
||||||
if (string.IsNullOrEmpty(propertyName) || propertyName == name)
|
if (string.IsNullOrEmpty(propertyName) || propertyName == name)
|
||||||
{
|
{
|
||||||
if (_isPreInitInjectionComplete == false)
|
|
||||||
{
|
|
||||||
_notInjected.Remove(item.property.PropertyType);
|
|
||||||
}
|
|
||||||
item.property.Inject(item.target, obj);
|
item.property.Inject(item.target, obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user