public static void Add_OnSelf <TScope, TComp>(this Entity <TScope> entity, IOnSelf <TScope, TComp> listener) where TScope : IScope where TComp : Scope <TScope>, IComponent, IEvent_Self <TScope, TComp> { var index = Lookup <TScope, Event_SelfComponent <TScope, TComp> > .Id; Event_SelfComponent <TScope, TComp> component; if (entity.HasComponent(index)) { component = (Event_SelfComponent <TScope, TComp>)entity.GetComponent(index); } else { component = entity.CreateComponent <Event_SelfComponent <TScope, TComp> >(index); entity.AddComponent(index, component); component.Listeners.Clear(); } component.Listeners.Add(listener); }
public static void Remove_OnSelf <TScope, TComp>(this Entity <TScope> entity, IOnSelf <TScope, TComp> listener) where TScope : IScope where TComp : Scope <TScope>, IComponent, IEvent_Self <TScope, TComp> { var index = Lookup <TScope, Event_SelfComponent <TScope, TComp> > .Id; var component = (Event_SelfComponent <TScope, TComp>)entity.GetComponent(index); component.Listeners.Remove(listener); }