diff --git a/CinderellaCitySimulation/Assets/Scripts/ManageAudioSources.cs b/CinderellaCitySimulation/Assets/Scripts/ManageAudioSources.cs
new file mode 100644
index 000000000..136a63321
--- /dev/null
+++ b/CinderellaCitySimulation/Assets/Scripts/ManageAudioSources.cs
@@ -0,0 +1,344 @@
+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
+{
+ // 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();
+}
+
+public class ManageAudioSources
+{
+ // retrieve the known speaker params if it exists in the list
+ public static SpeakerParams GetSpeakerParamsByKeyName(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 = GetSpeakerParamsByKeyName(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 = GetSpeakerParamsByKeyName(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 = GetSpeakerParamsByKeyName(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 = GetSpeakerParamsByKeyName(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 = GetSpeakerParamsByKeyName(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 = GetSpeakerParamsByKeyName(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 = GetSpeakerParamsByKeyName(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 = GetSpeakerParamsByKeyName(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 = GetSpeakerParamsByKeyName(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 = GetSpeakerParamsByKeyName(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 = GetSpeakerParamsByKeyName(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/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..37a437c86 100644
--- a/CinderellaCitySimulation/Assets/Scripts/PlayAudioSequencesByName.cs
+++ b/CinderellaCitySimulation/Assets/Scripts/PlayAudioSequencesByName.cs
@@ -10,372 +10,48 @@
///
// 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;
-
- // 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(AudioSourceGlobals.mallAmbientChatter60s70sKeyName):
-
- thisKeyName = AudioSourceGlobals.mallAmbientChatter60s70sKeyName;
- 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(AudioSourceGlobals.mallMusic60s70sKeyName):
-
- thisKeyName = AudioSourceGlobals.mallMusic60s70sKeyName;
- 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(AudioSourceGlobals.mallMusic80s90sKeyName):
-
- thisKeyName = AudioSourceGlobals.mallMusic80s90sKeyName;
- 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 bool isMasterAudioSource = false;
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);
}
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;
@@ -402,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;
}
@@ -426,7 +102,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)
@@ -440,22 +116,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;
@@ -465,12 +125,12 @@ public static SpeakerParams GetAmbientChatterSpeakerParamsByScene(string sceneNa
case string partialName when partialName.Contains("60s70s") ||
partialName.Contains(SceneGlobals.experimentalSceneName):
- matchingParams = AssociateSpeakerParamsByName(AudioSourceGlobals.mallAmbientChatter60s70sKeyName);
+ matchingParams = ManageAudioSources.AssociateSpeakerParamsByName("mall-ambient-chatter-60s70s");
return matchingParams;
case string partialName when partialName.Contains("80s90s"):
- matchingParams = AssociateSpeakerParamsByName(AudioSourceGlobals.mallAmbientChatter80s90sKeyName);
+ matchingParams = ManageAudioSources.AssociateSpeakerParamsByName("mall-ambient-chatter-80s90s");
return matchingParams;
default:
@@ -487,12 +147,12 @@ public static SpeakerParams GetMallMusicSpeakerParamsByScene(string sceneName)
case string partialName when partialName.Contains("60s70s") ||
partialName.Contains(SceneGlobals.experimentalSceneName):
- matchingParams = AssociateSpeakerParamsByName(AudioSourceGlobals.mallMusic60s70sKeyName);
+ matchingParams = ManageAudioSources.AssociateSpeakerParamsByName("mall-music-60s70s");
return matchingParams;
case string partialName when partialName.Contains("80s90s"):
- matchingParams = AssociateSpeakerParamsByName(AudioSourceGlobals.mallMusic80s90sKeyName);
+ matchingParams = ManageAudioSources.AssociateSpeakerParamsByName("mall-music-80s90s");
return matchingParams;
default:
@@ -598,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
@@ -680,7 +340,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)