feat: IComponent can access EntityComponent properties
PR Details
Like the Entity Entity { get; } already in Stride.BepuPhysics.Components.ISimulationUpdate
Allow flexible processing Processor to visit public properties of EntityComponent like EntityProcessor<TComponent, TData>
It's common to get data from other components of the same entity in game dev, e.g.
Health, MoveSpeed are properties of reusable component Unit, another reusable component UnitMove need to get MoveSpeed from Unit. Also, there could be an EffectContainer contains effects may change speed like Frozen or SpeedUp that UnitMove need to get.
in EntityProcessor, it can do such things through EntityComponent.Entity.Get<T>() while traversing ComponentDatas.Values, but it's not a default feature for IComponent and IProcessor of flexible processing.
So I add getter to IComponent and remove the Entity Entity { get; } in ISimulationUpdate since it's the only one built-in component inherits IComponent.
Related Issue
none
Types of changes
- [ ] Docs change / refactoring / dependency upgrade
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
Checklist
- [ ] My change requires a change to the documentation.
- [ ] I have added tests to cover my changes.
- [x] All new and existing tests passed.
- [x] I have built and run the editor to try this change out.
Do we want all implementations of IComponent to have an Entity? If not (for more flexibility or other reasons), then it cannot be promoted to the base interface. Just because the current implementation has it doesn't mean all (including future one) will.
Pinging @Eideren since they worked on that "flexible processing" part (cf #2331).
I don't understand what this PR tries to achieve - the interface as is is not supposed to be consumed by anything besides the internals of stride - the processor of a given IComponent should process the interface as its derived type, not the generic IComponent type.
Could you show us a concrete example were this would be useful ?
Converting this to draft while the contributor gets back to us