AudioWarper Component
AudioWarper
Overview
The AudioWarper component allows you to associate multiple audio clips with different languages directly in the inspector. Unlike the LanguageAudioManager, this component manages its own audio clips and swaps them automatically based on the selected language, without depending on any external audio manager.
This is useful for situations where audio needs to be localized on a per-object basis, and you want each object to handle its audio internally.
Key Features
Localized Audio: Each object can have its own localized audio clips based on language.
Automatic Switching: The audio clips automatically change based on the currently selected language.
Flexible Setup: Can be configured to play the audio either on an
AudioSourcecomponent or usingPlayClipAtPointfor 3D sound positioning.Easy Integration: Integrates seamlessly with the existing LanguageManager to track language changes in real-time.
How It Works
The AudioWarper component stores a list of LocalizedAudioClip objects, each of which contains a languageID and an associated AudioClip. When the language is changed in the game, the component automatically updates the audio clip being used.
Setup Instructions
Add the Component: Add the AudioWarper component to any GameObject that requires language-specific audio.
Configure Localized Audio Clips: In the Inspector, configure the
audioClipslist to include thelanguageID(e.g., "en", "pt-BR") and the associated audio clip.Optional - Auto Update AudioSource: If you want the component to automatically update the
AudioSourceon the object, enable theChange AudioSource Clip based on Languageoption and assign anAudioSource.Play Audio: Use the
PlayLocalizedAudio()method to play the audio in the correct language.
AudioWarper Properties
audioClips
A list of localized audio clips. Each entry includes a
languageIDand anAudioClip.
changeAudioSourceClip
If enabled, the
AudioSourceon the GameObject will be automatically updated with the correct audio clip based on the current language.
audioSource
The
AudioSourcecomponent to update with the localized audio clip. If left empty, the component will try to get theAudioSourceautomatically from the GameObject.
API Reference
UpdateAudioClip()
Updates the audio clip of the associated AudioSource based on the current language.
PlayLocalizedAudio()
Plays the localized audio clip for the current language. If an AudioSource is assigned, it plays through the AudioSource. Otherwise, it uses AudioSource.PlayClipAtPoint() to play the audio at the GameObject's position.
GetAudioClipForLanguage(string languageID)
Retrieves the AudioClip associated with a specific language ID.
StopAudio()
Stops any currently playing audio on the assigned AudioSource.
Example: Playing Localized Audio
Here's an example of how you can set up and use the AudioWarper component to play localized audio.
Add the AudioWarper component to a GameObject.
Add different audio clips for each language to the
audioClipslist.Ensure the
AudioSourceis assigned or use the default settings.Call
PlayLocalizedAudio()when you want to play the audio in the correct language.
Use Case
The AudioWarper component is ideal for use cases where you want to manage localized audio clips directly on a GameObject without relying on a global audio manager. It gives you more granular control over individual audio sources, allowing each GameObject to manage its own language-specific audio assets.

Last updated