sschmid / Entitas

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

Add EventType.AddedOrRemoved for listeners to react to either addition or removal. #1024

Open alexandrunechita-popcore opened 1 year ago

alexandrunechita-popcore commented 1 year ago

Is your feature request related to a problem? Please describe. I want my listener to react to component Added and Removed (respectively) especially in situations where the component is empty and just behaves like a boolean.

[Game, Event(EventTarget.Self), Cleanup(CleanupMode.RemoveComponent)]
public sealed class VisibleComponent : IComponent {}
isVisible = true; //Triggers with default behavior or EventType.Added;
isVisible = false; //Triggers if set as EventType.Removed;

Describe the solution you'd like Current solution exists but is cumbersome, very hard to deduce by myself: Event(EventTarget.Self, EventType.Added, 1), Event(EventTarget.Self, EventType.Removed, 2)

Ideal solution: Event(EventTarget.Self, EventType.AddedOrRemoved) I am fine if the default remains as EventType.Added.

  public enum EventType
  {
    Added,
    Removed,
    AddedOrRemoved
  }

Describe alternatives you've considered Solution proposed is a natural upgrade, and easy for a dev to find using auto-complete of the enum.