/// <summary> /// 播放音效 /// </summary> void PlaySound(AudioSoundMsg soundMsg) { if (SoundOn.Value) { AudioUnit unit = SafeObjectPool <AudioUnit> .Instance.Allocate(); unit.SetOnStartListener(delegate(AudioUnit soundUnit) { soundMsg.onSoundBeganCallback.InvokeGracefully(); unit.SetVolume(soundMsg.Volume); unit.SetOnStartListener(null); }); unit.SetAudio(gameObject, soundMsg.SoundName, false); unit.SetOnFinishListener(delegate(AudioUnit soundUnit) { soundMsg.onSoundEndedCallback.InvokeGracefully(); unit.SetOnFinishListener(null); }); } }
private void SetVolume(AudioUnit audioUnit, VolumeLevel volumeLevel) { switch (volumeLevel) { case VolumeLevel.Max: audioUnit.SetVolume(1.0f); break; case VolumeLevel.Normal: audioUnit.SetVolume(0.5f); break; case VolumeLevel.Min: audioUnit.SetVolume(0.2f); break; } }