AudioManager
public static class AudioManagerAudio playback and loading for the Audio Tool.
Methods
Section titled “Methods”
LoadAudioFromFile(string, bool)
Section titled “LoadAudioFromFile(string, bool)”public static Task<AudioClip> LoadAudioFromFile(string filePath, bool allowStreaming = true)Loads an audio file from disk.
Parameters
| Name | Type | Description |
|---|---|---|
filePath |
System.String | Path to the audio file |
allowStreaming |
System.Boolean | If true, uses streaming for better performance. Set to false to access raw sample data. |
Returns
System.Threading.Tasks.Task{UnityEngine.AudioClip}: The loaded AudioClip, or null if loading failed
PlayClip(AudioClip, int, bool)
Section titled “PlayClip(AudioClip, int, bool)”public static void PlayClip(AudioClip clip, int startSample = 0, bool loop = false)Plays an AudioClip directly.
Parameters
| Name | Type | Description |
|---|---|---|
clip |
UnityEngine.AudioClip | The audio clip to play |
startSample |
System.Int32 | Inclusive per-channel sample-frame index at which playback begins. |
loop |
System.Boolean | Whether to loop playback |
PlayClipRange(AudioClip, int, int, bool)
Section titled “PlayClipRange(AudioClip, int, int, bool)”public static void PlayClipRange(AudioClip clip, int startSample, int endSample, bool loop = false)Plays a specific range of an AudioClip. Note: Due to Unity’s API limitations, this plays from startSample but doesn’t auto-stop at endSample. Use GetCurrentSamplePosition() to check and stop manually if needed.
Parameters
| Name | Type | Description |
|---|---|---|
clip |
UnityEngine.AudioClip | The audio clip to play |
startSample |
System.Int32 | Inclusive per-channel sample-frame index at which playback begins. |
endSample |
System.Int32 | Exclusive per-channel sample-frame index tracked as the requested end. |
loop |
System.Boolean | Whether to loop playback |
GetCurrentPosition()
Section titled “GetCurrentPosition()”public static float GetCurrentPosition()Gets the current playback position in seconds.
Returns
System.Single: Current position in seconds, or 0 if not playing
GetCurrentSamplePosition()
Section titled “GetCurrentSamplePosition()”public static int GetCurrentSamplePosition()Gets the current playback position in samples.
Returns
System.Int32: Current sample position, or 0 if not playing
HasReachedRangeEnd()
Section titled “HasReachedRangeEnd()”public static bool HasReachedRangeEnd()Checks if the playback has reached the end of the specified range.
Returns
System.Boolean: True if range playback has completed
IsPlaying()
Section titled “IsPlaying()”public static bool IsPlaying()Checks if audio is currently playing.
Returns
System.Boolean: True if audio is playing
PauseAudio()
Section titled “PauseAudio()”public static void PauseAudio()Pauses the currently playing audio.
ResumeAudio()
Section titled “ResumeAudio()”public static void ResumeAudio()Resumes paused audio.
StopAudio()
Section titled “StopAudio()”public static void StopAudio()Stops audio playback.
Properties
Section titled “Properties”
CurrentClip
Section titled “CurrentClip”public static AudioClip CurrentClip { get; }Gets the clip most recently started through this manager, or null before playback.
Returns
UnityEngine.AudioClip
IsRangePlaying
Section titled “IsRangePlaying”public static bool IsRangePlaying { get; }Gets whether the current preview is being tracked against a requested sample range.
Returns
System.Boolean
RangeEndSample
Section titled “RangeEndSample”public static int RangeEndSample { get; }Gets the exclusive per-channel sample-frame index used to detect the end of range playback.
Returns
System.Int32
RangeStartSample
Section titled “RangeStartSample”public static int RangeStartSample { get; }Gets the inclusive per-channel sample-frame index where range playback started.
Returns
System.Int32