Esempio n. 1
0
    public void SetBGMVolume(float volume)
    {
        if (bgmVolume == volume)
        {
            return;
        }

        bgmVolume = volume;

        for (int type = 0; type < soundTypeCount; type++)
        {
            Define.SoundType soundType = (Define.SoundType)type;

            if (!playingBGM.ContainsKey(soundType))
            {
                continue;
            }

            if (playingBGM[soundType].fadingVolume == 0f)
            {
                playingBGM[soundType].source.volume = volume;
            }
            else
            {
                playingBGM[soundType].source.volume = playingBGM[soundType].fadingVolume;
            }
        }
    }
Esempio n. 2
0
 public void StopBGM(Define.SoundType soundType)
 {
     if (playingBGM.ContainsKey(soundType))
     {
         playingBGM[soundType].source.Stop();
     }
 }
Esempio n. 3
0
 public void AllPasueSound()
 {
     for (int type = 0; type < soundTypeCount; type++)
     {
         Define.SoundType soundType = (Define.SoundType)type;
         PauseSound(soundType);
     }
 }
Esempio n. 4
0
        public SoundPack(Define.SoundType type, AudioSource source)
        {
            this.type   = type;
            this.source = source;

            fadingVolume = 0f;
            isPause      = false;
        }
Esempio n. 5
0
 public void FadeInAndPlayBGM(Define.SoundType soundType, float time = 1f)
 {
     PlayBGM(soundType);
     if (playingBGM.ContainsKey(soundType))
     {
         StartCoroutine(Fade(playingBGM[soundType], time, true));
     }
 }
Esempio n. 6
0
 public void FadeOutAndStopBGM(Define.SoundType soundType, float time = 1f)
 {
     if (playingBGM.ContainsKey(soundType))
     {
         StartCoroutine(Fade(playingBGM[soundType], time, false, () =>
         {
             StopBGM(soundType);
         }));
     }
 }
Esempio n. 7
0
 public void ContinueBGM(Define.SoundType soundType)
 {
     if (playingBGM.ContainsKey(soundType))
     {
         if (!playingBGM[soundType].source.isPlaying)
         {
             playingBGM[soundType].source.UnPause();
         }
     }
 }
Esempio n. 8
0
    public void AllContinueSound()
    {
        for (int type = 0; type < soundTypeCount; type++)
        {
            Define.SoundType soundType = (Define.SoundType)type;
            if (!playingAudio.ContainsKey(soundType))
            {
                continue;
            }

            ContinueSound(soundType);
        }
    }
Esempio n. 9
0
    public void ContinueAllBGM()
    {
        for (int type = 0; type < soundTypeCount; type++)
        {
            Define.SoundType soundType = (Define.SoundType)type;
            if (!playingBGM.ContainsKey(soundType))
            {
                continue;
            }

            ContinueBGM(soundType);
        }
    }
Esempio n. 10
0
    public void StopSound(Define.SoundType soundType)
    {
        if (playingAudio.ContainsKey(soundType))
        {
            for (int i = playingAudio[soundType].Count - 1; i >= 0; i--)
            {
                AudioSource source = playingAudio[soundType][i].source;
                playingAudio[soundType][i].source.Stop();
                playingAudio[soundType].RemoveAt(i);

                ReturnAudioSource(source);
            }
        }
    }
Esempio n. 11
0
    public void AllStopSound()
    {
        for (int type = 0; type < soundTypeCount; type++)
        {
            Define.SoundType soundType = (Define.SoundType)type;
            if (!playingAudio.ContainsKey(soundType))
            {
                continue;
            }

            StopSound(soundType);

            playingAudio[soundType].Clear();
        }
    }
Esempio n. 12
0
    public void ContinueSound(Define.SoundType soundType)
    {
        if (playingAudio.ContainsKey(soundType))
        {
            for (int i = 0, max = playingAudio[soundType].Count; i < max; i++)
            {
                if (!playingAudio[soundType][i].source.isPlaying)
                {
                    playingAudio[soundType][i].source.UnPause();
                }

                playingAudio[soundType][i].SetPause(false);
            }
        }
    }
Esempio n. 13
0
    private AudioClip LoadAudioClip(Define.SoundType type, string path)
    {
        switch (type)
        {
        case Define.SoundType.BGM:
            return(GameManager.Resource.Load <AudioClip>($"SoundSources/BGM/{path}"));

        case Define.SoundType.FX:
            return(GameManager.Resource.Load <AudioClip>($"SoundSources/FX/{path}"));

        case Define.SoundType.LoopFX:
            return(GameManager.Resource.Load <AudioClip>($"SoundSources/FX/{path}"));
        }

        return(null);
    }
Esempio n. 14
0
    public async Task PlayAsync(Define.SoundType type, string path, float duration, float volume = 1f)
    {
        if (LoadAudioAndClip(type, path, out var audio, out var source) == false)
        {
            return;
        }

        if (audio.isPlaying)
        {
            await DoTransition(audio, source, duration, volume);
        }
        else
        {
            await DoPlay(audio, source, duration, volume);
        }
    }
Esempio n. 15
0
    public void PauseSound(Define.SoundType soundType)
    {
        if (!playingAudio.ContainsKey(soundType))
        {
            return;
        }

        for (int i = 0, max = playingAudio[soundType].Count; i < max; i++)
        {
            if (playingAudio[soundType][i].source.isPlaying)
            {
                playingAudio[soundType][i].source.Pause();
            }

            playingAudio[soundType][i].SetPause(true);
        }
    }
