예제 #1
0
    private IEnumerator PlayMusicCoroutine(CachedSoundConfig config)
    {
        float start   = Time.time;
        float end     = start + _musicSwitchTime / 2f;
        float current = start;

        float baseVolume = _musicSource.volume;

        while (current <= end)
        {
            current = Time.time;
            float percentage = Mathf.InverseLerp(start, end, current);
            float volume     = Mathf.Lerp(baseVolume, 0, percentage);

            yield return(null);
        }

        start   = Time.time;
        end     = start + _musicSwitchTime / 2f;
        current = start;

        _musicSource.clip = config.Clip;

        while (current <= end)
        {
            current = Time.time;
            float percentage = Mathf.InverseLerp(start, end, current);
            float volume     = Mathf.Lerp(0, config.Volume, percentage);

            yield return(null);
        }

        _musicSource.volume = config.Volume;
    }
예제 #2
0
    public bool PlaySound(string soundName)
    {
        CachedSoundConfig config = Instance._sounds.Find(s => s.Name == soundName);

        if (config == null)
        {
            return(false);
        }

        return(PlaySound(config));
    }
예제 #3
0
    public bool PlayMusic(string musicName)
    {
        CachedSoundConfig config = Instance._sounds.Find(s => s.Name == musicName);

        if (config == null)
        {
            return(false);
        }

        Instance.StartCoroutine(PlayMusicCoroutine(config));
        return(true);
    }