public static void PlayMusic(string musicName, bool loop = true, float fadeInTime = 0f) { if (!MgrData.GetBool(MgrData.appSettingsName, "XLAF.music", true)) { return; } if (musicName.IndexOf(".") < 0) { XLAFInnerLog.Warning("You must use musicName's extension, for example \"click.mp3\""); return; } AudioClip clip = Resources.Load <AudioClip> (_GetAudioSource(musicName.Split(new char[] { '.' }) [0])); musicSource.loop = loop; musicSource.clip = clip; musicSource.Play(); if (fadeInTime <= 0f) { musicSource.volume = maxMusicVolume; } else { _FadeInOutVolume(musicSource, fadeInTime, 0, maxMusicVolume); } }
/// <summary> /// Plaies the sound. /// </summary> /// <param name="soundName">Sound name. (with ext e.g. click.mp3)</param> /// <param name="valume">Valume.</param> public static void PlaySound(string soundName, float valume) { if (!MgrData.GetBool(MgrData.appSettingsName, "XLAF.sound", true)) { return; } if (soundName.IndexOf(".") < 0) { XLAFInnerLog.Warning("You must use soundName's extension, for example \"click.mp3\""); return; } #if UNITY_ANDROID && !UNITY_EDITOR int soundId = 0; if (androidSoundIds.TryGetValue(soundName, out soundId)) { audioCenter.Call("PlaySound", soundId, valume); } #else AudioClip clip = Resources.Load <AudioClip> (_GetAudioSource(soundName.Split(new char[] { '.' }) [0])); if (clip != null) { soundSource.volume = valume; soundSource.PlayOneShot(clip); } #endif }