From fdc61ca408a1d40f69c299c8789ecff4e369ff74 Mon Sep 17 00:00:00 2001 From: Mike Hsu Date: Sun, 3 Mar 2024 22:53:09 -0800 Subject: [PATCH] cleanup associate type example a bit more --- examples/ecs/generic_system.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/examples/ecs/generic_system.rs b/examples/ecs/generic_system.rs index 783b8d57d9..8b3aa8742a 100644 --- a/examples/ecs/generic_system.rs +++ b/examples/ecs/generic_system.rs @@ -174,12 +174,16 @@ mod system_with_generic_system_param { } } -// TODO: change this to use assets? // You may want to be have the SystemParam be specified in an associated type. mod system_param_in_associated_type { use super::*; use bevy::ecs::system::{lifetimeless::SRes, StaticSystemParam, SystemParam, SystemParamItem}; + #[derive(Resource)] + pub struct ResourceA { + pub data: u32, + } + #[derive(Resource)] pub struct ResourceC { pub data: u32, @@ -202,10 +206,22 @@ mod system_param_in_associated_type { } } + #[derive(Resource)] + pub struct ItemB; + impl MyTrait for ItemB { + // we can specify any system param here, including a combination of other system params + type Param = (SRes, SRes); + + fn do_something(&self, param: &mut SystemParamItem) -> u32 { + // todo: Make this more intelligible + param.0.data + param.1.data + } + } + pub fn system( mut param: StaticSystemParam<::Param>, - asset: ResMut, + item: ResMut, ) { - asset.do_something(&mut param); + item.do_something(&mut param); } }