Trait bevy_yarnspinner::prelude::AssetProvider
source · pub trait AssetProvider: Debug + Send + Sync {
// Required methods
fn as_any(&self) -> &dyn Any;
fn as_any_mut(&mut self) -> &mut dyn Any;
fn get_language(&self) -> Option<Language>;
fn set_language(&mut self, language: Option<Language>);
fn set_localizations(&mut self, localizations: Localizations);
fn set_asset_server(&mut self, asset_server: AssetServer);
fn update_asset_availability(
&mut self,
loaded_untyped_assets: &Assets<LoadedUntypedAsset>
) -> bool;
fn accept_line_hints(&mut self, line_ids: &[LineId]);
fn get_assets(&self, line: &UnderlyingYarnLine) -> LineAssets;
}
Expand description
Trait for providing assets for lines, e.g. audio files or character portraits.
If the audio_assets
feature is enabled, you can use the bundled [AudioAssetProvider
] struct to retrieve audio files.
You can also fetch assets in a similar way by using the FileExtensionAssetProvider
struct.
Required Methods§
sourcefn as_any(&self) -> &dyn Any
fn as_any(&self) -> &dyn Any
Returns the type as a [dyn Any
]. Used for polymorphism. Should be implemented like this:
fn as_any(&self) -> &dyn Any {
self
}
sourcefn as_any_mut(&mut self) -> &mut dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
Returns the type as a mutable [dyn Any
]. Used for polymorphism. Should be implemented like this:
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
sourcefn get_language(&self) -> Option<Language>
fn get_language(&self) -> Option<Language>
Returns the Language
that this AssetProvider
is currently using. If there are no Localizations
set, this returns None
.
sourcefn set_language(&mut self, language: Option<Language>)
fn set_language(&mut self, language: Option<Language>)
Sets the Language
that this AssetProvider
should use. If there are Localizations
available, this should only be called with Some
.
Since this method can be called by the user, implementors should check if the Language
is available via Localizations::supports_language
and panic if it isn’t.
sourcefn set_localizations(&mut self, localizations: Localizations)
fn set_localizations(&mut self, localizations: Localizations)
Sets the available Localizations
.
sourcefn set_asset_server(&mut self, asset_server: AssetServer)
fn set_asset_server(&mut self, asset_server: AssetServer)
Sets the [AssetServer
] used. This is a simple clone of the one found in the Bevy ECS [World
].
sourcefn update_asset_availability(
&mut self,
loaded_untyped_assets: &Assets<LoadedUntypedAsset>
) -> bool
fn update_asset_availability( &mut self, loaded_untyped_assets: &Assets<LoadedUntypedAsset> ) -> bool
Returns whether the assets for all lines announced by AssetProvider::accept_line_hints
are available, i.e. have been loaded and are ready to be used.
This method is allowed to process already loaded assets to make them ready for delivery.
sourcefn accept_line_hints(&mut self, line_ids: &[LineId])
fn accept_line_hints(&mut self, line_ids: &[LineId])
Passes the LineId
s that this AssetProvider
should soon provide assets for. These are the LineId
s that are contained in the current node and are not required to be actually reached.
sourcefn get_assets(&self, line: &UnderlyingYarnLine) -> LineAssets
fn get_assets(&self, line: &UnderlyingYarnLine) -> LineAssets
Returns the LineAssets
for the given UnderlyingYarnLine
. Will only be called if AssetProvider::update_asset_availability
returns true
,
so an implementor is expected to panic if the assets are not available.