Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Assets/LucidAudio/Runtime/AudioPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,9 @@ public AudioPlayer SetVolume(float volume)
case AudioType.SE:
audioSource.volume = volume * LucidAudio.SEVolume;
break;
case AudioType.SpatialSE:
audioSource.volume = volume * LucidAudio.SpatialVolume;
break;
}
return this;
}
Expand Down Expand Up @@ -536,6 +539,9 @@ public void FadeVolume(float endValue, float duration, Action callback = null)
case AudioType.SE:
fadeVolumeStartValue = LucidAudio.SEVolume == 0 ? 1 : (audioSource.volume / LucidAudio.SEVolume);
break;
case AudioType.SpatialSE:
fadeVolumeStartValue = LucidAudio.SpatialVolume == 0 ? 1 : (audioSource.volume / LucidAudio.SpatialVolume);
break;
}
fadeVolumeEndValue = endValue;

Expand Down
5 changes: 3 additions & 2 deletions Assets/LucidAudio/Runtime/Enum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ namespace AnnulusGames.LucidTools.Audio
{
public enum AudioType
{
BGM,
SE
BGM =0,
SE =1,
SpatialSE =2
}

public enum AudioCancelBehaviour
Expand Down
55 changes: 46 additions & 9 deletions Assets/LucidAudio/Runtime/LucidAudio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,27 @@ public static int ActivePlayerCount

public static float BGMVolume { get; set; } = 1f;
public static float SEVolume { get; set; } = 1f;
public static float SpatialVolume { get; set; } = 1f;

public static AudioMixerGroup defaultBGMMixerGroup = null;
public static AudioMixerGroup defaultSEMixerGroup = null;
public static AudioMixerGroup defaultBGMMixerGroup
{
get => MixerGroups[(int)AudioType.BGM];
set => MixerGroups[(int)AudioType.BGM] = value;
}

public static AudioMixerGroup defaultSEMixerGroup
{
get => MixerGroups[(int)AudioType.SE];
set => MixerGroups[(int)AudioType.SE] = value;
}

public static AudioMixerGroup defaultSpatialSEMixerGroup
{
get => MixerGroups[(int)AudioType.SpatialSE];
set => MixerGroups[(int)AudioType.SpatialSE] = value;
}

public static readonly AudioMixerGroup[] MixerGroups = new AudioMixerGroup[3];

public static AudioPlayer[] GetPlayers()
{
Expand All @@ -53,7 +71,7 @@ public static AudioPlayer[] GetPlayersByClip(AudioClip clip)

public static AudioPlayer Play(AudioType type, AudioClip clip, float fadeInDuration = 0f)
{
return LucidAudioManager.Instance.Play(type, clip, fadeInDuration).SetAudioMixerGroup(defaultSEMixerGroup);
return LucidAudioManager.Instance.Play(type, clip, fadeInDuration).SetAudioMixerGroup(MixerGroups[(int)type]);
}

public static AudioPlayer PlayBGM(AudioClip clip, float fadeInDuration = 0f)
Expand All @@ -64,7 +82,10 @@ public static AudioPlayer PlaySE(AudioClip clip, float fadeInDuration = 0f)
{
return Play(AudioType.SE, clip, fadeInDuration);
}

public static AudioPlayer PlaySpatial(AudioClip clip, float fadeInDuration = 0f)
{
return Play(AudioType.SpatialSE, clip, fadeInDuration);
}
public static void RestartAllBGM()
{
LucidAudioManager.Instance.Restart(AudioType.BGM);
Expand All @@ -84,7 +105,10 @@ public static void RestartAllSE()
{
LucidAudioManager.Instance.Restart(AudioType.SE);
}

public static void RestartAllSpatial()
{
LucidAudioManager.Instance.Restart(AudioType.SpatialSE);
}
public static void RestartAllSE(AudioClip clip)
{
LucidAudioManager.Instance.Restart(AudioType.SE, clip);
Expand All @@ -99,6 +123,7 @@ public static void RestartAll()
{
RestartAllBGM();
RestartAllSE();
RestartAllSpatial();
}

public static void RestartAll(AudioClip clip)
Expand All @@ -117,7 +142,6 @@ public static void StopAllBGM()
{
LucidAudioManager.Instance.Stop(AudioType.BGM);
}

public static void StopAllBGM(float fadeOutDuration)
{
LucidAudioManager.Instance.Stop(AudioType.BGM, null, null, fadeOutDuration);
Expand Down Expand Up @@ -172,11 +196,15 @@ public static void StopAllSE(string id, float fadeOutDuration)
{
LucidAudioManager.Instance.Stop(AudioType.SE, null, id, fadeOutDuration);
}

public static void StopAllSpatial()
{
LucidAudioManager.Instance.Stop(AudioType.SpatialSE);
}
public static void StopAll()
{
StopAllBGM();
StopAllSE();
StopAllSpatial();
}

public static void StopAll(float fadeOutDuration)
Expand Down Expand Up @@ -212,6 +240,10 @@ public static void StopAll(string id, float fadeOutDuration)
public static void PauseAllBGM()
{
LucidAudioManager.Instance.Pause(AudioType.BGM);
}
public static void PauseAllSpatial()
{
LucidAudioManager.Instance.Pause(AudioType.SpatialSE);
}

public static void PauseAllBGM(float fadeOutDuration)
Expand Down Expand Up @@ -273,6 +305,7 @@ public static void PauseAll()
{
PauseAllBGM();
PauseAllSE();
PauseAllSpatial();
}

public static void PauseAll(float fadeOutDuration)
Expand Down Expand Up @@ -309,7 +342,10 @@ public static void UnPauseAllBGM()
{
LucidAudioManager.Instance.UnPause(AudioType.BGM);
}

public static void UnPauseAllSpatial()
{
LucidAudioManager.Instance.UnPause(AudioType.SpatialSE);
}
public static void UnPauseAllBGM(float fadeInDuration)
{
LucidAudioManager.Instance.UnPause(AudioType.BGM, null, null, fadeInDuration);
Expand Down Expand Up @@ -369,6 +405,7 @@ public static void UnPauseAll()
{
UnPauseAllBGM();
UnPauseAllSE();
UnPauseAllSpatial();
}

public static void UnPauseAll(float fadeInDuration)
Expand Down Expand Up @@ -401,4 +438,4 @@ public static void UnPauseAll(string id, float fadeInDuration)
UnPauseAllSE(id, fadeInDuration);
}
}
}
}
2 changes: 2 additions & 0 deletions Assets/LucidAudio/Runtime/LucidAudioManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static LucidAudioManager Instance
internal static bool isInstanceNull => instance == null;

private Queue<AudioSource> seSourcePool = new Queue<AudioSource>();
private Queue<AudioSource> spatialSourcePool = new Queue<AudioSource>();
private Queue<AudioSource> bgmSourcePool = new Queue<AudioSource>();
private List<AudioPlayer> activeAudioPlayers = new List<AudioPlayer>();
private List<AudioPlayer> waitingAudioPlayers = new List<AudioPlayer>();
Expand Down Expand Up @@ -177,6 +178,7 @@ private Queue<AudioSource> GetAudioSourcePool(AudioType audioType)
{
case AudioType.BGM: return bgmSourcePool;
case AudioType.SE: return seSourcePool;
case AudioType.SpatialSE: return spatialSourcePool;
}
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/LucidAudio/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.annulusgames.lucid-audio",
"displayName": "Lucid Audio",
"version": "1.0.1",
"version": "1.0.2",
"unity": "2019.4",
"license": "MIT",
"author": {
Expand Down