Beispiel #1
0
        public static void Remove_OnAnyRemoved <TScope, TComp>(this Entity <TScope> entity, IOnAnyRemoved <TScope, TComp> listener)
            where TScope : IScope
            where TComp : Scope <TScope>, IComponent, IEvent_AnyRemoved <TScope, TComp>
        {
            var index     = Lookup <TScope, Event_AnyRemovedComponent <TScope, TComp> > .Id;
            var component = (Event_AnyRemovedComponent <TScope, TComp>)entity.GetComponent(index);

            component.Listeners.Remove(listener);
        }
Beispiel #2
0
        public static void Add_OnAnyRemoved <TScope, TComp>(this Entity <TScope> entity, IOnAnyRemoved <TScope, TComp> listener)
            where TScope : IScope
            where TComp : Scope <TScope>, IComponent, IEvent_AnyRemoved <TScope, TComp>
        {
            var index = Lookup <TScope, Event_AnyRemovedComponent <TScope, TComp> > .Id;

            Event_AnyRemovedComponent <TScope, TComp> component;

            if (entity.HasComponent(index))
            {
                component = (Event_AnyRemovedComponent <TScope, TComp>)entity.GetComponent(index);
            }
            else
            {
                component = entity.CreateComponent <Event_AnyRemovedComponent <TScope, TComp> >(index);
                entity.AddComponent(index, component);
                component.Listeners.Clear();
            }

            component.Listeners.Add(listener);
        }