Пример #1
0
        private static AudioAsset GetEmptyAudioAssetFromSFXList(GameObject owner)
        {
            AudioAsset        au      = null;
            List <AudioAsset> sfxList = null;

            if (sfxDic.ContainsKey(owner))
            {
                sfxList = sfxDic[owner];
                if (sfxList.Count > 0)
                {
                    for (int i = 0; i < sfxList.Count; i++)
                    {
                        if (sfxList[i].PlayState == AudioPlayState.Stop)
                        {
                            au = sfxList[i];
                        }
                    }
                }
            }
            else
            {
                sfxList = new List <AudioAsset>();
                sfxDic.Add(owner, sfxList);
            }
            if (au == null)
            {
                au = AudioManager.CreateAudioAsset(owner, true);
                sfxList.Add(au);
            }

            return(au);
        }
Пример #2
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;
        }
Пример #3
0
        public static AudioAsset CreateAudioAsset(GameObject gameObject, bool is3D)
        {
            AudioAsset au = new AudioAsset();

            au.audioSource = gameObject.AddComponent <AudioSource>();
            au.audioSource.spatialBlend = is3D ? 1 : 0;
            return(au);
        }
Пример #4
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();
        }
Пример #5
0
        private static AudioAsset GetEmptyAudioAssetFromSFXList()
        {
            AudioAsset au = null;

            if (sfxList.Count > 0)
            {
                for (int i = 0; i < sfxList.Count; i++)
                {
                    if (sfxList[i].PlayState == AudioPlayState.Stop)
                    {
                        au = sfxList[i];
                    }
                }
            }
            if (au == null)
            {
                au = AudioManager.CreateAudioAsset(audioObject, false);
                sfxList.Add(au);
            }
            return(au);
        }