private void OnComponentAdded(int entityId, object component) { ComponentAddedDelegate <object> handler = this.ComponentAdded; if (handler != null) { handler(entityId, component); } }
/// <summary> /// Registers listeners to track adding/removing of components of specified component type. /// </summary> /// <param name="componentType">Type of component to track.</param> /// <param name="onComponentAdded">Callback when a new component of the type was added.</param> /// <param name="onComponentRemoved">Callback when a component of the type was removed.</param> public void RegisterComponentListeners( Type componentType, ComponentAddedDelegate <object> onComponentAdded, ComponentRemovedDelegate <object> onComponentRemoved) { ComponentManager componentManager = this.GetComponentManager(componentType, true); componentManager.ComponentAdded += onComponentAdded; componentManager.ComponentRemoved += onComponentRemoved; }
/// <summary> /// Registers listeners to track adding/removing of components of type T. /// </summary> /// <typeparam name="T">Type of component to track.</typeparam> /// <param name="onComponentAdded">Callback when a new component of the type was added.</param> /// <param name="onComponentRemoved">Callback when a component of the type was removed.</param> public void RegisterComponentListeners <T>( ComponentAddedDelegate <T> onComponentAdded, ComponentRemovedDelegate <T> onComponentRemoved) { Type componentType = typeof(T); this.RegisterComponentListeners( componentType, (entityId, component) => onComponentAdded(entityId, (T)component), (entityId, component) => onComponentRemoved(entityId, (T)component)); }