sschmid / Entitas

Entitas is a super fast Entity Component System (ECS) Framework specifically made for C# and Unity
MIT License
7.18k stars 1.11k forks source link

A component with multiple contexts +events, only make event listeners for 1 context #1071

Open Discipol opened 1 year ago

Discipol commented 1 year ago

The problem is that the interfaces for listeners need to mention the type of the entity/context, and if you have two contexts, you would basically create the same class twice(or more), but each copy would have a different SOMETHINGEntity

Example"

[App, Game] //Two contexts [Event(EventType.Any)] public sealed CheeseComponent : IComponent {}

Proposition 1: If more than 1 context, create them as IAnyAppCheeseAddedListener + IAnyGameCheeseAddedListener Autocomplete will make it very easy to adapt. You could also make this change for 1 context, to put that context name in there always.

Proposition 2: IAnyCheeseAddedListener< T > where T : Entity We can't limit it to AppEntity / GameEntity as far as I know as "where T" does not allow A-or-B. The method that implements the interface would use T