Exemplo n.º 1
0
        public static IEnumerator EaseToChangeVolume(AudioAsset au, string name, bool isLoop, float volumeScale, float delay, float fadeTime)
        {
            AudioClip ac     = AudioManager.GetAudioClip(name);
            float     target = au.Volume;

            if (au.audioSource && au.IsPlay)
            {
                while (target > 0f)
                {
                    float speed = Volume * volumeScale / fadeTime;
                    target    = target - speed * Time.fixedDeltaTime;
                    au.Volume = target;
                    yield return(new WaitForFixedUpdate());
                }
                au.Stop();
            }
            au.assetName        = name;
            au.audioSource.clip = ac;
            au.audioSource.loop = isLoop;
            au.Play(delay);
            target = 0;
            yield return(new WaitForSeconds(delay));

            while (target < Volume * volumeScale)
            {
                float speed = Volume * volumeScale / fadeTime * 1.2f;
                target    = target + speed * Time.fixedDeltaTime;
                au.Volume = target;
                yield return(new WaitForFixedUpdate());
            }
            au.VolumeScale = volumeScale;
        }
Exemplo n.º 2
0
        public static void PlaySFX(string name, float volumeScale = 1f, float delay = 0f)
        {
            AudioClip  ac = AudioManager.GetAudioClip(name);
            AudioAsset aa = GetEmptyAudioAssetFromSFXList();

            aa.audioSource.clip = ac;
            aa.Play(delay);
            aa.VolumeScale = volumeScale;
            ClearMoreAudioAsset();
        }