123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- public class AudioLabel
- {
- public static string ClickButton = "BtnClip";
- public static string UseSkill = "SkillClip";
- public static string Error = "ErrorClip";
- public static string Minigame_DropAward = "DropClip";
- public static string Close = "CloseClip";
- public static string PlantFlower = "FlowerClip";
- public static string Bubble = "BubbleClip";
- public static string GetCurrent = "CurrentClip";
- public static string MinigameEnd = "MiniEndClip";
- }
- public class AudioManager : Regist
- {
- #region Config
- public static AudioManager Instance;
- public static bool AudioOn = true;
- public static bool MusicOn = true;
- public static Coroutine CoroThemeMusic;
- public static Coroutine CoroMiniGameMusic;
- public static Coroutine CoroPartyThemeMusic;
- public static AudioSource ClipAudioSource;
- public static AudioSource MinigameAudio;
- public static AudioSource GardenThemeAudio;
- public static AudioSource PartyThemeAudio;
- #endregion
- public override void InstantiatePrefabs()
- {
- ResourceManager.Get(ResourceLabel.Music, Folder.Audio, true, transform, true, ObjType.Music);
- }
- public override void FirstInit()
- {
- Instance = this;
- #region MusicMini
- TweenAudio tween = MinigameAudio.CreateTweenAudio(1, 2f, true, true, Curve.EaseOutQuad);
- tween.OnForwardStart += () =>
- {
- if (MusicOn)
- {
- MinigameAudio.Play();
- CoroMiniGameMusic = StartCoroutine(LoopPlayback(MinigameAudio));
- }
- };
- tween.OnBackwardStart += () =>
- {
- if (MusicOn)
- {
- StopCoroutine(CoroThemeMusic);
- }
- };
- #endregion
- #region MusicTheme
- tween = GardenThemeAudio.CreateTweenAudio(1, 2f, true, true, Curve.EaseOutQuad);
- tween.OnForwardStart += () =>
- {
- if (MusicOn)
- {
- GardenThemeAudio.Play();
- CoroThemeMusic = StartCoroutine(LoopPlayback(GardenThemeAudio));
- }
- };
- tween.OnBackwardStart += () =>
- {
- if (MusicOn)
- {
- StopCoroutine(CoroThemeMusic);
- }
- };
- #endregion
- #region MusicPartyTheme
- tween = PartyThemeAudio.CreateTweenAudio(1, 2f, true, true, Curve.EaseOutQuad);
- tween.OnForwardStart += () =>
- {
- if (MusicOn)
- {
- PartyThemeAudio.Play();
- CoroPartyThemeMusic = StartCoroutine(LoopPlayback(PartyThemeAudio));
- }
- };
- tween.OnBackwardStart += () =>
- {
- if (MusicOn)
- {
- StopCoroutine(CoroPartyThemeMusic);
- }
- };
- #endregion
- if (!MusicOn)
- {
- ResourceManager.SetActive(CanvasLabel.L_MusicOn, false);
- ResourceManager.SetActive(CanvasLabel.L_MusicOff, true);
- }
- if (!AudioOn)
- {
- ResourceManager.SetActive(CanvasLabel.L_AudioOn, false);
- ResourceManager.SetActive(CanvasLabel.L_AudioOff, true);
- }
- }
- public override void RegistReference()
- {
- AudioSource[] audioSources = ResourceManager.Gets<AudioSource>(ResourceLabel.Music);
- ClipAudioSource = audioSources[2];
- MinigameAudio = audioSources[1];
- GardenThemeAudio = audioSources[0];
- PartyThemeAudio = audioSources[3];
- }
- public static void LoadPrefs()
- {
- AudioOn = PlayerPrefs.GetInt(Lib.AudioPrefs, 1).ToBool();
- MusicOn = PlayerPrefs.GetInt(Lib.MusicPrefs, 1).ToBool();
- }
- public static void SetLogoVolume()
- {
- if (!AudioOn || !MusicOn)
- {
- GameObject.Find(ResourceLabel.LOGO0005).GetComponent<AudioSource>().volume = 0;
- }
- }
- public static void PlayClip(string clipName)
- {
- if (AudioOn)
- {
- AudioClip audioClip = ResourceManager.Load<AudioClip>(clipName, Folder.Audio);
- ClipAudioSource.PlayOneShot(audioClip);
- }
- }
- public void MusicSwitch()
- {
- if (MusicOn)
- {
- MusicOn = false;
- ResourceManager.SetActive(CanvasLabel.L_MusicOn, false);
- ResourceManager.SetActive(CanvasLabel.L_MusicOff, true);
-
- MinigameAudio.Pause();
- GardenThemeAudio.Pause();
- PartyThemeAudio.Pause();
- PlayerPrefs.SetInt(Lib.MusicPrefs, 0);
- }
- else
- {
- MusicOn = true;
- ResourceManager.SetActive(CanvasLabel.L_MusicOn, true);
- ResourceManager.SetActive(CanvasLabel.L_MusicOff, false);
- MinigameAudio.UnPause();
- PartyThemeAudio.UnPause();
- if (GardenThemeAudio.isPlaying)
- {
- GardenThemeAudio.UnPause();
- }
- else
- {
- GardenThemeAudio.TweenReForAudio();
- }
- PlayerPrefs.SetInt(Lib.MusicPrefs, 1);
- }
- }
- public void AudioSwitch()
- {
- if (AudioOn)
- {
- AudioOn = false;
- ResourceManager.SetActive(CanvasLabel.L_AudioOn, false);
- ResourceManager.SetActive(CanvasLabel.L_AudioOff, true);
- PlayerPrefs.SetInt(Lib.AudioPrefs, 0);
- }
- else
- {
- AudioOn = true;
- ResourceManager.SetActive(CanvasLabel.L_AudioOn, true);
- ResourceManager.SetActive(CanvasLabel.L_AudioOff, false);
- PlayerPrefs.SetInt(Lib.AudioPrefs, 1);
- }
- }
- private float LoopDelay = 1.5f;
- public IEnumerator LoopPlayback(AudioSource audioSource)
- {
- while (true)
- {
- Mark: yield return null;
- while (Manager.InBackground)
- {
- goto Mark;
- }
- while (!audioSource.enabled)
- {
- goto Mark;
- }
-
- while (audioSource.isPlaying)
- {
- goto Mark;
- }
- while (!MusicOn)
- {
- goto Mark;
- }
- yield return new WaitForSeconds(LoopDelay);
- audioSource.Play();
- }
- }
- }
|