- 0.6 到 0.7
- 针对冲突的 SystemParam 的 ParamSet
- 别名可变性
- 移除 margins.rs
- 移除 face_toward.rs
- World::entities_mut 现在是不安全的
- 自定义顶点属性
- 网格顶点缓冲区布局
- 使用运行条件管道时,不再需要 “IntoSystem::into_system()”
- 移除 RunSystem
- 用 PresentMode 替换 VSync
- 修复 mul_vec3 变换顺序
- 使用标记组件代替名称字符串表示摄像机
- 移除配置 API
- 摄像机现在指向 RenderTarget 而不是 Window
- 为 Commands 和 World 实现 init_resource
- 无错误资源获取器
- 事件处理类型不再从 bevy_app 重新导出
迁移指南:0.6 到 0.7
针对冲突的 SystemParam 的 ParamSet #
// 0.6
fn system(
mut transforms: QuerySet<(
QueryState<&mut Transform, With<Marker>>,
QueryState<&Transform>,
)>,
) {
for transform in transforms.q1().iter() {
// ...
}
}
// 0.7
fn system(
mut transforms: ParamSet<(
Query<&mut Transform, With<Marker>>,
Query<&Transform>
)>,
) {
for transform in transforms.p1().iter() {
// ...
}
}
别名可变性 #
QueryEntityError
枚举现在有一个 AliasedMutability
变体,并返回出错的实体。
移除 margins.rs #
Margins
类型已被移除。要迁移,请将所有 Margins
替换为 Rect
。
移除 face_toward.rs #
FaceToward
特性已被移除。要迁移,请将所有 Mat4::face_toward
替换为 Mat4::look_at_rh
。
World::entities_mut 现在是不安全的 #
// 0.6
world.entities_mut()
// 0.7
unsafe { world.entities_mut() }
自定义顶点属性 #
自定义顶点属性现在由 MeshVertexAttribute
引用,而不是简单的字符串,set_attribute
已重命名为 insert_attribute
以更好地反映其行为。
// 0.6
mesh.set_attribute("Vertex_Custom", VertexAttributeValues::Sint32x4(vec![]));
// 0.7
// Generate your own "high" random usize identifier here.
// https://play.rust-lang.org/?gist=f40a801c124befef4a8270f6b011f275
pub const ATTRIBUTE_CUSTOM: MeshVertexAttribute =
MeshVertexAttribute::new("Custom", 3046527323, VertexFormat::Sint32x4);
mesh.insert_attribute(
ATTRIBUTE_CUSTOM,
VertexAttributeValues::Sint32x4(vec![]),
);
网格顶点缓冲区布局 #
顶点缓冲区不再需要在 RenderPipelineDescriptor
中使用偏移量和跨度值手动布局。
// 0.6
let vertex_buffer_layout = VertexBufferLayout {
array_stride: 20,
step_mode: VertexStepMode::Vertex,
attributes: vec![
VertexAttribute {
format: VertexFormat::Float32x3,
offset: 0,
shader_location: 0,
},
VertexAttribute {
format: VertexFormat::Float32x2,
offset: 12,
shader_location: 1,
},
],
};
// 0.7
let mut formats = vec![
VertexFormat::Float32x3,
VertexFormat::Float32x2,
];
let vertex_layout = VertexBufferLayout::from_vertex_formats(VertexStepMode::Vertex, formats);
使用运行条件管道时,不再需要 “IntoSystem::into_system()” #
// 0.6
.with_run_criteria(RunCriteria::pipe(
"is_done_label",
IntoSystem::into_system(inverse),
))
// 0.7
.with_run_criteria(RunCriteria::pipe("is_done_label", inverse))
移除 RunSystem #
您可能不应该使用 RunSystem
或 ParamSystem
,但如果您确实使用了它,并且确实需要它,请务必 创建一个新的讨论 告知我们。
用 PresentMode 替换 VSync #
我们不再使用布尔标志表示垂直同步,而是使用具有多个变体的 PresentMode
枚举。
// 0.6
App::new()
.insert_resource(WindowDescriptor {
vsync: false,
..Default::default()
})
// 0.7
use bevy::window::PresentMode;
App::new()
.insert_resource(WindowDescriptor {
present_mode: PresentMode::Immediate,
..Default::default()
})
修复 mul_vec3 变换顺序 #
变换现在始终按标准的缩放 -> 旋转 -> 平移顺序应用。除非您处理了错误的行为,否则这不需要任何代码更改,但这意味着 SpriteBundle 现在在旋转时将按预期行为。
使用标记组件代替名称字符串表示摄像机 #
// 0.6
pub const FIRST_PASS_CAMERA: &str = "first_pass_camera";
fn setup(mut commands: Commands) {
commands.spawn_bundle(PerspectiveCameraBundle {
camera: Camera {
name: Some(FIRST_PASS_CAMERA.to_string()),
..Default::default()
},
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 15.0))
.looking_at(Vec3::default(), Vec3::Y),
..Default::default()
});
}
fn camera_system(cameras: Query<&Camera>) {
for camera in cameras.iter() {
if camera.name == Some(FIRST_PASS_CAMERA.to_string()) {
// Do something with a camera
}
}
}
// 0.7
#[derive(Component, Default)]
pub struct FirstPassCamera;
fn setup(mut commands: Commands) {
commands.spawn_bundle(PerspectiveCameraBundle::<FirstPassCamera> {
camera: Camera::default(),
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 15.0))
.looking_at(Vec3::default(), Vec3::Y),
..PerspectiveCameraBundle::new()
});
}
fn camera_system(cameras: Query<&Camera, With<FirstPassCamera>>) {
for camera in cameras.iter() {
// Do something with camera
}
}
移除配置 API #
// 0.6
struct Config(u32);
fn local_is_42(local: Local<Config>) {
assert_eq!(*local.0, 42);
}
fn main() {
App::new()
.add_system(local_is_42.config(|params| params.0 = Some(Config(42))))
.run();
}
// 0.7
fn local_is_42(local: u32) -> impl FnMut() {
// This closure will be the system that will be executed
move || {
assert_eq!(local, 42);
}
}
fn main() {
App::new().add_system(local_is_42(42)).run();
}
摄像机现在指向 RenderTarget 而不是 Window #
此更改是为了支持渲染到纹理。使用多个窗口的用户可能会受到影响。
// 0.6
commands.spawn_bundle(PerspectiveCameraBundle {
camera: Camera {
window: window_id,
..Default::default()
},
..Default::default()
});
// 0.7
commands.spawn_bundle(PerspectiveCameraBundle {
camera: Camera {
target: RenderTarget::Window(window_id),
..Default::default()
},
..Default::default()
});
为 Commands 和 World 实现 init_resource #
处理插入资源的方法已重新设计,以确保 Commands
和 Worlds
API 之间的 consistency。
重大变化是 World::insert_non_send
已重命名为 World::insert_non_send_resource
。
// 0.6
world.insert_non_send(Score { score: 0 });
// 0.7
world.insert_non_send_resource(Score { score: 0 });
无错误资源获取器 #
// 0.6
let score = world.get_resource::<Score>().unwrap();
// 0.7
let score = world.resource::<Score>();
事件处理类型不再从 bevy_app 重新导出 #
这只会影响直接从 bevy_app
导入这些类型而不是通过 bevy 的序言导入的用户。
// 0.6
use bevy::app::{EventId, EventReader, EventWriter, Events, ManualEventReader};
// 0.7
use bevy::ecs::event::{EventId, EventReader, EventWriter, Events, ManualEventReader};