mirror of
https://github.com/bevyengine/bevy
synced 2025-02-16 14:08:32 +00:00
Derive FromReflect
for Transform
and GlobalTransform
(#6015)
# Objective Both components already derives `Reflect` and it would be nice to have `FromReflect` in order to ser/de between those types without relaying on `downcast`, since it can fail between different platforms, like WebAssembly. ## Solution Derive `FromReflect` for `Transform` and `GlobalTransform`. I thought if I should also derive `FromReflect` for `GlobalTransform`, since it's a computed component, but there may be some use cases where a `GlobalTransform` is needed to be sent over the wire, so I decided to do it.
This commit is contained in:
parent
69d08c5ef4
commit
dc5836f5b7
2 changed files with 3 additions and 3 deletions
|
@ -3,7 +3,7 @@ use std::ops::Mul;
|
|||
use super::Transform;
|
||||
use bevy_ecs::{component::Component, reflect::ReflectComponent};
|
||||
use bevy_math::{Affine3A, Mat4, Quat, Vec3, Vec3A};
|
||||
use bevy_reflect::Reflect;
|
||||
use bevy_reflect::{FromReflect, Reflect};
|
||||
|
||||
/// Describe the position of an entity relative to the reference frame.
|
||||
///
|
||||
|
@ -31,7 +31,7 @@ use bevy_reflect::Reflect;
|
|||
/// - [`global_vs_local_translation`]
|
||||
///
|
||||
/// [`global_vs_local_translation`]: https://github.com/bevyengine/bevy/blob/latest/examples/transforms/global_vs_local_translation.rs
|
||||
#[derive(Component, Debug, PartialEq, Clone, Copy, Reflect)]
|
||||
#[derive(Component, Debug, PartialEq, Clone, Copy, Reflect, FromReflect)]
|
||||
#[reflect(Component, PartialEq)]
|
||||
pub struct GlobalTransform(Affine3A);
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ use std::ops::Mul;
|
|||
///
|
||||
/// [`global_vs_local_translation`]: https://github.com/bevyengine/bevy/blob/latest/examples/transforms/global_vs_local_translation.rs
|
||||
/// [`transform`]: https://github.com/bevyengine/bevy/blob/latest/examples/transforms/transform.rs
|
||||
#[derive(Component, Debug, PartialEq, Clone, Copy, Reflect)]
|
||||
#[derive(Component, Debug, PartialEq, Clone, Copy, Reflect, FromReflect)]
|
||||
#[reflect(Component, Default, PartialEq)]
|
||||
pub struct Transform {
|
||||
/// Position of the entity. In 2d, the last value of the `Vec3` is used for z-ordering.
|
||||
|
|
Loading…
Add table
Reference in a new issue