/// <summary> /// Returns localised audio /// </summary> public AudioRecordSettings GetAudioClip(SoundSettingsKey key) { string clipName = SoundSettingsValue.Mapping[key]; if (string.IsNullOrEmpty(clipName)) { Debug.Log($"[AUDIO] Skipping sound: {key}"); return(null); } if (!sounds.ContainsKey(currentLanguage)) { Debug.LogError($"[LOCALISATION] Missing locale: {currentLanguage}"); return(null); } SoundSettings soundSettings = sounds[currentLanguage]; if (!soundSettings.CachedRecords.ContainsKey(clipName)) { Debug.LogWarning($"[AUDIO] Missing sound: {key}"); return(null); } return(soundSettings.CachedRecords[clipName]); }
public void SetupWithAnswer(bool correct) { tickImage.SetActive(correct); crossImage.SetActive(!correct); sound = correct ? SoundSettingsKey.LevelNumberUpdate : SoundSettingsKey.CrossAppears; checkBoxAnimator.Rebind(); }
/// <summary> /// Returns localised audio /// </summary> public AudioRecordSettings GetAudioClip(SoundSettingsKey key) { string clipName = SoundSettingsValue.Mapping[key]; if (string.IsNullOrEmpty(clipName)) { Debug.Log($"[AUDIO] Skipping sound: {key}"); return(null); } SoundSettings soundSettings = settings.Sound[0]; if (!soundSettings.CachedRecords.ContainsKey(clipName)) { Debug.LogWarning($"[AUDIO] Missing sound: {key}"); return(null); } return(soundSettings.CachedRecords[clipName]); }
/// <summary> /// Returns localised audio /// </summary> /// <param name="twoNinethPitchCount">0 is pitch=1.00, 9 is pitch=3.00, -5 is pitch=-0.11, -4 is pitch=0.11</param> public void PlayAudioClip(SoundSettingsKey key, int twoNinethPitchCount = 0) { AudioRecordSettings record = GetAudioClip(key); if (record == null) { return; } AudioSource source; switch (record.SourceGroup) { case AudioSourceGroup.BackgroundAmbient: if (currentBackgroundAmbientSoundKey == key) { return; } source = backgroundAdditionalSource; currentBackgroundAmbientSoundKey = key; break; case AudioSourceGroup.Background: if (currentBackgroundSoundKey == key) { return; } source = backgroundSource; currentBackgroundSoundKey = key; break; case AudioSourceGroup.Event: source = eventSource; break; case AudioSourceGroup.Notification: source = notificationSource; break; case AudioSourceGroup.Expendable: source = expandableSource; break; default: #if UNITY_EDITOR if (showSoundLogs) { Debug.LogWarning( $"[AUDIO] Cannot find '{record.SourceGroup}' " + $"source group for '{key}' " + $"= '{SoundSettingsValue.Mapping[key]}'"); } #endif return; } if (record.ShouldNotPlayInARow && source.isPlaying) { bool isSameClip = source.clip == record.AudioClip; bool isSamePitch = Mathf.Approximately(source.pitch, 1f + 2f * twoNinethPitchCount / 9f); if (isSameClip && isSamePitch) { // do not play the same sound return; } } source.clip = record.AudioClip; source.pitch = 1f + 2f * twoNinethPitchCount / 9f; if (source.enabled) { if (record.CanBeInterrupted) { if (record.SourceGroup == AudioSourceGroup.Background || record.SourceGroup == AudioSourceGroup.BackgroundAmbient) { StartCoroutine(fadeSound(source, fadeInOutTime)); } else { // stop old and play new source.Stop(); source.Play(); } } else { // play new async SoundFactory.Instance.PlayAsCopy(source); } #if UNITY_EDITOR if (showSoundLogs) { Debug.Log( $"[AUDIO] Playing sound '{key}' " + $"= '{SoundSettingsValue.Mapping[key]}'" + $" as '{source.name}'"); } #endif } }