Exemplo n.º 1
0
        protected void HandleTupleInjection(ComponentSystem system)
        {
            Type systemType = system.GetType();

            Type injectTupleAttributeType = typeof(InjectTupleAttribute);
            Type iComponentArrayType      = typeof(ComponentArray);

            FieldInfo[] allFields = systemType.GetFieldsRecursive(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public).ToArray();
            IGrouping <int, FieldInfo>[] injectionTypeGroups = systemType.GetFieldsRecursive(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public)
                                                               .Where(field => field.GetCustomAttributes(injectTupleAttributeType, false).Any())
                                                               .Where(field => iComponentArrayType.IsAssignableFrom(field.FieldType))
                                                               .GroupBy(field => (field.GetCustomAttributes(injectTupleAttributeType, false).First() as InjectTupleAttribute).GroupId)
                                                               .ToArray();


            foreach (IGrouping <int, FieldInfo> injectionTypeGroup in injectionTypeGroups)
            {
                FieldInfo[] injectionTypeFields     = injectionTypeGroup.ToArray();
                Type[]      injectionComponentTypes = injectionTypeGroup
                                                      .Select(field => field.FieldType.GetGenericArguments()[0])
                                                      .ToArray();

                ComponentGroup group = _entityManager.GetComponentGroup(injectionComponentTypes);

                for (int i = 0; i < injectionComponentTypes.Length; i++)
                {
                    ComponentArray componentArray = group.GetComponent(injectionComponentTypes[i]);
                    injectionTypeFields[i].SetValue(system, componentArray);
                }

                IComponentSystemSetup systemSetup = system;
                systemSetup.AddGroup(group);
            }
        }
Exemplo n.º 2
0
        public virtual void RemoveSystem(ComponentSystem system)
        {
            _startSystemList.Remove(system);
            _updateSystemList.Remove(system);
            _fixedUpdateSystemList.Remove(system);

            IComponentSystemSetup systemSetup = system;

            systemSetup.RemoveAllGroups();
        }