我正在学习 Rust 和 Bevy 引擎,我想Font
在整个应用程序生命周期内保持某些资产(例如 s)的加载。
// Resource for fonts:
#[derive(Default, Clone)]
pub struct ResFont {
pub ui: Handle<Font>, // The font that will be used in this example.
pub dialog: Handle<Font>,
...
}
// Insert resource in main() during App building:
{
.insert_resource(ResFont::default())
}
// Load resource during startup:
pub fn startup(asset_server: Res<AssetServer>, mut res_font: ResMut<ResFont>)
{
res_font.ui = asset_server.load("font/Default.ttf");
}
// Use the font resource in a different place:
pub fn setup_ui(res_font: ResMut<ResFont>)
{
...
TextStyle {
font: res_font.ui.clone(),
font_size: 12.0,
color: Color::WHITE,
}
...
}
在底部的函数setup_ui()
中,我.clone()
用来复制该资产。如果我不使用.clone()
,我会收到错误消息:
cannot move out of dereference of `bevy::prelude::ResMut<'_, resource::text::ResFont>`
move occurs because value has type `bevy::prelude::Handle<bevy::prelude::Font>`, which does not implement the `Copy` traitrustc(E0507)
ui.rs(19, 27): move occurs because value has type `bevy::prelude::Handle<bevy::prelude::Font>`, which does not implement the `Copy` trait
我有两个问题:
我是
Font
在操作过程中复制整个这里.clone()
吗?这是保持资源加载并供以后使用的“正确”方法,还是有更好的方法来实现这一点,我不知道?