19个版本 (10个重大更改)
| 0.11.1 | 2024年3月1日 |
|---|---|
| 0.9.0 | 2023年11月4日 |
| 0.8.0 | 2023年7月14日 |
| 0.7.0 | 2023年3月18日 |
| 0.2.1 | 2021年6月4日 |
#263 在 游戏开发
每月313次下载
用于 2 包
520KB
585 行
bevy_console
一个简单的由 Half-Life 启发并支持参数解析的控制台,由 clap 提供。
用法
添加 ConsolePlugin 以及可选的资源 ConsoleConfiguration。
use bevy::prelude::*;
use bevy_console::{ConsoleConfiguration, ConsolePlugin};
fn main() {
App::new()
.add_plugins((DefaultPlugins, 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, 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中工作,但您需要禁用默认功能。
依赖关系
~26–62MB
~1M SLoC