From 6d8c1da35c5df71e74ba2eed1ec8494bcd4007c3 Mon Sep 17 00:00:00 2001 From: Josh Date: Fri, 2 May 2025 00:02:36 -0600 Subject: [PATCH 1/3] First pass of audio source management refactor --- .../Assets/Scripts/ManageAudioSources.cs | 50 +++++++++++++ .../Assets/Scripts/ManageAudioSources.cs.meta | 11 +++ .../Scripts/PlayAudioSequencesByName.cs | 73 ++++--------------- 3 files changed, 74 insertions(+), 60 deletions(-) create mode 100644 CinderellaCitySimulation/Assets/Scripts/ManageAudioSources.cs create mode 100644 CinderellaCitySimulation/Assets/Scripts/ManageAudioSources.cs.meta diff --git a/CinderellaCitySimulation/Assets/Scripts/ManageAudioSources.cs b/CinderellaCitySimulation/Assets/Scripts/ManageAudioSources.cs new file mode 100644 index 000000000..312f02b9b --- /dev/null +++ b/CinderellaCitySimulation/Assets/Scripts/ManageAudioSources.cs @@ -0,0 +1,50 @@ +using System.Collections.Generic; +using UnityEngine; + +/// +/// Manages the master and slave audio sources +/// + +// define the type of data/parameters that a set of speakers can get and set +[System.Serializable] +public class SpeakerParams +{ + public string keyName = ""; + public AudioSource masterAudioSource; + public List activeSlaveAudioSources = new List(); + public AudioClip[] clipSequence; + public int lastKnownClipIndex = 0; + public AudioClip lastKnownClip; + public float lastKnownClipTime = 0f; + public float speakerVolume = 0; // initialize at 0 to prevent a frame of extra-loud music + public float maxDistance = 0f; + public bool isResuming = false; +} + +public class AudioSourceGlobals +{ + // keep track of the master audio source in each scene + public static AudioSource masterAudioSource60s70s; + public static AudioSource masterAudioSource80s90s; + + // some audio clip sequences will change depending on + // whether the player is considered outside the mall or inside + public static bool isPlayerOutside; + + // default volume levels and max distances + public static float defaultSpeakerVolumeChatter = 0.3f; + public static float defaultSpeakerVolumeExteriorAmbient = 0.9f; + public static float defaultSpeakerMaxDistanceMallChatter = 500f; // also used for exterior ambient + + public static float defaultSpeakerVolumeMallCommon = 0.2f; + public static float defaultSpeakerMaxDistanceMallCommon = 20f; + + public static float defaultSpeakerVolumeMallFountain = 0.3f; + public static float defaultSpeakerDistanceMallFountain = 90f; + + public static float defaultSpeakerVolumeStore = 0.3f; + public static float defaultSpeakerMaxDistanceStore = 15f; + + // only one set of params can exist for each type, so keep track of them here + public static List allKnownSpeakerParams = new List(); +} \ No newline at end of file diff --git a/CinderellaCitySimulation/Assets/Scripts/ManageAudioSources.cs.meta b/CinderellaCitySimulation/Assets/Scripts/ManageAudioSources.cs.meta new file mode 100644 index 000000000..138c6551d --- /dev/null +++ b/CinderellaCitySimulation/Assets/Scripts/ManageAudioSources.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2c2b80e21d2c7724ab82976eb81a4df1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CinderellaCitySimulation/Assets/Scripts/PlayAudioSequencesByName.cs b/CinderellaCitySimulation/Assets/Scripts/PlayAudioSequencesByName.cs index 295dbc653..e977d99ed 100644 --- a/CinderellaCitySimulation/Assets/Scripts/PlayAudioSequencesByName.cs +++ b/CinderellaCitySimulation/Assets/Scripts/PlayAudioSequencesByName.cs @@ -10,68 +10,21 @@ /// // this script needs to be attached to an object that plays a series of AudioClips -// NOTE: this script assumes AudioClips have the proper import settings applied (Load in Background, Compressed in Memory, etc) which should be handled by AssetImportPipeline +// NOTE: this script assumes AudioClips have the proper import settings applied (Load in Background, +// Compressed in Memory, etc) which should be handled by AssetImportPipeline // if not, the game may stutter or hang at startup when invoking "Resources.Load()" on an AudioClip // the object this script is attached to should have these components [RequireComponent(typeof(AudioSource))] [RequireComponent(typeof(CanDisableComponents))] -// define the type of data/parameters that a set of speakers can get and set -[System.Serializable] -public class SpeakerParams -{ - public string keyName = ""; - public AudioSource masterAudioSource; - public List activeSlaveAudioSources = new List(); - public AudioClip[] clipSequence; - public int lastKnownClipIndex = 0; - public AudioClip lastKnownClip; - public float lastKnownClipTime = 0f; - public float speakerVolume = 0; // initialize at 0 to prevent a frame of extra-loud music - public float maxDistance = 0f; - public bool isResuming = false; -} - -public class AudioSourceGlobals -{ - // - // initialize speaker parameter sets - // - public static string mallAmbientChatter60s70sKeyName = "mall-ambient-chatter-60s70s"; - public static string mallMusic60s70sKeyName = "mall-music-60s70s"; - - public static string mallAmbientChatter80s90sKeyName = "mall-ambient-chatter-80s90s"; - public static string mallMusic80s90sKeyName = "mall-music-80s90s"; - - // default volume levels and max distances - public static float defaultSpeakerVolumeChatter = 0.3f; - public static float defaultSpeakerVolumeExteriorAmbient = 0.9f; - public static float defaultSpeakerMaxDistanceMallChatter = 500f; // also used for exterior ambient - - public static float defaultSpeakerVolumeMallCommon = 0.2f; - public static float defaultSpeakerMaxDistanceMallCommon = 20f; - - public static float defaultSpeakerVolumeMallFountain = 0.3f; - public static float defaultSpeakerDistanceMallFountain = 90f; - - public static float defaultSpeakerVolumeStore = 0.3f; - public static float defaultSpeakerMaxDistanceStore = 15f; - - // only one set of params can exist for each type, so keep track of them here - public static List allKnownSpeakerParams = new List(); - - // some audio clip sequences will change depending on - // whether the player is considered outside the mall or inside - public static bool isPlayerOutside; -} - public class PlayAudioSequencesByName : MonoBehaviour { // the audio source, scripts, and speaker parameters for this script instance AudioSource thisAudioSourceComponent; CanDisableComponents thisCanToggleComponentsScript; SpeakerParams thisSpeakerParams; + bool isMaster = false; // return speaker parameters by object name // most audio source distances and volumes are assigned to defaults, but can be overridden here @@ -86,9 +39,9 @@ public static SpeakerParams AssociateSpeakerParamsByName(string name) // mall - 60s70s // ambient chatter - case string partialName when partialName.Contains(AudioSourceGlobals.mallAmbientChatter60s70sKeyName): + case string partialName when partialName.Contains("mall-ambient-chatter-60s70s"): - thisKeyName = AudioSourceGlobals.mallAmbientChatter60s70sKeyName; + thisKeyName = "mall-ambient-chatter-60s70s"; matchingParams = GetSpeakerParamsIfKnown(thisKeyName); // if these params do not exist, create them and add them to the list if (matchingParams == null) @@ -157,9 +110,9 @@ public static SpeakerParams AssociateSpeakerParamsByName(string name) return matchingParams; // common area music - case string partialName when partialName.Contains(AudioSourceGlobals.mallMusic60s70sKeyName): + case string partialName when partialName.Contains("mall-music-60s70s"): - thisKeyName = AudioSourceGlobals.mallMusic60s70sKeyName; + thisKeyName = "mall-music-60s70s"; matchingParams = GetSpeakerParamsIfKnown(thisKeyName); // if these params do not exist, create them and add them to the list @@ -232,9 +185,9 @@ public static SpeakerParams AssociateSpeakerParamsByName(string name) return matchingParams; // common area music - case string partialName when partialName.Contains(AudioSourceGlobals.mallMusic80s90sKeyName): + case string partialName when partialName.Contains("mall-music-80s90s"): - thisKeyName = AudioSourceGlobals.mallMusic80s90sKeyName; + thisKeyName = "mall-music-80s90s"; matchingParams = GetSpeakerParamsIfKnown(thisKeyName); // if these params do not exist, create them and add them to the list if (matchingParams == null) @@ -465,12 +418,12 @@ public static SpeakerParams GetAmbientChatterSpeakerParamsByScene(string sceneNa case string partialName when partialName.Contains("60s70s") || partialName.Contains(SceneGlobals.experimentalSceneName): - matchingParams = AssociateSpeakerParamsByName(AudioSourceGlobals.mallAmbientChatter60s70sKeyName); + matchingParams = AssociateSpeakerParamsByName("mall-ambient-chatter-60s70s"); return matchingParams; case string partialName when partialName.Contains("80s90s"): - matchingParams = AssociateSpeakerParamsByName(AudioSourceGlobals.mallAmbientChatter80s90sKeyName); + matchingParams = AssociateSpeakerParamsByName("mall-ambient-chatter-80s90s"); return matchingParams; default: @@ -487,12 +440,12 @@ public static SpeakerParams GetMallMusicSpeakerParamsByScene(string sceneName) case string partialName when partialName.Contains("60s70s") || partialName.Contains(SceneGlobals.experimentalSceneName): - matchingParams = AssociateSpeakerParamsByName(AudioSourceGlobals.mallMusic60s70sKeyName); + matchingParams = AssociateSpeakerParamsByName("mall-music-60s70s"); return matchingParams; case string partialName when partialName.Contains("80s90s"): - matchingParams = AssociateSpeakerParamsByName(AudioSourceGlobals.mallMusic80s90sKeyName); + matchingParams = AssociateSpeakerParamsByName("mall-music-80s90s"); return matchingParams; default: From 018105486d4d3cdc6eeaf5921ed445c3f8bd8cb1 Mon Sep 17 00:00:00 2001 From: Josh Date: Fri, 2 May 2025 00:08:35 -0600 Subject: [PATCH 2/3] Moving more code --- .../Assets/Scripts/ManageAudioSources.cs | 298 +++++++++++++++++ .../Scripts/PlayAudioSequencesByName.cs | 309 +----------------- ...leChildrenComponentsByProximityToPlayer.cs | 2 +- 3 files changed, 306 insertions(+), 303 deletions(-) diff --git a/CinderellaCitySimulation/Assets/Scripts/ManageAudioSources.cs b/CinderellaCitySimulation/Assets/Scripts/ManageAudioSources.cs index 312f02b9b..bef853002 100644 --- a/CinderellaCitySimulation/Assets/Scripts/ManageAudioSources.cs +++ b/CinderellaCitySimulation/Assets/Scripts/ManageAudioSources.cs @@ -47,4 +47,302 @@ public class AudioSourceGlobals // only one set of params can exist for each type, so keep track of them here public static List allKnownSpeakerParams = new List(); +} + +public class ManageAudioSources +{ + // retrieve the known speaker params if it exists in the list + public static SpeakerParams GetSpeakerParamsIfKnown(string keyName) + { + SpeakerParams matchingParams = null; + + foreach (SpeakerParams knownParams in AudioSourceGlobals.allKnownSpeakerParams) + { + if (knownParams.keyName == keyName) + { + matchingParams = knownParams; + } + } + + return matchingParams; + } + + // return speaker parameters by object name + // most audio source distances and volumes are assigned to defaults, but can be overridden here + // primarily, this is used for differentiating audio sequences (playlists) between speakers + public static SpeakerParams AssociateSpeakerParamsByName(string name) + { + string thisKeyName = ""; + SpeakerParams matchingParams = null; + + switch (name) + { + // mall - 60s70s + + // ambient chatter + case string partialName when partialName.Contains("mall-ambient-chatter-60s70s"): + + thisKeyName = "mall-ambient-chatter-60s70s"; + matchingParams = GetSpeakerParamsIfKnown(thisKeyName); + // if these params do not exist, create them and add them to the list + if (matchingParams == null) + { + matchingParams = new SpeakerParams + { + keyName = thisKeyName, + maxDistance = AudioSourceGlobals.defaultSpeakerMaxDistanceMallChatter, + speakerVolume = AudioSourceGlobals.defaultSpeakerVolumeChatter, + clipSequence = ArrayUtils.ShuffleArray(Resources.LoadAll("Audio/sfx-mall-ambient-chatter")) + }; + AudioSourceGlobals.allKnownSpeakerParams.Add(matchingParams); + } + else // but if the params exist, make sure they're updated + { + matchingParams.clipSequence = AudioSourceGlobals.isPlayerOutside ? ArrayUtils.ShuffleArray(Resources.LoadAll("Audio/sfx-exterior-ambient")) : ArrayUtils.ShuffleArray(Resources.LoadAll("Audio/sfx-mall-ambient-chatter")); + matchingParams.speakerVolume = AudioSourceGlobals.isPlayerOutside ? AudioSourceGlobals.defaultSpeakerVolumeExteriorAmbient : AudioSourceGlobals.defaultSpeakerVolumeChatter; + } + + return matchingParams; + + // fountain type 1 + case string partialName when partialName.Contains("mall-fountain-60s70s-1"): + + thisKeyName = "mall-fountain-60s70s-1"; + matchingParams = GetSpeakerParamsIfKnown(thisKeyName); + // if these params do not exist, create them and add them to the list + if (matchingParams == null) + { + matchingParams = new SpeakerParams + { + keyName = thisKeyName, + maxDistance = AudioSourceGlobals.defaultSpeakerDistanceMallFountain, + speakerVolume = AudioSourceGlobals.defaultSpeakerVolumeMallFountain, + clipSequence = ArrayUtils.ShuffleArray(Resources.LoadAll("Audio/sfx-mall-fountain-1")) + }; + AudioSourceGlobals.allKnownSpeakerParams.Add(matchingParams); + } + else // but if the params exist, make sure they're updated + { + matchingParams.speakerVolume = AudioSourceGlobals.isPlayerOutside ? 0 : AudioSourceGlobals.defaultSpeakerVolumeMallFountain; + } + return matchingParams; + + // fountain type 2 + case string partialName when partialName.Contains("mall-fountain-60s70s-2"): + + thisKeyName = "mall-fountain-60s70s-2"; + matchingParams = GetSpeakerParamsIfKnown(thisKeyName); + // if these params do not exist, create them and add them to the list + if (matchingParams == null) + { + matchingParams = new SpeakerParams + { + keyName = thisKeyName, + maxDistance = AudioSourceGlobals.defaultSpeakerDistanceMallFountain, + speakerVolume = AudioSourceGlobals.isPlayerOutside ? 0 : AudioSourceGlobals.defaultSpeakerVolumeMallFountain, + clipSequence = ArrayUtils.ShuffleArray(Resources.LoadAll("Audio/sfx-mall-fountain-2")) + }; + AudioSourceGlobals.allKnownSpeakerParams.Add(matchingParams); + } + else // but if the params exist, make sure they're updated + { + matchingParams.speakerVolume = AudioSourceGlobals.isPlayerOutside ? 0 : AudioSourceGlobals.defaultSpeakerVolumeMallFountain; + } + return matchingParams; + + // common area music + case string partialName when partialName.Contains("mall-music-60s70s"): + + thisKeyName = "mall-music-60s70s"; + matchingParams = GetSpeakerParamsIfKnown(thisKeyName); + + // if these params do not exist, create them and add them to the list + if (matchingParams == null) + { + matchingParams = new SpeakerParams + { + keyName = thisKeyName, + maxDistance = AudioSourceGlobals.defaultSpeakerMaxDistanceMallCommon, + speakerVolume = AudioSourceGlobals.defaultSpeakerVolumeMallCommon, + clipSequence = ArrayUtils.ShuffleArray(Resources.LoadAll("Audio/music-mall-60s70s")) + }; + AudioSourceGlobals.allKnownSpeakerParams.Add(matchingParams); + } + else // but if the params exist, make sure they're updated + { + matchingParams.speakerVolume = AudioSourceGlobals.isPlayerOutside ? 0 : AudioSourceGlobals.defaultSpeakerVolumeMallCommon; + } + return matchingParams; + + // stores - 60s70s + + // store - musicland + case string partialName when partialName.Contains("store-music-musicland-60s70s"): + + thisKeyName = "store-music-musicland-60s70s"; + matchingParams = GetSpeakerParamsIfKnown(thisKeyName); + // if these params do not exist, create them and add them to the list + if (matchingParams == null) + { + matchingParams = new SpeakerParams + { + keyName = thisKeyName, + maxDistance = AudioSourceGlobals.defaultSpeakerMaxDistanceStore, + speakerVolume = AudioSourceGlobals.defaultSpeakerVolumeStore, + clipSequence = ArrayUtils.ShuffleArray(Resources.LoadAll("Audio/music-store-musicland-60s70s")) + }; + AudioSourceGlobals.allKnownSpeakerParams.Add(matchingParams); + } + else // but if the params exist, make sure they're updated + { + matchingParams.speakerVolume = AudioSourceGlobals.isPlayerOutside ? 0 : AudioSourceGlobals.defaultSpeakerVolumeStore; + } + return matchingParams; + + // mall - 80s90s + + // ambient chatter + case string partialName when partialName.Contains("mall-ambient-chatter-80s90s"): + + thisKeyName = "mall-ambient-chatter-80s90s"; + matchingParams = GetSpeakerParamsIfKnown(thisKeyName); + // if these params do not exist, create them and add them to the list + if (matchingParams == null) + { + matchingParams = new SpeakerParams + { + keyName = thisKeyName, + maxDistance = AudioSourceGlobals.defaultSpeakerMaxDistanceMallChatter, + speakerVolume = AudioSourceGlobals.defaultSpeakerVolumeChatter, + clipSequence = ArrayUtils.ShuffleArray(Resources.LoadAll("Audio/sfx-mall-ambient-chatter")) + }; + AudioSourceGlobals.allKnownSpeakerParams.Add(matchingParams); + } + else // but if the params exist, make sure they're updated + { + matchingParams.clipSequence = AudioSourceGlobals.isPlayerOutside ? ArrayUtils.ShuffleArray(Resources.LoadAll("Audio/sfx-exterior-ambient")) : ArrayUtils.ShuffleArray(Resources.LoadAll("Audio/sfx-mall-ambient-chatter")); + matchingParams.speakerVolume = AudioSourceGlobals.isPlayerOutside ? AudioSourceGlobals.defaultSpeakerVolumeExteriorAmbient : AudioSourceGlobals.defaultSpeakerVolumeChatter; + } + return matchingParams; + + // common area music + case string partialName when partialName.Contains("mall-music-80s90s"): + + thisKeyName = "mall-music-80s90s"; + matchingParams = GetSpeakerParamsIfKnown(thisKeyName); + // if these params do not exist, create them and add them to the list + if (matchingParams == null) + { + matchingParams = new SpeakerParams + { + keyName = thisKeyName, + maxDistance = AudioSourceGlobals.defaultSpeakerMaxDistanceMallCommon, + speakerVolume = AudioSourceGlobals.defaultSpeakerVolumeMallCommon, + clipSequence = ArrayUtils.ShuffleArray(Resources.LoadAll("Audio/music-mall-80s90s")) + }; + AudioSourceGlobals.allKnownSpeakerParams.Add(matchingParams); + } + else // but if the params exist, make sure they're updated + { + matchingParams.speakerVolume = AudioSourceGlobals.isPlayerOutside ? 0 : AudioSourceGlobals.defaultSpeakerVolumeMallCommon; + } + return matchingParams; + + // store - consumer beauty + case string partialName when partialName.Contains("store-music-consumer-beauty-80s90s"): + + thisKeyName = "store-music-consumer-beauty-80s90s"; + matchingParams = GetSpeakerParamsIfKnown(thisKeyName); + // if these params do not exist, create them and add them to the list + if (matchingParams == null) + { + matchingParams = new SpeakerParams + { + keyName = thisKeyName, + maxDistance = AudioSourceGlobals.defaultSpeakerMaxDistanceStore, + speakerVolume = AudioSourceGlobals.defaultSpeakerVolumeStore, + clipSequence = ArrayUtils.ShuffleArray(Resources.LoadAll("Audio/music-store-consumer-beauty-80s90s")) + }; + AudioSourceGlobals.allKnownSpeakerParams.Add(matchingParams); + } + else // but if the params exist, make sure they're updated + { + matchingParams.speakerVolume = AudioSourceGlobals.isPlayerOutside ? 0 : AudioSourceGlobals.defaultSpeakerVolumeStore; + } + return matchingParams; + + // store - dolcis + case string partialName when partialName.Contains("store-music-dolcis-80s90s"): + + thisKeyName = "store-music-dolcis-80s90s"; + matchingParams = GetSpeakerParamsIfKnown(thisKeyName); + // if these params do not exist, create them and add them to the list + if (matchingParams == null) + { + matchingParams = new SpeakerParams + { + keyName = thisKeyName, + maxDistance = AudioSourceGlobals.defaultSpeakerMaxDistanceStore, + speakerVolume = AudioSourceGlobals.defaultSpeakerVolumeStore, + clipSequence = ArrayUtils.ShuffleArray(Resources.LoadAll("Audio/music-store-dolcis-80s90s")) + }; + AudioSourceGlobals.allKnownSpeakerParams.Add(matchingParams); + } + else // but if the params exist, make sure they're updated + { + matchingParams.speakerVolume = AudioSourceGlobals.isPlayerOutside ? 0 : AudioSourceGlobals.defaultSpeakerVolumeStore; + } + return matchingParams; + + // store - generic + case string partialName when partialName.Contains("store-music-generic-80s90s"): + + thisKeyName = "store-music-generic-80s90s"; + matchingParams = GetSpeakerParamsIfKnown(thisKeyName); + // if these params do not exist, create them and add them to the list + if (matchingParams == null) + { + matchingParams = new SpeakerParams + { + keyName = thisKeyName, + maxDistance = AudioSourceGlobals.defaultSpeakerMaxDistanceStore, + speakerVolume = AudioSourceGlobals.defaultSpeakerVolumeStore, + clipSequence = ArrayUtils.ShuffleArray(Resources.LoadAll("Audio/music-store-generic-80s90s")) + }; + AudioSourceGlobals.allKnownSpeakerParams.Add(matchingParams); + } + else // but if the params exist, make sure they're updated + { + matchingParams.speakerVolume = AudioSourceGlobals.isPlayerOutside ? 0 : AudioSourceGlobals.defaultSpeakerVolumeStore; + } + return matchingParams; + + // store - musicland + case string partialName when partialName.Contains("store-music-musicland-80s90s"): + + thisKeyName = "store-music-musicland-80s90s"; + matchingParams = GetSpeakerParamsIfKnown(thisKeyName); + // if these params do not exist, create them and add them to the list + if (matchingParams == null) + { + matchingParams = new SpeakerParams + { + keyName = thisKeyName, + maxDistance = AudioSourceGlobals.defaultSpeakerMaxDistanceStore, + speakerVolume = AudioSourceGlobals.defaultSpeakerVolumeStore, + clipSequence = ArrayUtils.ShuffleArray(Resources.LoadAll("Audio/music-store-musicland-80s90s")) + }; + AudioSourceGlobals.allKnownSpeakerParams.Add(matchingParams); + } + else // but if the params exist, make sure they're updated + { + matchingParams.speakerVolume = AudioSourceGlobals.isPlayerOutside ? 0 : AudioSourceGlobals.defaultSpeakerVolumeStore; + } + return matchingParams; + + default: + DebugUtils.DebugLog("Failed to associate speaker params with this speaker: " + name); + return null; + } + } } \ No newline at end of file diff --git a/CinderellaCitySimulation/Assets/Scripts/PlayAudioSequencesByName.cs b/CinderellaCitySimulation/Assets/Scripts/PlayAudioSequencesByName.cs index e977d99ed..c43037fd2 100644 --- a/CinderellaCitySimulation/Assets/Scripts/PlayAudioSequencesByName.cs +++ b/CinderellaCitySimulation/Assets/Scripts/PlayAudioSequencesByName.cs @@ -26,291 +26,12 @@ public class PlayAudioSequencesByName : MonoBehaviour SpeakerParams thisSpeakerParams; bool isMaster = false; - // return speaker parameters by object name - // most audio source distances and volumes are assigned to defaults, but can be overridden here - // primarily, this is used for differentiating audio sequences (playlists) between speakers - public static SpeakerParams AssociateSpeakerParamsByName(string name) - { - string thisKeyName = ""; - SpeakerParams matchingParams = null; - - switch (name) - { - // mall - 60s70s - - // ambient chatter - case string partialName when partialName.Contains("mall-ambient-chatter-60s70s"): - - thisKeyName = "mall-ambient-chatter-60s70s"; - matchingParams = GetSpeakerParamsIfKnown(thisKeyName); - // if these params do not exist, create them and add them to the list - if (matchingParams == null) - { - matchingParams = new SpeakerParams - { - keyName = thisKeyName, - maxDistance = AudioSourceGlobals.defaultSpeakerMaxDistanceMallChatter, - speakerVolume = AudioSourceGlobals.defaultSpeakerVolumeChatter, - clipSequence = ArrayUtils.ShuffleArray(Resources.LoadAll("Audio/sfx-mall-ambient-chatter")) - }; - AudioSourceGlobals.allKnownSpeakerParams.Add(matchingParams); - } - else // but if the params exist, make sure they're updated - { - matchingParams.clipSequence = AudioSourceGlobals.isPlayerOutside ? ArrayUtils.ShuffleArray(Resources.LoadAll("Audio/sfx-exterior-ambient")) : ArrayUtils.ShuffleArray(Resources.LoadAll("Audio/sfx-mall-ambient-chatter")); - matchingParams.speakerVolume = AudioSourceGlobals.isPlayerOutside ? AudioSourceGlobals.defaultSpeakerVolumeExteriorAmbient : AudioSourceGlobals.defaultSpeakerVolumeChatter; - } - - return matchingParams; - - // fountain type 1 - case string partialName when partialName.Contains("mall-fountain-60s70s-1"): - - thisKeyName = "mall-fountain-60s70s-1"; - matchingParams = GetSpeakerParamsIfKnown(thisKeyName); - // if these params do not exist, create them and add them to the list - if (matchingParams == null) - { - matchingParams = new SpeakerParams - { - keyName = thisKeyName, - maxDistance = AudioSourceGlobals.defaultSpeakerDistanceMallFountain, - speakerVolume = AudioSourceGlobals.defaultSpeakerVolumeMallFountain, - clipSequence = ArrayUtils.ShuffleArray(Resources.LoadAll("Audio/sfx-mall-fountain-1")) - }; - AudioSourceGlobals.allKnownSpeakerParams.Add(matchingParams); - } - else // but if the params exist, make sure they're updated - { - matchingParams.speakerVolume = AudioSourceGlobals.isPlayerOutside ? 0 : AudioSourceGlobals.defaultSpeakerVolumeMallFountain; - } - return matchingParams; - - // fountain type 2 - case string partialName when partialName.Contains("mall-fountain-60s70s-2"): - - thisKeyName = "mall-fountain-60s70s-2"; - matchingParams = GetSpeakerParamsIfKnown(thisKeyName); - // if these params do not exist, create them and add them to the list - if (matchingParams == null) - { - matchingParams = new SpeakerParams - { - keyName = thisKeyName, - maxDistance = AudioSourceGlobals.defaultSpeakerDistanceMallFountain, - speakerVolume = AudioSourceGlobals.isPlayerOutside ? 0 : AudioSourceGlobals.defaultSpeakerVolumeMallFountain, - clipSequence = ArrayUtils.ShuffleArray(Resources.LoadAll("Audio/sfx-mall-fountain-2")) - }; - AudioSourceGlobals.allKnownSpeakerParams.Add(matchingParams); - } - else // but if the params exist, make sure they're updated - { - matchingParams.speakerVolume = AudioSourceGlobals.isPlayerOutside ? 0 : AudioSourceGlobals.defaultSpeakerVolumeMallFountain; - } - return matchingParams; - - // common area music - case string partialName when partialName.Contains("mall-music-60s70s"): - - thisKeyName = "mall-music-60s70s"; - matchingParams = GetSpeakerParamsIfKnown(thisKeyName); - - // if these params do not exist, create them and add them to the list - if (matchingParams == null) - { - matchingParams = new SpeakerParams - { - keyName = thisKeyName, - maxDistance = AudioSourceGlobals.defaultSpeakerMaxDistanceMallCommon, - speakerVolume = AudioSourceGlobals.defaultSpeakerVolumeMallCommon, - clipSequence = ArrayUtils.ShuffleArray(Resources.LoadAll("Audio/music-mall-60s70s")) - }; - AudioSourceGlobals.allKnownSpeakerParams.Add(matchingParams); - } - else // but if the params exist, make sure they're updated - { - matchingParams.speakerVolume = AudioSourceGlobals.isPlayerOutside ? 0 : AudioSourceGlobals.defaultSpeakerVolumeMallCommon; - } - return matchingParams; - - // stores - 60s70s - - // store - musicland - case string partialName when partialName.Contains("store-music-musicland-60s70s"): - - thisKeyName = "store-music-musicland-60s70s"; - matchingParams = GetSpeakerParamsIfKnown(thisKeyName); - // if these params do not exist, create them and add them to the list - if (matchingParams == null) - { - matchingParams = new SpeakerParams - { - keyName = thisKeyName, - maxDistance = AudioSourceGlobals.defaultSpeakerMaxDistanceStore, - speakerVolume = AudioSourceGlobals.defaultSpeakerVolumeStore, - clipSequence = ArrayUtils.ShuffleArray(Resources.LoadAll("Audio/music-store-musicland-60s70s")) - }; - AudioSourceGlobals.allKnownSpeakerParams.Add(matchingParams); - } - else // but if the params exist, make sure they're updated - { - matchingParams.speakerVolume = AudioSourceGlobals.isPlayerOutside ? 0 : AudioSourceGlobals.defaultSpeakerVolumeStore; - } - return matchingParams; - - // mall - 80s90s - - // ambient chatter - case string partialName when partialName.Contains("mall-ambient-chatter-80s90s"): - - thisKeyName = "mall-ambient-chatter-80s90s"; - matchingParams = GetSpeakerParamsIfKnown(thisKeyName); - // if these params do not exist, create them and add them to the list - if (matchingParams == null) - { - matchingParams = new SpeakerParams - { - keyName = thisKeyName, - maxDistance = AudioSourceGlobals.defaultSpeakerMaxDistanceMallChatter, - speakerVolume = AudioSourceGlobals.defaultSpeakerVolumeChatter, - clipSequence = ArrayUtils.ShuffleArray(Resources.LoadAll("Audio/sfx-mall-ambient-chatter")) - }; - AudioSourceGlobals.allKnownSpeakerParams.Add(matchingParams); - } - else // but if the params exist, make sure they're updated - { - matchingParams.clipSequence = AudioSourceGlobals.isPlayerOutside ? ArrayUtils.ShuffleArray(Resources.LoadAll("Audio/sfx-exterior-ambient")) : ArrayUtils.ShuffleArray(Resources.LoadAll("Audio/sfx-mall-ambient-chatter")); - matchingParams.speakerVolume = AudioSourceGlobals.isPlayerOutside ? AudioSourceGlobals.defaultSpeakerVolumeExteriorAmbient : AudioSourceGlobals.defaultSpeakerVolumeChatter; - } - return matchingParams; - - // common area music - case string partialName when partialName.Contains("mall-music-80s90s"): - - thisKeyName = "mall-music-80s90s"; - matchingParams = GetSpeakerParamsIfKnown(thisKeyName); - // if these params do not exist, create them and add them to the list - if (matchingParams == null) - { - matchingParams = new SpeakerParams - { - keyName = thisKeyName, - maxDistance = AudioSourceGlobals.defaultSpeakerMaxDistanceMallCommon, - speakerVolume = AudioSourceGlobals.defaultSpeakerVolumeMallCommon, - clipSequence = ArrayUtils.ShuffleArray(Resources.LoadAll("Audio/music-mall-80s90s")) - }; - AudioSourceGlobals.allKnownSpeakerParams.Add(matchingParams); - } - else // but if the params exist, make sure they're updated - { - matchingParams.speakerVolume = AudioSourceGlobals.isPlayerOutside ? 0 : AudioSourceGlobals.defaultSpeakerVolumeMallCommon; - } - return matchingParams; - - // store - consumer beauty - case string partialName when partialName.Contains("store-music-consumer-beauty-80s90s"): - - thisKeyName = "store-music-consumer-beauty-80s90s"; - matchingParams = GetSpeakerParamsIfKnown(thisKeyName); - // if these params do not exist, create them and add them to the list - if (matchingParams == null) - { - matchingParams = new SpeakerParams - { - keyName = thisKeyName, - maxDistance = AudioSourceGlobals.defaultSpeakerMaxDistanceStore, - speakerVolume = AudioSourceGlobals.defaultSpeakerVolumeStore, - clipSequence = ArrayUtils.ShuffleArray(Resources.LoadAll("Audio/music-store-consumer-beauty-80s90s")) - }; - AudioSourceGlobals.allKnownSpeakerParams.Add(matchingParams); - } - else // but if the params exist, make sure they're updated - { - matchingParams.speakerVolume = AudioSourceGlobals.isPlayerOutside ? 0 : AudioSourceGlobals.defaultSpeakerVolumeStore; - } - return matchingParams; - - // store - dolcis - case string partialName when partialName.Contains("store-music-dolcis-80s90s"): - - thisKeyName = "store-music-dolcis-80s90s"; - matchingParams = GetSpeakerParamsIfKnown(thisKeyName); - // if these params do not exist, create them and add them to the list - if (matchingParams == null) - { - matchingParams = new SpeakerParams - { - keyName = thisKeyName, - maxDistance = AudioSourceGlobals.defaultSpeakerMaxDistanceStore, - speakerVolume = AudioSourceGlobals.defaultSpeakerVolumeStore, - clipSequence = ArrayUtils.ShuffleArray(Resources.LoadAll("Audio/music-store-dolcis-80s90s")) - }; - AudioSourceGlobals.allKnownSpeakerParams.Add(matchingParams); - } - else // but if the params exist, make sure they're updated - { - matchingParams.speakerVolume = AudioSourceGlobals.isPlayerOutside ? 0 : AudioSourceGlobals.defaultSpeakerVolumeStore; - } - return matchingParams; - - // store - generic - case string partialName when partialName.Contains("store-music-generic-80s90s"): - - thisKeyName = "store-music-generic-80s90s"; - matchingParams = GetSpeakerParamsIfKnown(thisKeyName); - // if these params do not exist, create them and add them to the list - if (matchingParams == null) - { - matchingParams = new SpeakerParams - { - keyName = thisKeyName, - maxDistance = AudioSourceGlobals.defaultSpeakerMaxDistanceStore, - speakerVolume = AudioSourceGlobals.defaultSpeakerVolumeStore, - clipSequence = ArrayUtils.ShuffleArray(Resources.LoadAll("Audio/music-store-generic-80s90s")) - }; - AudioSourceGlobals.allKnownSpeakerParams.Add(matchingParams); - } - else // but if the params exist, make sure they're updated - { - matchingParams.speakerVolume = AudioSourceGlobals.isPlayerOutside ? 0 : AudioSourceGlobals.defaultSpeakerVolumeStore; - } - return matchingParams; - - // store - musicland - case string partialName when partialName.Contains("store-music-musicland-80s90s"): - - thisKeyName = "store-music-musicland-80s90s"; - matchingParams = GetSpeakerParamsIfKnown(thisKeyName); - // if these params do not exist, create them and add them to the list - if (matchingParams == null) - { - matchingParams = new SpeakerParams - { - keyName = thisKeyName, - maxDistance = AudioSourceGlobals.defaultSpeakerMaxDistanceStore, - speakerVolume = AudioSourceGlobals.defaultSpeakerVolumeStore, - clipSequence = ArrayUtils.ShuffleArray(Resources.LoadAll("Audio/music-store-musicland-80s90s")) - }; - AudioSourceGlobals.allKnownSpeakerParams.Add(matchingParams); - } - else // but if the params exist, make sure they're updated - { - matchingParams.speakerVolume = AudioSourceGlobals.isPlayerOutside ? 0 : AudioSourceGlobals.defaultSpeakerVolumeStore; - } - return matchingParams; - - default: - DebugUtils.DebugLog("Failed to associate speaker params with this speaker: " + name); - return null; - } - } - private void Awake() { // record the audio source, scripts, and speaker parameters for this script instance thisAudioSourceComponent = this.GetComponent(); thisCanToggleComponentsScript = this.GetComponent(); - thisSpeakerParams = AssociateSpeakerParamsByName(this.name); + thisSpeakerParams = ManageAudioSources.AssociateSpeakerParamsByName(this.name); InitializeAudioSourceWithSpeakerParams(thisAudioSourceComponent, thisSpeakerParams); } @@ -379,7 +100,7 @@ void Update() } // update the audio source with new speaker params if necessary - SpeakerParams newSpeakerParams = AssociateSpeakerParamsByName(this.name); + SpeakerParams newSpeakerParams = ManageAudioSources.AssociateSpeakerParamsByName(this.name); bool requireAudioSourceResume = UpdateAudioSourceWithSpeakerParams(thisAudioSourceComponent, newSpeakerParams); if (requireAudioSourceResume) @@ -393,22 +114,6 @@ void Update() //} } - // retrieve the known speaker params if it exists in the list - public static SpeakerParams GetSpeakerParamsIfKnown(string keyName) - { - SpeakerParams matchingParams = null; - - foreach (SpeakerParams knownParams in AudioSourceGlobals.allKnownSpeakerParams) - { - if (knownParams.keyName == keyName) - { - matchingParams = knownParams; - } - } - - return matchingParams; - } - public static SpeakerParams GetAmbientChatterSpeakerParamsByScene(string sceneName) { SpeakerParams matchingParams = null; @@ -418,12 +123,12 @@ public static SpeakerParams GetAmbientChatterSpeakerParamsByScene(string sceneNa case string partialName when partialName.Contains("60s70s") || partialName.Contains(SceneGlobals.experimentalSceneName): - matchingParams = AssociateSpeakerParamsByName("mall-ambient-chatter-60s70s"); + matchingParams = ManageAudioSources.AssociateSpeakerParamsByName("mall-ambient-chatter-60s70s"); return matchingParams; case string partialName when partialName.Contains("80s90s"): - matchingParams = AssociateSpeakerParamsByName("mall-ambient-chatter-80s90s"); + matchingParams = ManageAudioSources.AssociateSpeakerParamsByName("mall-ambient-chatter-80s90s"); return matchingParams; default: @@ -440,12 +145,12 @@ public static SpeakerParams GetMallMusicSpeakerParamsByScene(string sceneName) case string partialName when partialName.Contains("60s70s") || partialName.Contains(SceneGlobals.experimentalSceneName): - matchingParams = AssociateSpeakerParamsByName("mall-music-60s70s"); + matchingParams = ManageAudioSources.AssociateSpeakerParamsByName("mall-music-60s70s"); return matchingParams; case string partialName when partialName.Contains("80s90s"): - matchingParams = AssociateSpeakerParamsByName("mall-music-80s90s"); + matchingParams = ManageAudioSources.AssociateSpeakerParamsByName("mall-music-80s90s"); return matchingParams; default: @@ -633,7 +338,7 @@ void SyncAudioSources(AudioSource masterAudioSource, AudioSource slaveAudioSourc void SynchronizeAllSlavesWithMaster(AudioSource masterAudioSource) { - SpeakerParams masterParams = AssociateSpeakerParamsByName(masterAudioSource.name); + SpeakerParams masterParams = ManageAudioSources.AssociateSpeakerParamsByName(masterAudioSource.name); List slaveAudioSources = masterParams.activeSlaveAudioSources; foreach (AudioSource slaveAudiosource in slaveAudioSources) diff --git a/CinderellaCitySimulation/Assets/Scripts/ToggleChildrenComponentsByProximityToPlayer.cs b/CinderellaCitySimulation/Assets/Scripts/ToggleChildrenComponentsByProximityToPlayer.cs index dd1ecd392..bfd10d63b 100644 --- a/CinderellaCitySimulation/Assets/Scripts/ToggleChildrenComponentsByProximityToPlayer.cs +++ b/CinderellaCitySimulation/Assets/Scripts/ToggleChildrenComponentsByProximityToPlayer.cs @@ -143,7 +143,7 @@ void Update() childrenPositions[originalIndex] = distributedChildrenPositions[i]; // update the original array // if this is a speaker object, its max distance may be different - maxDistance = distributedChildrenObjects[i].name.Contains("speaker-") ? PlayAudioSequencesByName.AssociateSpeakerParamsByName(distributedChildrenObjects[i].name).maxDistance : maxDistance; + maxDistance = distributedChildrenObjects[i].name.Contains("speaker-") ? ManageAudioSources.AssociateSpeakerParamsByName(distributedChildrenObjects[i].name).maxDistance : maxDistance; // skip if there's no player camera available if (!ManageFPSControllers.FPSControllerGlobals.activeFPSControllerCamera) From fde4054030d724bccb61868c6151ac32f0b43b44 Mon Sep 17 00:00:00 2001 From: Josh Date: Fri, 2 May 2025 14:03:04 -0600 Subject: [PATCH 3/3] More cleanup --- .../Assets/Scripts/ManageAudioSources.cs | 28 ++++++++----------- .../Scripts/PlayAudioSequencesByName.cs | 20 +++++++------ 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/CinderellaCitySimulation/Assets/Scripts/ManageAudioSources.cs b/CinderellaCitySimulation/Assets/Scripts/ManageAudioSources.cs index bef853002..136a63321 100644 --- a/CinderellaCitySimulation/Assets/Scripts/ManageAudioSources.cs +++ b/CinderellaCitySimulation/Assets/Scripts/ManageAudioSources.cs @@ -23,10 +23,6 @@ public class SpeakerParams public class AudioSourceGlobals { - // keep track of the master audio source in each scene - public static AudioSource masterAudioSource60s70s; - public static AudioSource masterAudioSource80s90s; - // some audio clip sequences will change depending on // whether the player is considered outside the mall or inside public static bool isPlayerOutside; @@ -52,7 +48,7 @@ public class AudioSourceGlobals public class ManageAudioSources { // retrieve the known speaker params if it exists in the list - public static SpeakerParams GetSpeakerParamsIfKnown(string keyName) + public static SpeakerParams GetSpeakerParamsByKeyName(string keyName) { SpeakerParams matchingParams = null; @@ -83,7 +79,7 @@ public static SpeakerParams AssociateSpeakerParamsByName(string name) case string partialName when partialName.Contains("mall-ambient-chatter-60s70s"): thisKeyName = "mall-ambient-chatter-60s70s"; - matchingParams = GetSpeakerParamsIfKnown(thisKeyName); + matchingParams = GetSpeakerParamsByKeyName(thisKeyName); // if these params do not exist, create them and add them to the list if (matchingParams == null) { @@ -108,7 +104,7 @@ public static SpeakerParams AssociateSpeakerParamsByName(string name) case string partialName when partialName.Contains("mall-fountain-60s70s-1"): thisKeyName = "mall-fountain-60s70s-1"; - matchingParams = GetSpeakerParamsIfKnown(thisKeyName); + matchingParams = GetSpeakerParamsByKeyName(thisKeyName); // if these params do not exist, create them and add them to the list if (matchingParams == null) { @@ -131,7 +127,7 @@ public static SpeakerParams AssociateSpeakerParamsByName(string name) case string partialName when partialName.Contains("mall-fountain-60s70s-2"): thisKeyName = "mall-fountain-60s70s-2"; - matchingParams = GetSpeakerParamsIfKnown(thisKeyName); + matchingParams = GetSpeakerParamsByKeyName(thisKeyName); // if these params do not exist, create them and add them to the list if (matchingParams == null) { @@ -154,7 +150,7 @@ public static SpeakerParams AssociateSpeakerParamsByName(string name) case string partialName when partialName.Contains("mall-music-60s70s"): thisKeyName = "mall-music-60s70s"; - matchingParams = GetSpeakerParamsIfKnown(thisKeyName); + matchingParams = GetSpeakerParamsByKeyName(thisKeyName); // if these params do not exist, create them and add them to the list if (matchingParams == null) @@ -180,7 +176,7 @@ public static SpeakerParams AssociateSpeakerParamsByName(string name) case string partialName when partialName.Contains("store-music-musicland-60s70s"): thisKeyName = "store-music-musicland-60s70s"; - matchingParams = GetSpeakerParamsIfKnown(thisKeyName); + matchingParams = GetSpeakerParamsByKeyName(thisKeyName); // if these params do not exist, create them and add them to the list if (matchingParams == null) { @@ -205,7 +201,7 @@ public static SpeakerParams AssociateSpeakerParamsByName(string name) case string partialName when partialName.Contains("mall-ambient-chatter-80s90s"): thisKeyName = "mall-ambient-chatter-80s90s"; - matchingParams = GetSpeakerParamsIfKnown(thisKeyName); + matchingParams = GetSpeakerParamsByKeyName(thisKeyName); // if these params do not exist, create them and add them to the list if (matchingParams == null) { @@ -229,7 +225,7 @@ public static SpeakerParams AssociateSpeakerParamsByName(string name) case string partialName when partialName.Contains("mall-music-80s90s"): thisKeyName = "mall-music-80s90s"; - matchingParams = GetSpeakerParamsIfKnown(thisKeyName); + matchingParams = GetSpeakerParamsByKeyName(thisKeyName); // if these params do not exist, create them and add them to the list if (matchingParams == null) { @@ -252,7 +248,7 @@ public static SpeakerParams AssociateSpeakerParamsByName(string name) case string partialName when partialName.Contains("store-music-consumer-beauty-80s90s"): thisKeyName = "store-music-consumer-beauty-80s90s"; - matchingParams = GetSpeakerParamsIfKnown(thisKeyName); + matchingParams = GetSpeakerParamsByKeyName(thisKeyName); // if these params do not exist, create them and add them to the list if (matchingParams == null) { @@ -275,7 +271,7 @@ public static SpeakerParams AssociateSpeakerParamsByName(string name) case string partialName when partialName.Contains("store-music-dolcis-80s90s"): thisKeyName = "store-music-dolcis-80s90s"; - matchingParams = GetSpeakerParamsIfKnown(thisKeyName); + matchingParams = GetSpeakerParamsByKeyName(thisKeyName); // if these params do not exist, create them and add them to the list if (matchingParams == null) { @@ -298,7 +294,7 @@ public static SpeakerParams AssociateSpeakerParamsByName(string name) case string partialName when partialName.Contains("store-music-generic-80s90s"): thisKeyName = "store-music-generic-80s90s"; - matchingParams = GetSpeakerParamsIfKnown(thisKeyName); + matchingParams = GetSpeakerParamsByKeyName(thisKeyName); // if these params do not exist, create them and add them to the list if (matchingParams == null) { @@ -321,7 +317,7 @@ public static SpeakerParams AssociateSpeakerParamsByName(string name) case string partialName when partialName.Contains("store-music-musicland-80s90s"): thisKeyName = "store-music-musicland-80s90s"; - matchingParams = GetSpeakerParamsIfKnown(thisKeyName); + matchingParams = GetSpeakerParamsByKeyName(thisKeyName); // if these params do not exist, create them and add them to the list if (matchingParams == null) { diff --git a/CinderellaCitySimulation/Assets/Scripts/PlayAudioSequencesByName.cs b/CinderellaCitySimulation/Assets/Scripts/PlayAudioSequencesByName.cs index c43037fd2..37a437c86 100644 --- a/CinderellaCitySimulation/Assets/Scripts/PlayAudioSequencesByName.cs +++ b/CinderellaCitySimulation/Assets/Scripts/PlayAudioSequencesByName.cs @@ -24,7 +24,7 @@ public class PlayAudioSequencesByName : MonoBehaviour AudioSource thisAudioSourceComponent; CanDisableComponents thisCanToggleComponentsScript; SpeakerParams thisSpeakerParams; - bool isMaster = false; + private bool isMasterAudioSource = false; private void Awake() { @@ -38,18 +38,20 @@ private void Awake() void OnEnable() { - if (!ManageFPSControllers.FPSControllerGlobals.activeFPSController) + // check if this is the master audio source + isMasterAudioSource = thisSpeakerParams.masterAudioSource == thisAudioSourceComponent; + + // only start the audio source if there's an active FPSController + if (ManageFPSControllers.FPSControllerGlobals.activeFPSController) { - return; + StartAudioSource(); } - - StartAudioSource(); } void OnDisable() { // if this is a master audiosource, record the last-known clip and time for the next master to resume - if (thisAudioSourceComponent == thisSpeakerParams.masterAudioSource) + if (isMasterAudioSource) { thisSpeakerParams.lastKnownClip = thisAudioSourceComponent.clip; //thisSpeakerParams.lastKnownClipTime = thisAudioSourceComponent.time; @@ -76,12 +78,12 @@ void Update() { // if this is a master, check if it has active slaves // if so, we cannot disable it when it gets out of range, so except it from the proximity script - if (thisSpeakerParams.masterAudioSource == thisAudioSourceComponent && thisSpeakerParams.activeSlaveAudioSources.Count > 0) + if (isMasterAudioSource && thisSpeakerParams.activeSlaveAudioSources.Count > 0) { thisCanToggleComponentsScript.canDisableComponents = false; } // if no active slaves, allow it to be disabled when it gets out of range - else if (thisSpeakerParams.masterAudioSource == thisAudioSourceComponent && thisSpeakerParams.activeSlaveAudioSources.Count == 0) + else if (isMasterAudioSource && thisSpeakerParams.activeSlaveAudioSources.Count == 0) { thisCanToggleComponentsScript.canDisableComponents = true; } @@ -256,7 +258,7 @@ public void StartAudioSource() // set isResuming as false so when the next song plays, it starts at time 0 without errors thisSpeakerParams.isResuming = false; } - // otherwise, this must be a subordinate audiosource + // otherwise, this must be a slave audiosource else { // keep track of the active slaves