This example is running in WebGL2 and should work in most browsers. You can check the WebGPU examples here.
observer_propagation.rs:
//! Demonstrates how to propagate events through the hierarchy with observers.
use Duration;
use ;
use ;
// In this example, we spawn a goblin wearing different pieces of armor. Each piece of armor
// is represented as a child entity, with an `Armor` component.
//
// We're going to model how attack damage can be partially blocked by the goblin's armor using
// event bubbling. Our events will target the armor, and if the armor isn't strong enough to block
// the attack it will continue up and hit the goblin.
// This event represents an attack we want to "bubble" up from the armor to the goblin.
// We enable propagation by implementing `Event` manually (rather than using a derive) and specifying
// two important pieces of information:
/// An entity that can take damage.
;
/// For damage to reach the wearer, it must exceed the armor.
;
/// A normal bevy system that attacks a piece of the goblin's armor on a timer.
/// A callback placed on [`Armor`], checking if it absorbed all the [`Attack`] damage.
/// A callback on the armor wearer, triggered when a piece of armor is not able to block an attack,
/// or the wearer is attacked directly.