10 个重大版本更新
0.11.0 | 2023 年 11 月 10 日 |
---|---|
0.9.0 | 2023 年 4 月 23 日 |
0.8.0 | 2023 年 3 月 17 日 |
1377 在 游戏开发 中
53 次每月下载
33KB
658 行
Bevy 组件镜像
用于镜像 Component
值的第三方 crate。
默认情况下,它还提供了一组 bevy Component
,它们镜像了 bevy_rapier
Component
的值。(目前只有 bevy_rapier3d
,欢迎 PR!)由于一些 bevy_rapier
Component
没有实现 Reflect
,它们可能更难处理。这个 crate 特别适合与 bevy-inspector-egui
一起使用,它将允许你在运行时编辑 rapier 值,因此你不必反复重新启动游戏来找到正确的物理参数。
使用方法
- 将此 crate 作为依赖项添加到您的
Cargo.toml
。
[dependencies]
bevy_mod_component_mirror = "0.11.0"
- 将
RapierMirrorsPlugins
添加到您的应用程序
use bevy_mod_component_mirror::RapierMirrorsPlugins;
# fn main() {
# let mut app = bevy::prelude::App::new();
app
// Notice v the plural
.add_plugins(RapierMirrorsPlugins);
# }
就这样!现在每个具有以下 rapier (3d)组件的 Entity
都将自动有一个等效的 XyzMirror
组件,它会自动将其值与其同步。
ImpulseJoint
Collider
(一些碰撞形状尚未实现!)ColliderMassProperties
AdditionalMassProperties
实现您自己的镜像
如果您希望镜像其他组件,您需要执行以下操作
- 创建一个
Component
(例如:ForeignMirror
) - 为该组件实现
Mirror
trait。 - 为
From<&'a Foreign> for ForeignMirror
实现 - 将
MirrorPlugin::<Foreign, ForeignMirror>::new()
添加到您的app
use bevy_mod_component_mirror::{Mirror, MirrorPlugin};
use bevy::prelude::*;
# mod foreign_crate {
# use super::*;
# #[derive(Component)]
# pub struct Foreign; impl Foreign {
# pub fn set_length(&mut self, value: f32) {}
# pub fn length(&self) -> f32 { 0.0 }
# }}
use foreign_crate::Foreign;
// Component: required because you want it to be a component
// Reflect: this let `MirrorPlugin` register the `Mirror` type itself
#[derive(Component, Reflect)]
pub struct ForeignMirror {
inner: f32,
}
// Foreign → ForeignMirror
impl<'a> From<&'a Foreign> for ForeignMirror {
fn from(value: &'a Foreign) -> Self {
ForeignMirror {
inner: value.length(),
}
}
}
// ForeignMirror → Foreign
impl Mirror<Foreign> for ForeignMirror {
fn apply(&self, value: &mut Foreign) {
value.set_length(self.inner);
}
}
fn main() {
let mut app = App::new();
app.add_plugins(MirrorPlugin::<Foreign, ForeignMirror>::new());
}
功能
如果您不需要 rapier 组件的定义但仍然希望使用镜像插件,您可以使用以下方法禁用 rapier 组件
[dependencies]
bevy_mod_component_mirror = { version = "0.11.0", default-features = false }
版本矩阵
bevy | bevy_rapier3d | bevy_mod_component_mirror |
---|---|---|
0.12 | 0.23.0 | 0.11.0 |
0.11 | 0.22.0 | 0.10.0 |
0.10 | 0.21.0 | 0.9 |
0.9 | 0.20.0 | 0.7 |
变更日志
0.11
: 重大变更:升级到 bevy 0.12 & rapier 0.230.10
: 重大变更: 升级到 bevy 0.11 & rapier 0.22(感谢 GitHub 上的 Naomijub,参见 #3)0.9
: 修复了一个目前未知来源的编译错误
开发
考虑将 .git/hooks/pre-commit.sample
移动到 .git/hooks/pre-commit.sample
,并在最后一个 exec
之前添加以下行
if ! make pre-hook ; then
echo Error: Some pre-commit checks did not pass!
exit 1
fi
许可证
版权所有 © 2022 Nicola Papale
本软件根据您个人喜好,许可使用 MIT 或 Apache 2.0 协议。请参阅许可证目录获取详细信息。
依赖项
~24MB
~435K SLoC