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 在 游戏开发 中
每月下载 136 次
19KB
329 行
Turbo Atlas Icons
一个用于 Bevy 的包,可以帮助您更轻松地从图集渲染 UI 图标。
只需将 UiIconComponent 添加到您的 Ui 节点(AtlasImageBundle),将其源设置为预注册的源,它就会工作!
- 安装插件
app.insert_plugins( TurboAtlasIconsPlugin )
- 注册图标源类型(将源类型映射到如何访问纹理图集数据)
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
}
}
- 将图标源类型信息作为组件附加到 AtlasImageBundle 节点
commands.entity(icon_node).insert(
UiIconComponent{
icon_source : Some(Box::new( GuiPixelIconSource("heart_full.tga".into() ) )
}
);
- 您的图标将渲染!
(这假设 TextureAtlasCombined 已加载到内存中,用于 IconSource 查找 --- 请参阅 sample/texture_atlas_assets 中的示例,说明如何实现此操作 -- 例如使用 bevy_asset_loader)
依赖项
~41–78MB
~1.5M SLoC