Add SceneInstanceReady (#9313)

# Objective

Closes #9115, replaces #9117.

## Solution

Emit event when scene is ready.

---

## Changelog

### Added

- `SceneInstanceReady` event when scene becomes ready.
This commit is contained in:
Hennadii Chernyshchyk 2023-08-15 22:45:01 +03:00 committed by GitHub
parent 55a710995c
commit d60b715411
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View file

@ -40,6 +40,7 @@ impl Plugin for ScenePlugin {
app.add_asset::<DynamicScene>()
.add_asset::<Scene>()
.init_asset_loader::<SceneLoader>()
.add_event::<SceneInstanceReady>()
.init_resource::<SceneSpawner>()
.add_systems(SpawnScene, (scene_spawner, scene_spawner_system).chain());
}

View file

@ -2,7 +2,7 @@ use crate::{DynamicScene, Scene};
use bevy_asset::{AssetEvent, Assets, Handle};
use bevy_ecs::{
entity::{Entity, EntityMap},
event::{Events, ManualEventReader},
event::{Event, Events, ManualEventReader},
reflect::AppTypeRegistry,
system::{Command, Resource},
world::{Mut, World},
@ -12,6 +12,15 @@ use bevy_utils::{tracing::error, HashMap, HashSet};
use thiserror::Error;
use uuid::Uuid;
/// Emitted when [`crate::SceneInstance`] becomes ready to use.
///
/// See also [`SceneSpawner::instance_is_ready`].
#[derive(Event)]
pub struct SceneInstanceReady {
/// Entity to which the scene was spawned as a child.
pub parent: Entity,
}
/// Information about a scene instance.
#[derive(Debug)]
pub struct InstanceInfo {
@ -285,6 +294,8 @@ impl SceneSpawner {
child: entity,
}
.apply(world);
world.send_event(SceneInstanceReady { parent });
}
}
} else {