![]() |
Magical Box
1.15
Modular Particle Engine for Unity3D
|
Magical Box provides several useful events you can hook into for advanced control, e.g. you may want to play a fireworks emitter once a rocket particle dies.
On any event you receive a MBEvent parameter providing you detail information. MBEvent.Type provides information about the type of event (useful if you want to have a single event handler for multiple events), MBEvent.Source and MBEvent.Context provide information about the raising object and the details (usually a specific particle) and MBEvent.Data provides space for additional data, e.g. the DeathReason. For your convenience MBEvent.Particle returns the context as a MBParticle.
See the table below...
| Class | Event | Description | Context | Data |
|---|---|---|---|---|
| MBEmitter | ParticleBirth | Raised after a particle is born | the particle | null |
| MBEmitter | ParticleDeath | Raised after a particle died | the particle | a MBDeathReason |
| MBEmitter | EmitterStopsPlaying | Raised when the emitter stops playing | the emitter | null |
| MBParticleCollider | ParticleCollides | Raised when a particle collides | the particle | the parameter |
| MBParticleZoneBase | ParticleInsideZone | Raised when a particle is inside a zone | the particle | the parameter |
Magical Box provides two different ways you can use it's events:
Create a event handler method that takes a MBEvent as parameter:
void DoSomethingOnEvent(MBEvent e) { }
You need to register your event handler in order to catch the event, e.g. in OnEnable():
void OnEnable() { MBEmitter em = GetComponent<MBEmitter>(); em.ParticleDeath += new MBEventHandler(DoSomethingOnEvent); }
You should unregister your event handler when you don't need events anymore, e.g. in OnDisable():
void OnDisable() { MBEmitter em = GetComponent<MBEmitter>(); em.ParticleDeath -= new MBEventHandler(DoSomethingOnEvent); }
In a MonoBehaviour script that is attached to a GameObject, create a event handler method that takes a MBEvent as parameter:
void DoSomethingOnEvent(MBEvent e) { }
In the Magical Box editor assign the GameObject holding the above script to the appropriate event and set the name of the handler method and you're done.