~starkingdoms/starkingdoms

ref: 4296e758d0675fd1b18c389ead495cf22eb8a763 starkingdoms/crates/unified/src/client/incoming_particles.rs -rw-r--r-- 1.1 KiB
4296e758 — core feat(particles): enoki particles (tmp) 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use bevy::prelude::*;
use bevy_enoki::{ParticleEffectHandle, ParticleSpawner};
use bevy_enoki::prelude::ParticleSpawnerState;
use crate::ecs::Particles;

pub fn replicated_particles_plugin(app: &mut App) {
    app.add_systems(PreUpdate, (replicate_new_particles, replicate_updated_particles));
}

fn replicate_new_particles(q: Query<(Entity, &Particles), Added<Particles>>, assets: Res<AssetServer>, mut commands: Commands) {
    for (entity, p) in q.iter() {
        commands.entity(entity)
            .insert(ParticleSpawner::default())
            .insert(ParticleEffectHandle(assets.load(&p.effect)))
            .insert(ParticleSpawnerState {
                active: p.active,
                ..default()
            });
        info!("replicate_new_particles {:?}", p);
    }
}
fn replicate_updated_particles(mut q: Query<(Entity, &mut ParticleEffectHandle, &mut ParticleSpawnerState, &Particles), Changed<Particles>>, assets: Res<AssetServer>, mut commands: Commands ) {
    for (_entity, mut handle, mut state, p) in q.iter_mut() {
        *handle = ParticleEffectHandle(assets.load(&p.effect));
        state.active = p.active;
    }
}