protected virtual void OnComponentChanged(Entity entity, int index, EntityComponent previousComponent, EntityComponent newComponent) { ComponentChanged?.Invoke(this, new EntityComponentEventArgs(entity, index, previousComponent, newComponent)); }
internal void NotifyComponentChanged(Entity entity, int index, EntityComponent oldComponent, EntityComponent newComponent) { // No real update if (oldComponent == newComponent) { return; } // If we have a new component we can try to collect processors for it if (newComponent != null) { CollectNewProcessorsByComponentType(newComponent.GetType().GetTypeInfo()); RegisterPendingProcessors(); } // Remove previous component from processors currentDependentProcessors.Clear(); if (oldComponent != null) { CheckEntityComponentWithProcessors(entity, oldComponent, true, currentDependentProcessors); } // Add new component to processors if (newComponent != null) { CheckEntityComponentWithProcessors(entity, newComponent, false, currentDependentProcessors); } // Update all dependencies if (currentDependentProcessors.Count > 0) { UpdateDependentProcessors(entity, oldComponent, newComponent); currentDependentProcessors.Clear(); } // Notify component changes OnComponentChanged(entity, index, oldComponent, newComponent); }
private void UpdateDependentProcessors(Entity entity, EntityComponent skipComponent1, EntityComponent skipComponent2) { var components = entity.Components; for (int i = 0; i < components.Count; i++) { var component = components[i]; if (component == skipComponent1 || component == skipComponent2) { continue; } var componentType = component.GetType().GetTypeInfo(); var processorsForComponent = MapComponentTypeToProcessors[componentType]; { for (int j = 0; j < processorsForComponent.Count; j++) { var processor = processorsForComponent[j]; if (currentDependentProcessors.Contains(processor)) { processor.ProcessEntityComponent(entity, component, false); } } } } }
/// <summary> /// Checks if <see cref="Entity"/> needs to be either added or removed. /// </summary> /// <param name="entity">The entity.</param> /// <param name="entityComponent"></param> /// <param name="forceRemove"></param> protected internal abstract void ProcessEntityComponent(Entity entity, EntityComponent entityComponent, bool forceRemove);