/// <summary> /// Provides the <paramref name="source"/> a clip from either Cavern or Unity. /// </summary> public static void TunnelClips(ref Clip source, AudioClip unity, Clip cavern, ref int lastClipHash) { if (cavern) { if (!source || lastClipHash != cavern.GetHashCode()) { source = cavern; lastClipHash = cavern.GetHashCode(); } } else if (unity) { if (!source || lastClipHash != unity.GetHashCode()) { float[] AllData = new float[unity.channels * unity.samples]; unity.GetData(AllData, 0); source = new Clip(AllData, unity.channels, unity.frequency); lastClipHash = unity.GetHashCode(); } } else if (source && lastClipHash != 0) { source = null; lastClipHash = 0; } }
public static void PlayVoice(AudioClip clip, bool loop = false, System.Action onBeganCallback = null, System.Action onEndedCallback = null) { var audioMgr = AudioManager.Instance; audioMgr.CurrentVoiceName = "voice" + clip.GetHashCode(); if (!Settings.IsVoiceOn.Value) { return; } VoicePlayer.SetOnStartListener(musicUnit => { onBeganCallback.InvokeGracefully(); VoicePlayer.SetOnStartListener(null); }); VoicePlayer.SetAudioExt(AudioManager.Instance.gameObject, clip, audioMgr.CurrentVoiceName, loop); VoicePlayer.SetOnFinishListener(musicUnit => { onEndedCallback.InvokeGracefully(); VoicePlayer.SetOnFinishListener(null); }); }
public override int GetHashCode() { if (clip == null) { return(loop.GetHashCode()); } return(clip.GetHashCode() ^ loop.GetHashCode()); }
public void Play(AudioClip clip, bool loop, float volume) { if (Target != null) { Code = clip.GetHashCode(); Target.clip = clip; Target.loop = loop; Target.volume = volume; Target.Play(); } }
public override int GetHashCode() { unchecked { var hashCode = Time.GetHashCode(); hashCode = (hashCode * 397) ^ (Animation != null ? Animation.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Transition != null ? Transition.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Sound != null ? Sound.GetHashCode() : 0); return(hashCode); } }
public bool IsCached(AudioClip audioclip) { return(this.SEClipsCache.Any(clip => { if (clip == null || clip.SEClip == null) { return false; } return clip.SEClip.GetHashCode() == audioclip.GetHashCode(); })); }
/// <summary> /// Plays a one-shot sound. /// Only allows one instance of the same sound to be played per frame. /// TODO: Allow customizeable volume stacking behavior when this happens. /// </summary> /// <returns>AudioSource used to play the sound, or null if no sound was played.</returns> /// <param name="audioClipPath">Audio clip to play.</param> public static AudioSource PlaySound(AudioClip clip, float volume = 1.0f) { Assert.IsNotNull(clip); if (clip == null) { return(null); } if (Instance.played.Contains(clip.GetHashCode())) { return(null); } Instance.played.Add(clip.GetHashCode()); Instance.PurgeSources(); AudioSource source = Instance.gameObject.AddComponent <AudioSource>(); source.outputAudioMixerGroup = staticSfxMixerGroup; source.volume = volume; source.PlayOneShot(clip); return(source); }
public static void PlayMusic(AudioClip clip, bool loop = true, System.Action onBeganCallback = null, System.Action onEndCallback = null, bool allowMusicOff = true, float volume = -1f) { var audioMgr = AudioManager.Instance; audioMgr.CurrentMusicName = "music" + clip.GetHashCode(); if (!Settings.IsMusicOn.Value && allowMusicOff) { onBeganCallback.InvokeGracefully(); onEndCallback.InvokeGracefully(); return; } Log.I(">>>>>> Start Play Music"); // TODO: 需要按照这个顺序去 之后查一下原因 // 需要先注册事件,然后再play MusicPlayer.SetOnStartListener(musicUnit => { onBeganCallback.InvokeGracefully(); if (volume < 0) { MusicPlayer.SetVolume(Settings.MusicVolume.Value); } else { MusicPlayer.SetVolume(volume); } // 调用完就置为null,否则应用层每注册一个而没有注销,都会调用 MusicPlayer.SetOnStartListener(null); }); MusicPlayer.SetAudioExt(audioMgr.gameObject, clip, audioMgr.CurrentMusicName, loop); MusicPlayer.SetOnFinishListener(musicUnit => { onEndCallback.InvokeGracefully(); // 调用完就置为null,否则应用层每注册一个而没有注销,都会调用 MusicPlayer.SetOnFinishListener(null); }); }
public AudioClip GetCachedClip(AudioClip audioclip) { IEnumerable <SE> _cachedSE = this.SEClipsCache.Where(clip => { if (clip == null || clip.SEClip == null) { return(false); } return(clip.SEClip.GetHashCode() == audioclip.GetHashCode()); }); if (_cachedSE == null || _cachedSE.Count() == 0) { return(null); } return(_cachedSE.First().SEClip); }
public AudioSource PlaySound(AudioClip clip, float volume = 1.0f) { Assert.IsNotNull(clip); int clipHash = clip.GetHashCode(); if (sources.ContainsKey(clipHash)) { return(null); } PurgeSources(); AudioSource source = gameObject.AddComponent <AudioSource>(); sources.Add(clipHash, source); source.outputAudioMixerGroup = sfxMixerGroup; source.volume = volume; source.PlayOneShot(clip); return(source); }
public void PlayMusic(string name, bool loop = true) { AudioClip clip = ResourceManager.LoadAudioClip("Sound", name); if (sourceMusic.isPlaying) { if (sourceMusic.clip.GetHashCode() == clip.GetHashCode()) { return; } } sourceMusic.clip = clip; sourceMusic.priority = 50; sourceMusic.loop = loop; if (enableMusic) { sourceMusic.Play(); } }
public override int GetHashCode() { return((_intro == null ? 0 : 2 * _intro.GetHashCode()) + (_loop == null ? 0 : _loop.GetHashCode())); }
public static AudioPlayer PlaySound(AudioClip clip, bool loop = false, Action <AudioPlayer> callBack = null, int customEventId = -1) { if (!Settings.IsSoundOn.Value) { return(null); } var soundPlayer = SafeObjectPool <AudioPlayer> .Instance.Allocate(); soundPlayer.SetAudioExt(AudioManager.Instance.gameObject, clip, "sound" + clip.GetHashCode(), loop); soundPlayer.SetVolume(Settings.SoundVolume.Value); soundPlayer.SetOnFinishListener(soundUnit => { if (callBack != null) { callBack(soundUnit); } AudioManager.Instance.RemoveSoundPlayerFromPool(soundPlayer); }); soundPlayer.customEventID = customEventId; AudioManager.Instance.AddSoundPlayer2Pool(soundPlayer); return(soundPlayer); }
public override int GetHashCode() { return((null == clip) ? 0 : clip.GetHashCode()); }