Esempio n. 16
0
    public void PlaySound(Define.SoundType soundType)
    {
        if (soundStore.ContainsKey(soundType))
        {
            if (!playingAudio.ContainsKey(soundType))
            {
                playingAudio.Add(soundType, new List <SoundPack>());
            }

            AudioSource source = GetAudioSource();
            playingAudio[soundType].Add(new SoundPack(soundType, source));

            source.clip   = soundStore[soundType];
            source.volume = soundVolume;
            source.loop   = false;
            source.Play();
        }
    }
Esempio n. 17
0
 private void Update()
 {
     for (int type = 0; type < soundTypeCount; type++)
     {
         Define.SoundType soundType = (Define.SoundType)type;
         if (playingAudio.ContainsKey(soundType))
         {
             for (int i = playingAudio[soundType].Count - 1; i >= 0; i--)
             {
                 if (!playingAudio[soundType][i].source.isPlaying && !playingAudio[soundType][i].isPause)
                 {
                     ReturnAudioSource(playingAudio[soundType][i].source);
                     playingAudio[soundType].RemoveAt(i);
                 }
             }
         }
     }
 }
Esempio n. 18
0
    public void Play(Define.SoundType type, string path, float volume = 1f)
    {
        AudioClip source = null;

        switch (type)
        {
        case Define.SoundType.BGM:
            source = GameManager.Resource.Load <AudioClip>($"SoundSources/BGM/{path}");
            if (source == null)
            {
                Debug.Log($"'{path}' 사운드 정보를 찾을 수 없습니다. Resources/SoundSources/BGM 폴더를 확인해주세요.");
                return;
            }
            audio[(int)type].clip   = source;
            audio[(int)type].volume = volume;
            audio[(int)type].Play();
            break;

        case Define.SoundType.FX:
            source = GameManager.Resource.Load <AudioClip>($"SoundSources/FX/{path}");
            if (source == null)
            {
                Debug.Log($"'{path}' 사운드 정보를 찾을 수 없습니다. Resources/SoundSources/FX 폴더를 확인해주세요.");
                return;
            }
            audio[(int)type].PlayOneShot(source, volume);
            break;

        case Define.SoundType.LoopFX:
            source = GameManager.Resource.Load <AudioClip>($"SoundSources/FX/{path}");
            if (source == null)
            {
                Debug.Log($"'{path}' 사운드 정보를 찾을 수 없습니다. Resources/SoundSources/FX 폴더를 확인해주세요.");
                return;
            }
            audio[(int)type].clip   = source;
            audio[(int)type].volume = volume;
            audio[(int)type].Play();
            break;
        }
    }
Esempio n. 19
0
    public void Play(Define.SoundType type, string path, float volume = 1f)
    {
        if (LoadAudioAndClip(type, path, out var audio, out var source) == false)
        {
            return;
        }

        switch (type)
        {
        case Define.SoundType.BGM:
        case Define.SoundType.LoopFX:
            audio.clip   = source;
            audio.volume = volume;
            audio.Play();
            break;

        case Define.SoundType.FX:
            audio.PlayOneShot(source, volume);
            break;
        }
    }
Esempio n. 20
0
    private bool LoadAudioAndClip(Define.SoundType type, string path, out AudioSource audio, out AudioClip clip)
    {
        audio = null; clip = null;

        if ((int)type >= audios.Length)
        {
            Debug.LogError($"유효하지 않은 타입입니다: {type}");
            return(false);
        }

        audio = audios[(int)type];
        clip  = LoadAudioClip(type, path);

        if (clip == null)
        {
            Debug.LogError($"'{type}' 타입의 '{path}' 사운드 정보를 찾을 수 없습니다. Resources/SoundSources/ 폴더를 확인해주세요.");
            return(false);
        }

        return(true);
    }
Esempio n. 21
0
    public void PlayBGM(Define.SoundType soundType, bool bLoop = true)
    {
        if (soundStore.ContainsKey(soundType))
        {
            if (!playingBGM.ContainsKey(soundType))
            {
                playingBGM.Add(soundType, new SoundPack(soundType, GetAudioSource()));
            }

            if (playingBGM[soundType].source.isPlaying)
            {
                return;
            }

            AudioClip source = soundStore[soundType];

            playingBGM[soundType].source.clip   = source;
            playingBGM[soundType].source.volume = bgmVolume;
            playingBGM[soundType].source.loop   = bLoop;
            playingBGM[soundType].source.Play();
        }
    }
Esempio n. 22
0
    public void SetSoundVolume(float volume)
    {
        if (soundVolume == volume)
        {
            return;
        }

        soundVolume = volume;

        for (int type = 0; type < soundTypeCount; type++)
        {
            Define.SoundType soundType = (Define.SoundType)type;

            if (!playingAudio.ContainsKey(soundType))
            {
                continue;
            }

            for (int i = 0, max = playingAudio[soundType].Count; i < max; i++)
            {
                playingAudio[soundType][i].source.volume = volume;
            }
        }
    }
Esempio n. 23
0
 public void Stop(Define.SoundType type)
 {
     audio[(int)type].Stop();
 }