3 个版本 (重大变更)
0.5.0 | 2023年1月9日 |
---|---|
0.4.0 | 2022年12月20日 |
0.3.0 | 2022年2月27日 |
#153 在 #clap
每月下载量 656
在 3 个crate中使用(通过 bevy_console)
6KB
bevy_console
一个简单的受 Half-Life 启发的控制台,支持由 clap
驱动的参数解析。
用法
添加 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
将其添加到您的应用程序中。命令类似于 clap
命令,并通过 ConsoleCommand
derive 派生额外的 CommandName
特性。
为您的命令添加 文档注释 以在控制台中提供帮助信息。
use bevy::prelude::*;
use bevy_console::{reply, AddConsoleCommand, ConsoleCommand, ConsolePlugin};
use clap::Parser;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(ConsolePlugin)
.add_console_command::<ExampleCommand, _>(example_command);
}
/// Example command
#[derive(Parser, ConsoleCommand)]
#[command(name = "example")]
struct ExampleCommand {
/// Some message
msg: String,
}
fn example_command(mut log: ConsoleCommand<ExampleCommand>) {
if let Some(Ok(ExampleCommand { msg })) = log.take() {
// handle command
}
}
示例可以在 /examples 目录中找到。
cargo run --example log_command
wasm
应该可以在wasm中工作,但需要禁用默认功能。
依赖关系
~1.5MB
~36K SLoC