#icons #texture-atlas #bevy-ui #declarative-ui #source #rendering #bevy-plugin

turbo_atlas_icons

使用 Bevy 实现声明式 UI 图标渲染的系统

5 个版本 (3 个破坏性更新)

0.14.1 2024年7月16日
0.13.1 2024年6月5日
0.13.0 2024年6月5日
0.2.0 2024年6月1日
0.1.0 2024年5月23日

#733游戏开发

Download history 83/week @ 2024-05-21 211/week @ 2024-05-28 279/week @ 2024-06-04 2/week @ 2024-06-11 133/week @ 2024-07-16 3/week @ 2024-07-23

每月下载 136

MIT 许可证

19KB
329

Turbo Atlas Icons

一个用于 Bevy 的包,可以帮助您更轻松地从图集渲染 UI 图标。

只需将 UiIconComponent 添加到您的 Ui 节点(AtlasImageBundle),将其源设置为预注册的源,它就会工作!

  1. 安装插件


 app.insert_plugins( TurboAtlasIconsPlugin )


  1. 注册图标源类型(将源类型映射到如何访问纹理图集数据)



pub struct GuiPixelIconSource(String) ;   // This is your own source type that you invent !!  Can invent many. 

impl UiIconSource for GuiPixelIconSource {

	//describe how to get the Icon Handle Name 

    fn get_icon_name(&self, _world: &World) -> Option<String> {
        Some(self.0.clone())
    }

    //describe how to get the HashMap< IconHandleName -> ImageHandle  for this source 
   
   fn get_icons_handles_map<'a>(&'a self, world: &'a World) -> &'a TextureHandlesMap{
    	let images = world.resource::<TextureAssets>();
        &images.gui_pixel_icons
    }


    //describe how to get the texture atlas layout and overall image handle for this source 

    fn get_texture_atlas<'a>(&'a self, world: &'a World) ->  &'a Option<TextureAtlasCombined> {
        let texture_atlas_assets = world.resource::<TextureAtlasAssets>(); 

		&texture_atlas_assets.gui_pixel_icons_atlas
    }

      
}




  1. 将图标源类型信息作为组件附加到 AtlasImageBundle 节点

   commands.entity(icon_node).insert(  
 		UiIconComponent{
 			icon_source : Some(Box::new( GuiPixelIconSource("heart_full.tga".into() ) ) 

 		}
   	); 


  1. 您的图标将渲染!

(这假设 TextureAtlasCombined 已加载到内存中,用于 IconSource 查找 --- 请参阅 sample/texture_atlas_assets 中的示例,说明如何实现此操作 -- 例如使用 bevy_asset_loader)

image

依赖项

~41–78MB
~1.5M SLoC