use bevy::prelude::*; use common::prelude::*; pub fn plugin(app: &mut App) { app.add_observer(insert_block_visuals); app.load_resource::(); } #[derive(Resource, Asset, Reflect, Clone)] #[reflect(Resource)] pub struct BlockAssets { #[dependency] mesh: Handle, #[dependency] material: Handle, } impl FromWorld for BlockAssets { fn from_world(world: &mut World) -> Self { let assets = world.resource::(); Self { mesh: assets.add(Cuboid::new(1.0, 1.0, 1.0).into()), material: assets.add(Color::srgb_u8(124, 144, 255).into()), } } } /// Observer which automatically inserts block visuals (mesh and /// material) when an entity has the `Block` component added to it. fn insert_block_visuals( add: On, mut commands: Commands, block_assets: Res, ) { commands.entity(add.entity).insert(( Mesh3d(block_assets.mesh.clone()), MeshMaterial3d(block_assets.material.clone()), )); }