cleanup global_observers
This commit is contained in:
@@ -12,6 +12,5 @@ use bevy::prelude::*;
|
|||||||
pub(crate) use observers::global_observer;
|
pub(crate) use observers::global_observer;
|
||||||
|
|
||||||
pub fn plugin(app: &mut App) {
|
pub fn plugin(app: &mut App) {
|
||||||
app.add_plugins(observers::plugin);
|
|
||||||
app.add_plugins(one_shot_force::plugin);
|
app.add_plugins(one_shot_force::plugin);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
use bevy::prelude::*;
|
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! global_observer {
|
macro_rules! global_observer {
|
||||||
($app:expr, $($system:tt)*) => {{
|
($app:expr, $($system:tt)*) => {{
|
||||||
@@ -25,26 +23,3 @@ macro_rules! global_observer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub use global_observer;
|
pub use global_observer;
|
||||||
|
|
||||||
pub fn plugin(app: &mut App) {
|
|
||||||
app.add_systems(Update, global_observers);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn global_observers(
|
|
||||||
mut cmds: Commands,
|
|
||||||
query: Query<Entity, (With<Observer>, Without<Children>, Added<Observer>)>,
|
|
||||||
mut root: Local<Option<Entity>>,
|
|
||||||
) {
|
|
||||||
if root.is_none() {
|
|
||||||
let new_root = cmds.spawn(Name::new("Observers")).id();
|
|
||||||
*root = Some(new_root);
|
|
||||||
}
|
|
||||||
|
|
||||||
let Some(root) = *root else {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
for o in query.iter() {
|
|
||||||
cmds.entity(o).try_insert(ChildOf(root));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user