public AudioSource AddSound(string name, GameObject obj, bool loop = false, bool removeAtEnd = true, AudioType type = AudioType.AUDIO_TYPE_EFFECT, bool notFade = false) { PlayAudioInfo info = new PlayAudioInfo(); info.Name = name; info.GameObject = obj; info.Loop = loop; info.RemoveAtEnd = removeAtEnd; info.Type = type; info.NotFade = notFade; if (type == AudioType.AUDIO_TYPE_BGM) { info.MixerGroup = EngineDelegateCore.DefaultBGMMixerGroup; info.SpatialBlend = 0; info.ReverbZoneMix = 0; } else { info.MixerGroup = EngineDelegateCore.DefaultEffectMixerGroup; info.SpatialBlend = EngineDelegateCore.DefaultEffectSpatialBlend; info.MinDistance = EngineDelegateCore.Default3DAudioMinDistance; info.MaxDistance = EngineDelegateCore.Default3DAudioMaxDistance; info.ReverbZoneMix = EngineDelegateCore.DefaultReverbZoneMix; } return(AddSound(ref info)); }
public AudioSource AddSound(ref PlayAudioInfo info) { AudioClipLoader loader = info.GameObject.AddComponent <AudioClipLoader>(); loader.ResName = info.Name; if (loader.AudioSource == null) { GameObject.DestroyImmediate(loader); return(null); } loader.AudioSource.playOnAwake = !IsMute; loader.AudioSource.loop = info.Loop; loader.AudioSource.volume = GetVolumeByType(info.Type); loader.AudioSource.mute = loader.AudioSource.volume <= 0; loader.AudioSource.outputAudioMixerGroup = info.MixerGroup; loader.AudioSource.spatialBlend = info.SpatialBlend; loader.AudioSource.minDistance = info.MinDistance; loader.AudioSource.maxDistance = info.MaxDistance; loader.AudioSource.rolloffMode = AudioRolloffMode.Linear; loader.AudioSource.dopplerLevel = 0; loader.AudioSource.bypassReverbZones = info.ReverbZoneMix == 0; loader.AudioSource.reverbZoneMix = info.ReverbZoneMix; loader.LoadSound(); if (!info.Loop && info.RemoveAtEnd) { autoDestoryAudios.Add(new AudioInfo(loader.AudioSource)); } else if (info.Loop && !IsMute && !info.NotFade) { AudioInfo ai = new AudioInfo(loader.AudioSource); ai.SetFadeIn(); ai.type = info.Type; loader.AudioSource.volume = 0; addToFadePool(ai); } return(loader.AudioSource); }