/// <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); }); } }
public void OnSingletonInit() { Log.I("AudioManager OnSingletonInit"); RegisterEvents( AudioEvent.SoundSwitch, AudioEvent.MusicSwitch, AudioEvent.VoiceSwitch, AudioEvent.SetSoundVolume, AudioEvent.SetMusicVolume, AudioEvent.SetVoiceVolume, AudioEvent.PlayMusic, AudioEvent.PlaySound, AudioEvent.PlayVoice, AudioEvent.PlayNode, AudioEvent.AddRetainAudio, AudioEvent.RemoveRetainAudioAudio ); SafeObjectPool <AudioUnit> .Instance.Init(10, 1); mMainUnit = AudioUnit.Allocate(); mMainUnit.usedCache = false; mVoiceUnit = AudioUnit.Allocate(); mVoiceUnit.usedCache = false; CheckAudioListener(); gameObject.transform.position = Vector3.zero; // 读取存储 ReadAudioSetting(); }
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; } }