2个不稳定版本
0.4.0 | 2022年12月20日 |
---|---|
0.3.0 | 2022年2月27日 |
#1366 in 游戏开发
每月下载次数 25
18KB
299 代码行
bevy_console
一个简单的半衰期风格的控制台,支持参数解析。
用法
添加ConsolePlugin
,可选地添加资源ConsoleConfiguration
。
use bevy::prelude::*;
use bevy_console::{ConsoleConfiguration, ConsolePlugin};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(ConsolePlugin)
.insert_resource(ConsoleConfiguration {
// override config here
..Default::default()
});
}
创建控制台命令结构和系统,并通过.add_console_command
将其添加到您的应用程序中。
为您的命令添加文档注释,以在控制台中提供帮助信息。
use bevy::prelude::*;
use bevy_console::{reply, AddConsoleCommand, ConsoleCommand, ConsolePlugin};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(ConsolePlugin)
.add_console_command::<ExampleCommand, _>(example_command);
}
/// Example command
#[derive(ConsoleCommand)]
#[console_command(name = "example")]
struct ExampleCommand {
/// Some message
msg: String,
}
fn example_command(mut log: ConsoleCommand<ExampleCommand>) {
if let Some(ExampleCommand { msg }) = log.take() {
// handle command
}
}
示例可以在/examples目录中找到。
cargo run --example log_command
wasm
应该能在wasm中工作,但需要禁用默认功能。
依赖项
~2.5MB
~47K SLoC