bevy
bevy copied to clipboard
Add extension method for `App` in `bevy_audio` that register custom `Decodable` types
What problem does this solve or what need does it fill?
Related to #6362. Creating custom Decodable types requires boilerplate.
What solution would you like?
Create an extension trait for App.
trait AddAudioSource {
fn add_audio_source<Au>(&mut self) -> &mut Self
where
Au: Decodable + Asset;
}
impl AddAudioSource for App {
fn add_audio_source<Au>(&mut self) -> &mut Self
where
Au: Decodable + Asset
{
self.add_asset::<Au>
.init_resource::<Audio<Au>>()
.init_non_send_resource::<AudioOutput<Au>>()
.add_system_to_stage(CoreStage::PostUpdate, play_queued_audio_system::<Au>)
}
}
What alternative(s) have you considered?
Simply do not do this. Manually register audio sources.
Additional context
See harudagondi/bevy_fundsp#6, especially in lib.rs and backend/bevy_audio.rs.
Also see bevy_oddio's implementation.
I am working on this.