2022-01-14 18:47:48 +00:00
|
|
|
#![warn(missing_docs)]
|
2021-12-18 22:59:55 +00:00
|
|
|
#![doc = include_str!("../README.md")]
|
|
|
|
|
2022-01-14 18:47:48 +00:00
|
|
|
/// The basic components of the transform crate
|
2019-12-02 09:31:07 +00:00
|
|
|
pub mod components;
|
2022-01-14 18:47:48 +00:00
|
|
|
/// Establishing and updating the transform hierarchy
|
2020-07-16 23:51:45 +00:00
|
|
|
pub mod hierarchy;
|
2022-01-14 18:47:48 +00:00
|
|
|
/// Propagating transform changes down the transform hierarchy
|
2020-06-07 20:39:50 +00:00
|
|
|
pub mod transform_propagate_system;
|
2019-12-02 09:31:07 +00:00
|
|
|
|
2022-01-14 18:47:48 +00:00
|
|
|
#[doc(hidden)]
|
2019-12-02 09:31:07 +00:00
|
|
|
pub mod prelude {
|
2021-04-27 18:29:33 +00:00
|
|
|
#[doc(hidden)]
|
2020-07-16 23:32:39 +00:00
|
|
|
pub use crate::{components::*, hierarchy::*, TransformPlugin};
|
2020-07-10 04:18:35 +00:00
|
|
|
}
|
|
|
|
|
2021-02-18 21:20:37 +00:00
|
|
|
use bevy_app::prelude::*;
|
2021-07-27 23:42:36 +00:00
|
|
|
use bevy_ecs::schedule::{ParallelSystemDescriptorCoercion, SystemLabel};
|
2020-11-22 20:05:58 +00:00
|
|
|
use prelude::{parent_update_system, Children, GlobalTransform, Parent, PreviousParent, Transform};
|
2020-07-16 23:32:39 +00:00
|
|
|
|
2022-01-14 18:47:48 +00:00
|
|
|
/// The base plugin for handling [`Transform`] components
|
2020-07-16 23:32:39 +00:00
|
|
|
#[derive(Default)]
|
|
|
|
pub struct TransformPlugin;
|
|
|
|
|
2022-01-14 18:47:48 +00:00
|
|
|
/// Label enum for the types of systems relating to transform
|
2021-02-18 21:20:37 +00:00
|
|
|
#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemLabel)]
|
|
|
|
pub enum TransformSystem {
|
2022-01-14 18:47:48 +00:00
|
|
|
/// Propagates changes in transform to childrens' [`GlobalTransform`]
|
2021-02-18 21:20:37 +00:00
|
|
|
TransformPropagate,
|
2022-01-14 18:47:48 +00:00
|
|
|
/// Updates [`Parent`] when changes in the hierarchy occur
|
2021-02-18 21:20:37 +00:00
|
|
|
ParentUpdate,
|
|
|
|
}
|
|
|
|
|
2020-08-08 03:22:17 +00:00
|
|
|
impl Plugin for TransformPlugin {
|
2021-07-27 20:21:06 +00:00
|
|
|
fn build(&self, app: &mut App) {
|
2020-11-28 00:39:59 +00:00
|
|
|
app.register_type::<Children>()
|
|
|
|
.register_type::<Parent>()
|
|
|
|
.register_type::<PreviousParent>()
|
|
|
|
.register_type::<Transform>()
|
|
|
|
.register_type::<GlobalTransform>()
|
2020-07-16 23:32:39 +00:00
|
|
|
// add transform systems to startup so the first update is "correct"
|
2020-11-29 22:07:47 +00:00
|
|
|
.add_startup_system_to_stage(
|
2021-02-18 21:20:37 +00:00
|
|
|
StartupStage::PostStartup,
|
2021-07-27 23:42:36 +00:00
|
|
|
parent_update_system.label(TransformSystem::ParentUpdate),
|
2021-02-17 02:00:12 +00:00
|
|
|
)
|
|
|
|
.add_startup_system_to_stage(
|
2021-02-18 21:20:37 +00:00
|
|
|
StartupStage::PostStartup,
|
2021-02-17 02:00:12 +00:00
|
|
|
transform_propagate_system::transform_propagate_system
|
2021-02-18 21:20:37 +00:00
|
|
|
.label(TransformSystem::TransformPropagate)
|
|
|
|
.after(TransformSystem::ParentUpdate),
|
2021-02-17 02:00:12 +00:00
|
|
|
)
|
|
|
|
.add_system_to_stage(
|
2021-02-18 21:20:37 +00:00
|
|
|
CoreStage::PostUpdate,
|
2021-07-27 23:42:36 +00:00
|
|
|
parent_update_system.label(TransformSystem::ParentUpdate),
|
2020-11-29 22:07:47 +00:00
|
|
|
)
|
2020-11-17 02:18:00 +00:00
|
|
|
.add_system_to_stage(
|
2021-02-18 21:20:37 +00:00
|
|
|
CoreStage::PostUpdate,
|
2021-02-17 02:00:12 +00:00
|
|
|
transform_propagate_system::transform_propagate_system
|
2021-02-18 21:20:37 +00:00
|
|
|
.label(TransformSystem::TransformPropagate)
|
|
|
|
.after(TransformSystem::ParentUpdate),
|
2020-11-17 02:18:00 +00:00
|
|
|
);
|
2020-07-16 23:32:39 +00:00
|
|
|
}
|
2019-12-02 09:31:07 +00:00
|
|
|
}
|