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); } }
public virtual void RemoveSystem(ComponentSystem system) { _startSystemList.Remove(system); _updateSystemList.Remove(system); _fixedUpdateSystemList.Remove(system); IComponentSystemSetup systemSetup = system; systemSetup.RemoveAllGroups(); }
public virtual void AddSystem(ComponentSystem componentSystem) { Type componentSystemType = componentSystem.GetType(); if (componentSystemType.GetMethod("OnStart").DeclaringType == componentSystemType) { _startSystemList.Add(componentSystem); } if (componentSystemType.GetMethod("OnUpdate").DeclaringType == componentSystemType) { _updateSystemList.Add(componentSystem); } if (componentSystemType.GetMethod("OnFixedUpdate").DeclaringType == componentSystemType) { _fixedUpdateSystemList.Add(componentSystem); } InjectionManager.ResolveDependency(componentSystem); HandleTupleInjection(componentSystem); }
public void AddSystem(ComponentSystem instance) { bool allowInstanceTypeSearch = true; Type instanceType = instance.GetType(); while (allowInstanceTypeSearch) { if (instanceType == typeof(ComponentSystem)) { break; } foreach (object attribute in instanceType.GetCustomAttributes(false)) { if (attribute is AllowMultipleAttribute) { allowInstanceTypeSearch = false; break; } } if (typeof(EntitySystem) .GetMethod("GetSystem") .MakeGenericMethod(instanceType) .Invoke(this, null) != null) { UnityEngine.Debug.LogError(string.Format( "OverallEntitySystem--AddSystem--Cannot have two instances of a ComponentSystem--{1}", instance.GetType().ToString())); return; } instanceType = instanceType.BaseType; } this.systems.Add(instance); this.ResetSystemCaches(); }
public void AddSystem(ComponentSystem componentSystem) { _systemRoot.AddSystem(componentSystem); }
public virtual void AddEntity(Entity instance) { if (instance == null) { Debug.LogError("OverallEntitySystem--AddEntity should not be passed a null value"); return; } if (this.GetEntity(instance.name) != null) { UnityEngine.Debug.LogError("StatComponentSystem -- You cannot add 2 statistics of the same name -- A statistic of name " + instance.name + " already exists in this System"); return; } instance.OnComponentsChanged += this.ResetCaches; this.entities.Add(instance); this.ResetCaches(); foreach (Component component in instance.GetComponents <Component>()) { foreach (object attribute in component.GetType().GetCustomAttributes(true)) { if (attribute is PartOfComponentSystemAttribute) { PartOfComponentSystemAttribute pocsa = (PartOfComponentSystemAttribute)attribute; bool isGlobalSystem = false; foreach (object parentSystemAttribute in pocsa.parentSystemType.GetCustomAttributes(true)) { if (parentSystemAttribute is GlobalComponentSystemAttribute) { isGlobalSystem = true; } } if (isGlobalSystem) { continue; } ComponentSystem system = (ComponentSystem)typeof(EntitySystem) .GetMethod("GetSystem") .MakeGenericMethod(pocsa.parentSystemType) .Invoke(this, null); if (system == null) { system = (ComponentSystem)pocsa.parentSystemType.GetConstructor(new Type[] { }).Invoke(null, null); this.AddSystem(system); } system.AddComponent(component); } } } instance.SetOverallSystem(this); }