|
|
|
|
@@ -5,6 +5,7 @@ using AppleHills.Core.Interfaces;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using AudioSourceEvents;
|
|
|
|
|
using System;
|
|
|
|
|
using Core;
|
|
|
|
|
using Core.Lifecycle;
|
|
|
|
|
|
|
|
|
|
public class AudioManager : ManagedBehaviour, IPausable
|
|
|
|
|
@@ -71,16 +72,14 @@ public class AudioManager : ManagedBehaviour, IPausable
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Debug.LogWarning("[AudioManager] QuickAccess.Instance is null during OnManagedAwake. Some audio references may remain unset.");
|
|
|
|
|
Logging.Warning("[AudioManager] QuickAccess.Instance is null during OnManagedAwake. Some audio references may remain unset.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Diagnostic
|
|
|
|
|
foreach (AppleAudioSource _audioSource in criticalVOSources)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("Found source: " + _audioSource.name);
|
|
|
|
|
Logging.Debug("Found source: " + _audioSource.name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Debug.Log("[AudioManager] OnManagedAwake completed");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetAudioPauseBehavior(PauseBehavior newPauseBehavior)
|
|
|
|
|
@@ -104,15 +103,15 @@ public class AudioManager : ManagedBehaviour, IPausable
|
|
|
|
|
|
|
|
|
|
public LevelAudioObject GetCurrentLevelAudioObject()
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("Audio objects: " + FindObjectsByType<LevelAudioObject>(FindObjectsInactive.Include, FindObjectsSortMode.None).Length);
|
|
|
|
|
Logging.Debug("Audio objects: " + FindObjectsByType<LevelAudioObject>(FindObjectsInactive.Include, FindObjectsSortMode.None).Length);
|
|
|
|
|
if (FindObjectsByType<LevelAudioObject>(FindObjectsInactive.Include, FindObjectsSortMode.None).Length > 1)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogWarning("Warning! More than one LevelAudioObject in the level! Using the first one found");
|
|
|
|
|
Logging.Warning("Warning! More than one LevelAudioObject in the level! Using the first one found");
|
|
|
|
|
return FindObjectsByType<LevelAudioObject>(FindObjectsInactive.Include, FindObjectsSortMode.None)[0];
|
|
|
|
|
}
|
|
|
|
|
if (FindObjectsByType<LevelAudioObject>(FindObjectsInactive.Include, FindObjectsSortMode.None).Length == 0)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogWarning("Error! No LevelAudioObject found, AudioManager might not function properly!");
|
|
|
|
|
Logging.Warning("Error! No LevelAudioObject found, AudioManager might not function properly!");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
@@ -158,12 +157,10 @@ public class AudioManager : ManagedBehaviour, IPausable
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool RequestPlayVO(AppleAudioSource requestedAudioSource)
|
|
|
|
|
{
|
|
|
|
|
//Debug.Log($"[AUDIOMANAGER] CurrentVO source prio: {currentlyPlayingVO.sourcePriority}, clip prio: {currentlyPlayingVO.clipPriority} requested VO prio: {requestedAudioSource.sourcePriority}, clip prio: {clipPriority}");
|
|
|
|
|
// If nothing is playing, let the requested audio source play
|
|
|
|
|
if (currentlyPlayingVO == null)
|
|
|
|
|
{
|
|
|
|
|
SetupNewAudioSource(requestedAudioSource);
|
|
|
|
|
Debug.Log($"[AUDIOMANAGER] Playing {currentlyPlayingVO.name} as nothing is currently playing.");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -177,7 +174,6 @@ public class AudioManager : ManagedBehaviour, IPausable
|
|
|
|
|
{
|
|
|
|
|
InterruptAudioSource(requestedAudioSource);
|
|
|
|
|
SetupNewAudioSource(requestedAudioSource);
|
|
|
|
|
Debug.Log($"[AUDIOMANAGER] {currentlyPlayingVO.name} is the same as {requestedAudioSource.name}. Triggering it again.");
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
@@ -187,7 +183,6 @@ public class AudioManager : ManagedBehaviour, IPausable
|
|
|
|
|
|
|
|
|
|
InterruptAudioSource(requestedAudioSource);
|
|
|
|
|
SetupNewAudioSource(requestedAudioSource);
|
|
|
|
|
Debug.Log($"[AUDIOMANAGER] {currentlyPlayingVO.name} is not critical. Playing {requestedAudioSource.name} instead because it is critical.");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
// If the requested audio source has the same priority as currently playing source, check the priority of the requested clip
|
|
|
|
|
@@ -197,8 +192,6 @@ public class AudioManager : ManagedBehaviour, IPausable
|
|
|
|
|
{
|
|
|
|
|
InterruptAudioSource(requestedAudioSource);
|
|
|
|
|
SetupNewAudioSource(requestedAudioSource);
|
|
|
|
|
Debug.Log($"[AUDIOMANAGER] Interrupted {currentlyPlayingVO.name} because it has same priority as {requestedAudioSource.name} but the requested clip has higher priority");
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
@@ -210,7 +203,6 @@ public class AudioManager : ManagedBehaviour, IPausable
|
|
|
|
|
if (currentlyPlayingVO.audioSourceType == AppleAudioSource.AudioSourceType.CriticalVO && currentlyPlayingVO.sourcePriority > requestedAudioSource.sourcePriority)
|
|
|
|
|
{
|
|
|
|
|
currentlyPlayingVO.InterruptAudio(requestedAudioSource.name);
|
|
|
|
|
Debug.Log($"[AUDIOMANAGER] Interrupted {currentlyPlayingVO.name} because {requestedAudioSource.name} has higher priority");
|
|
|
|
|
InterruptAudioSource(requestedAudioSource);
|
|
|
|
|
SetupNewAudioSource(requestedAudioSource);
|
|
|
|
|
return true;
|
|
|
|
|
@@ -218,7 +210,6 @@ public class AudioManager : ManagedBehaviour, IPausable
|
|
|
|
|
// If the requested audio source didn't clear any of the above cases, tell it to get rekt.
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Debug.Log($"[AUDIOMANAGER] {currentlyPlayingVO.name} is still playing. {requestedAudioSource.name} has lower priority");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -232,7 +223,6 @@ public class AudioManager : ManagedBehaviour, IPausable
|
|
|
|
|
{
|
|
|
|
|
if (audioSource.audioSource.resource == null)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log($"[AUDIOMANAGER] Faled to setup {audioSource.name}. Invalid resource");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
|