/// <summary> /// A generic add component /// </summary> private void AddComponentGeneric(Entity entity, IComponentData component) { MethodInfo methodInfo = typeof(EntityManager).GetMethod("AddComponentData"); MethodInfo genericMethodInfo = methodInfo.MakeGenericMethod(component.GetType()); var parameters = new object[] { entity, component }; object componentData = genericMethodInfo.Invoke(this.entityManager, parameters); }
public void BindComponentTo(Entity entity, IComponentData componentData, bool isAttach = true) { var componentType = componentData.GetType(); var processing = entitySystemsController.SystemInfos.Values.Where(e => e.NeededComponents.Any(x => x.TypeComponent.GetElementType() == componentType)); foreach (var processingInfo in processing) { if (processingInfo.NeededComponents.All(e => EntityContainer.HasComponent(entity, e.TypeComponent.GetElementType()))) { processingInfo.AttachedEntity.Add(entity); if (isAttach) { AttachComponents(processingInfo, processingInfo.AttachedEntity); } } } }
public void AddComponent(Entity entity, IComponentData componentData) { ComponentsContainer[entity].Add(componentData.GetType(), componentData); }