/// <summary> /// Disables the sound. /// </summary> public void DisableSound(bool IsUseAnimation = true) { if (SoundPlayer != null) { SoundPlayer.DOKill(); if (IsUseAnimation) { SoundPlayer.DOFade(0, Contains.DurationFade).OnComplete(() => { SoundPlayer.mute = true; }); ; } else { SoundPlayer.mute = true; SoundPlayer.volume = 0; } } // TODO: find all sound helper. var soundFinds = GameObject.FindObjectsOfType <SoundHelper> (); for (int i = 0; i < soundFinds.Length; i++) { // TODO: update the status of sound. soundFinds [i].UpdateStatusSound(); } }
public void Play(int loop, float volumeScale, EZAudioEnum audioEnum, Action action = null) { mAction = action; VolumeScale = volumeScale; AudioEnum = audioEnum; Audio.DOKill(); Audio.volume = VolumeScale * (AudioEnum == EZAudioEnum.MUSIC ? EZAudio.MusicVolume : EZAudio.SoundVolume); Audio.loop = loop == -1; if (loop == 1) { Debug.Log(Audio.clip.name + Audio.clip.length); Audio.PlayOneShot(Audio.clip); EZTime.Instance.InvokeOnce(EndAction, Audio.clip.length); } else { // if(EZAudioEnum.MUSIC == audioEnum) // { // float volume = Audio.volume; // Audio.volume = 0; // Audio.DOFade(volume,5).SetEase(Ease.InCirc); // } Audio.Play(); } }
/// <summary> /// Stops the music. /// </summary> public void StopMusic() { MusicPlayer.DOKill(true); MusicPlayer.DOFade(0, Contains.DurationFade).OnComplete(() => { MusicPlayer.Stop(); }); }
public void OnPointerEnter(PointerEventData eventData) { AudioHandler.DOKill(true); AudioHandler.Stop(); StartCoroutine(SongCoroutine(previewUrl)); AudioHandler.DOFade(1f, 1f); icon.DOColor(activeColor, 0.8f); }
private void ReactionTruckStart(object obj) { dangerSlider.gameObject.SetActive(false); dangerNotification.SetActive(false); backgroundMusic.DOKill(); catastrophyAudio.DOKill(); catastrophyAudio.DOFade(0, 3f); backgroundMusic.DOFade(0, 5f).OnComplete(SetCalmMusic); }
private async void LoadPreview() { var lastStage = SelectedTier.Meta.parsedStages.Last(); string path; if (lastStage.IsLocal) { path = "file://" + lastStage.Path + lastStage.Meta.music_preview.path; } else { path = lastStage.Meta.music_preview.path; } if (lastPreviewPath == path) { return; } lastPreviewPath = path; // Load var token = asyncPreviewToken = DateTime.Now; previewAudioSource.DOKill(); previewAudioSource.DOFade(0, 0.5f).SetEase(Ease.Linear); await UniTask.Delay(TimeSpan.FromSeconds(0.5f)); if (asyncPreviewToken != token) { return; } var audioClip = await Context.AssetMemory.LoadAsset <AudioClip>(path, AssetTag.PreviewMusic); if (asyncPreviewToken != token) { return; } if (State != ScreenState.Active) { return; } previewAudioSource.clip = audioClip; previewAudioSource.volume = 0; previewAudioSource.DOKill(); previewAudioSource.DOFade(Context.Player.Settings.MusicVolume, 0.5f).SetEase(Ease.Linear); previewAudioSource.loop = true; previewAudioSource.Play(); }
//--------------------------------------------------------------------------------------------------------------- private void OnMusicEnabledChanged(bool isEnabled) { //foreach (AudioSource source in activeMusicSources) //{ // source.DOKill(); // if (isEnabled) source.mute = !isEnabled; // source.DOFade(isEnabled.To01(), 0.5f).OnComplete(() => // { // source.mute = !isEnabled; // }); //} if (activeMusicSource == null) { return; } activeMusicSource.DOKill(); if (isEnabled) { activeMusicSource.mute = !isEnabled; } activeMusicSource.DOFade(isEnabled.To01(), 0.5f).OnComplete(() => { activeMusicSource.mute = !isEnabled; }); }
/// <summary> /// 播放世界音效 /// </summary> /// <param name="attachTarget">附加目标</param> /// <param name="clip">音乐剪辑</param> /// <param name="isLoop">是否循环</param> /// <param name="speed">播放速度</param> public void PlayWorldSound(GameObject attachTarget, AudioClip clip, bool isLoop = false, float speed = 1) { if (attachTarget == null || clip == null) { return; } if (WorldSources.ContainsKey(attachTarget)) { AudioSource audio = WorldSources[attachTarget]; audio.DOKill(); if (audio.isPlaying) { audio.Stop(); } audio.clip = clip; audio.loop = isLoop; audio.pitch = speed; audio.volume = WorldVolume; audio.Play(); } else { AudioSource audio = AudioToolkit.AttachAudioSource(attachTarget, WorldPriority, WorldVolume, 1, 1, Mute); WorldSources.Add(attachTarget, audio); audio.clip = clip; audio.loop = isLoop; audio.pitch = speed; audio.Play(); } }
/// <summary> /// 暂停播放指定的世界音效 /// </summary> /// <param name="attachTarget">附加目标</param> /// <param name="isGradual">是否渐进式</param> public void PauseWorldSound(GameObject attachTarget, bool isGradual = true) { if (attachTarget == null) { return; } if (WorldSources.ContainsKey(attachTarget)) { AudioSource audio = WorldSources[attachTarget]; audio.DOKill(); if (isGradual) { audio.DOFade(0, 2).OnComplete(() => { audio.Pause(); audio.volume = WorldVolume; }); } else { audio.Pause(); audio.volume = WorldVolume; } } }
void FadeInPlay(AudioSource InstanceSource, AudioClip audioClip) { InstanceSource.DOKill(); fadeTempMusic = audioClip; InstanceSource.DOFade(0, fadeInTime).SetId(3).SetUpdate(true); StartCoroutine(PlayFadeMusic()); }
public void DisableSound(bool IsUseAnimation = true) { if (_SoundAudioSource == null) { return; } _SoundAudioSource.DOKill(); if (IsUseAnimation) { _SoundAudioSource.DOFade(0, VariablesEnums.AnimationDurationFade).OnComplete(() => { _SoundAudioSource.mute = true; }).SetUpdate(true); } else { _SoundAudioSource.mute = true; _SoundAudioSource.volume = 0; } }
public void PlayLoop(AudioSource audioSource, AudioClip clip, float fadeTime) { audioSource.DOKill(); audioSource.clip = clip; audioSource.volume = 0; audioSource.Play(); audioSource.DOFade(1, fadeTime); }
public void PlaySong(int song) { if (currentSong != song) { musicSource.clip = songs[song]; musicSource.Play(); } currentSong = song; musicSource.DOKill(); musicSource.DOFade(maxVolume, 1f); }
public Tween SetVolumeSource(AudioSource audioSource, float volume, float delayFade) { if (!audioSource) { Debug.LogError("No clip received"); return(null); } if (delayFade == 0.0f) { audioSource.volume = volume; } audioSource.DOKill(true); return(audioSource.DOFade(volume, delayFade)); }
public void OnDespawned() { pool = null; #if UNITY_EDITOR gameObject.name = "<Free>"; #endif AudioSource.DOKill(false); if (AudioSource.isPlaying) { AudioSource.Stop(); } TargetTransform = null; AudioSource.clip = null; HandleID++; }
/// <summary> /// 恢复播放指定的世界音效 /// </summary> /// <param name="attachTarget">附加目标</param> /// <param name="isGradual">是否渐进式</param> public void UnPauseWorldSound(GameObject attachTarget, bool isGradual = true) { if (WorldSources.ContainsKey(attachTarget)) { AudioSource audio = WorldSources[attachTarget]; audio.DOKill(); if (isGradual) { audio.volume = 0; audio.UnPause(); audio.DOFade(WorldVolume, 2); } else { audio.UnPause(); audio.volume = WorldVolume; } } }
/// <summary> /// 播放世界音效 /// </summary> /// <param name="attachTarget">附加目标</param> /// <param name="clip">音乐剪辑</param> public void PlayWorldSound(GameObject attachTarget, AudioClip clip) { if (WorldSources.ContainsKey(attachTarget)) { AudioSource audio = WorldSources[attachTarget]; audio.DOKill(); if (audio.isPlaying) { audio.Stop(); } audio.clip = clip; audio.volume = WorldVolume; audio.Play(); } else { AudioSource audio = AudioToolkit.AttachAudioSource(attachTarget, WorldPriority, WorldVolume, 1, 1, Mute); WorldSources.Add(attachTarget, audio); audio.clip = clip; audio.Play(); } }
public void UpdatePitch(float value = 1, bool IsUseAnimation = false, float time = Contains.DurationFade, System.Action OnUpdateCompleted = null) { if (!object.ReferenceEquals(soundPlayer, null)) { soundPlayer.DOKill(); if (IsUseAnimation) { soundPlayer.DOPitch(value, time).OnComplete(() => { if (!object.ReferenceEquals(OnUpdateCompleted, null)) { OnUpdateCompleted(); } }); } else { // TODO: Stop the sound. soundPlayer.pitch = value; } } }
public void PlayAmbience() { windSource.DOKill(); windSource.DOFade(1f, 2f); }
public void StopLoop(AudioSource audioSource, float fadeTime) { audioSource.DOKill(); audioSource.DOFade(0, fadeTime); }
public void StopMusic() { _MusicAudioSource.DOKill(true); _MusicAudioSource.DOFade(0, VariablesEnums.AnimationDurationFade).OnComplete(() => { _MusicAudioSource.Stop(); }); }
//only happens if has particle system attached private void OnParticleSystemStopped() { source.DOKill(); gameObject.Destroy(); }