private static void InjectFields(ComponentSystemBase componentSystem, World world, EntityManager entityManager, out InjectComponentGroupData[] outInjectGroups, out InjectFromEntityData outInjectFromEntityData) { List <InjectComponentGroupData> list = new List <InjectComponentGroupData>(); List <InjectionData> componentDataFromEntity = new List <InjectionData>(); List <InjectionData> bufferFromEntity = new List <InjectionData>(); foreach (FieldInfo info in componentSystem.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance)) { object[] customAttributes = info.GetCustomAttributes(typeof(InjectAttribute), true); if (customAttributes.Length != 0) { if (info.FieldType.IsClass) { InjectConstructorDependencies(componentSystem, world, info); } else if (InjectFromEntityData.SupportsInjections(info)) { InjectFromEntityData.CreateInjection(info, entityManager, componentDataFromEntity, bufferFromEntity); } else { list.Add(InjectComponentGroupData.CreateInjection(info.FieldType, info, componentSystem)); } } } outInjectGroups = list.ToArray(); outInjectFromEntityData = new InjectFromEntityData(componentDataFromEntity.ToArray(), bufferFromEntity.ToArray()); }
public static void Inject(ComponentSystemBase componentSystem, World world, EntityManager entityManager, out InjectComponentGroupData[] outInjectGroups, out InjectFromEntityData outInjectFromEntityData) { var componentSystemType = componentSystem.GetType(); ValidateNoStaticInjectDependencies(componentSystemType); InjectFields(componentSystem, world, entityManager, out outInjectGroups, out outInjectFromEntityData); }
public static void Inject(ComponentSystemBase componentSystem, World world, EntityManager entityManager, out InjectComponentGroupData[] outInjectGroups, out InjectFromEntityData outInjectFromEntityData) { var componentSystemType = componentSystem.GetType(); ValidateNoStaticInjectDependencies(componentSystemType); var fields = componentSystemType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); var injectGroups = new List <InjectComponentGroupData>(); var injectFromEntity = new List <InjectionData>(); var injectFromFixedArray = new List <InjectionData>(); foreach (var field in fields) { var attr = field.GetCustomAttributes(typeof(InjectAttribute), true); if (attr.Length == 0) { continue; } if (field.FieldType.IsClass) { InjectConstructorDependencies(componentSystem, world, field); } else { if (InjectFromEntityData.SupportsInjections(field)) { InjectFromEntityData.CreateInjection(field, entityManager, injectFromEntity, injectFromFixedArray); } else { injectGroups.Add( InjectComponentGroupData.CreateInjection(field.FieldType, field, componentSystem)); } } } outInjectGroups = injectGroups.ToArray(); outInjectFromEntityData = new InjectFromEntityData(injectFromEntity.ToArray(), injectFromFixedArray.ToArray()); }