This is the lowest component in a hierarchy and extends Unity’s existing audio source component functionality. An audio component cannot have any children components attached.
In the audio component it is possible to:
- Set the audio clip that will be used to play audio, delay it
- Disable it from the audio component virtualization (if enabled in the Fabric manager)
- Keep the audio playing even if the parent game object has been destroyed
- Play audio clip
- Read loop markers from wavfile.
- Define num of loops
- Loop infinitely until stopped
- Randomise position
- Dynamic load the audio clip
- In Unity 4.5.3> the Resourcesw.LoadAsync is used, in previous version WWW is used
- Sync with global music selection set in the component properties
- Delay the start of the audio components by a number of beats
Dynamic AudioClip Loading
By Enabling this option Fabric will manage the loading of the audio data into memory automatically depending the audio clip options (for Unity 5+). For example if an audio component ir requested to play an instance for the first time the audio data will be loaded into memory and then will only get unloaded if all instances have stopped playing.
It is also possible to post LoadAudio/UnloadAudio event actions to any component in the Fabric hierarchy causing all audio components located underneath to load/unload their audio data into/from the audio memory.
Using AudioClip Path
When the dynamic audio clip option is selected for the first time the "Use AudioClip Path" behavior is enabled which uses Unity's Resource.Load function to load the audio clip into memory. This is the first implementation of this feature and was design with Unity 4 in mind. The main reason enabled by default mainly to support existing games.
AudioClip Loading options
In Unity 5+ the audio clip now provides two different options for loading the audio data,
- Load In Background: Loads the audio data Asynchronously without stalling the game
- Preload Audio Data: The audio data will load into memory the moment it is referenced by an audio component
Markers and Regions
The Audio Componebnt can load Markers and Regions that are saved within the audio file that is set to play.
NOTE: This is a manual process and its up to you to ensure that the markers are loaded/unloaded when a new audio file is selected.
When loading Markers it is possible to set the type of notification the audio component will send to its parent. This is useful if the audio component is part of a Sequence or Switch hiearchy tconfigured to sync on a marker and that way instruct them when to advance.
It is also possible to specify which the loop region using the markers and randomize the start or end marker from the list available. The randomization occurs everytime the sound has been looped.
|Marker Notification Types||Description|
|Ignore||Marker is ignored
|Notify||Marker notifies the parent and keeps playing|
|Notify And Play To End
||Marker notifies parent component and plays until the end and then stops|
|Notify And Stop||Marker notifies parent component and stops|
The audio component can also load Regions such as 'Sample Loops' and provide an option to set the active looop section.
When the "Randomize Region" option is enabled the audio component will pick a new loop region in random everytime a loop is played.
AudioComponent provides the following code features,
- SetMarker: If the audio clip has wavfile markers and they are loaded it is possible to set the playing position using the marker label, this is achieved by posting a SetMarker event action passing the name of the marker,
Fabric.EventManager.Instance.PostEvent("NAME OF EVENT", Fabric.EventAction.SetMarker, "marker name", gameObject);
Link to a video explaining more about Audio Components and event triggers