AudioManager
public static class AudioManagerAudio playback and loading for the Audio Tool.
Properties
Section titled “Properties”
CurrentClip
Section titled “CurrentClip”public static AudioClip CurrentClip { get; }Gets the currently playing audio clip.
Returns
UnityEngine.AudioClip — No return description is available.
IsRangePlaying
Section titled “IsRangePlaying”public static bool IsRangePlaying { get; }Gets whether range playback is active.
Returns
System.Boolean — No return description is available.
RangeEndSample
Section titled “RangeEndSample”public static int RangeEndSample { get; }Gets the range end sample for range playback.
Returns
System.Int32 — No return description is available.
RangeStartSample
Section titled “RangeStartSample”public static int RangeStartSample { get; }Gets the range start sample for range playback.
Returns
System.Int32 — No return description is available.
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 | Starting sample position |
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 | Starting sample position |
endSample |
System.Int32 | Ending sample position (for tracking purposes) |
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.