Assets
While Bevy as a whole has assets, Yarn Spinner can associate specific assets with lines. These are always localised, such as voiceovers.
Using Metadata Instead of Assets
Before we jump into assets, let's first help you out if you don't care about localization. The mechanism in place for this is line metadata, which are strings you can add to Yarn lines after a hashtag:
A Dialogue View will be able to read the metadata "smiling", "laughing", and "smiling" again from LocalizedLine::metadata
and accordingly load things like character portraits. These annotations will also be written into the "comment" field of strings files, which are explained in the chapter Localisation.
Asset Providers
Assets are fetched from the filesystem by structs implementing AssetProvider
. They need to be registered when creating a DialogueRunner
. For example, if you use the audio_assets
feature, you can register an asset provider for audio files by modifying the code found in the Quick Start like this:
The bundled example Dialogue View does not play any audio files, so you will need to write your own Dialogue View to make use of this feature.
The AudioAssetProvider
itself is just a specialized FileExtensionAssetProvider
. As the name suggests, it serves any assets based on their extension:
The FileExtensionAssetProvider
(and, by extension, the AudioAssetProvider
) will search for their assets in the directory assets/dialogue/<language>/<line-id.extension>
. So, for example, an AudioAssetProvider
serving up a voiceover for the line with the ID 41239 while the game is set to the language "de-CH" will search for assets/dialogue/de-CH/41239.mp3
.
Finally, you can implement AssetProvider
yourself with whatever custom behavior you desire. Check out the trait's documentation for the necessary methods.