/
arti4
/
CourseWork
Обзор
Документация
Войти
/
arti4
/
CourseWork
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Scriptes/AudioManager.cs
109 строк
3 KB
arti4
Загрузить файлы в «»
01 июн 2025, 11:56
01 июн 2025, 11:56
6a254d9
Код
Авторство
О чём код?
using UnityEngine; using UnityEngine.Audio; public class AudioManager : MonoBehaviour { public AudioMixer audioMixer; public AudioSource musicAudioSource; private static AudioManager instance; private void Update() { if (instance == null) { instance = this; DontDestroyOnLoad(gameObject); } else { Destroy(gameObject); } if (musicAudioSource == null) { musicAudioSource = GetComponent<AudioSource>(); } } //��������� ��������� public void SetVolume(float volume) { if (volume == 0f) { audioMixer.SetFloat("Game", -80f); } else { audioMixer.SetFloat("Game", Mathf.Log10(volume) * 20f); } PlayerPrefs.SetFloat("Game", volume); PlayerPrefs.Save(); } //��������� ��������� ������ public void SetMusicVolume(float volume) { if (volume == 0f) { audioMixer.SetFloat("Music", -80f); } else { audioMixer.SetFloat("Music", Mathf.Log10(volume) * 20f); } PlayerPrefs.SetFloat("Music", volume); PlayerPrefs.Save(); } //����� ������ public void PauseAudio() { if (musicAudioSource.isPlaying) { musicAudioSource.Pause(); } } //������������� ������ public void ResumeAudio() { if (!musicAudioSource.isPlaying) { musicAudioSource.UnPause(); // ������������ ������ } } //����� �������� public void PauseAudioEffects() { AudioSource[] audioSources = Object.FindObjectsByType<AudioSource>(FindObjectsSortMode.None); foreach (AudioSource audioSource in audioSources) { if (audioSource != musicAudioSource && audioSource.isPlaying) { audioSource.Pause(); } } } // ������������� �������� public void ResumeAudioEffects() { AudioSource[] audioSources = Object.FindObjectsByType<AudioSource>(FindObjectsSortMode.None); foreach (AudioSource audioSource in audioSources) { if (audioSource != musicAudioSource && !audioSource.isPlaying) { audioSource.UnPause(); } } } //���������� ��������� public void MuteGameSounds() { audioMixer.SetFloat("Game", -80f); //������ ������ } //������� ��������� public void UnmuteGameSounds() { float savedVolume = PlayerPrefs.GetFloat("Game", 1f); SetVolume(savedVolume); } }