/// <summary> /// Fade out the current track and fade in a new track /// </summary> /// <param name="track">The name of the music track</param> /// <param name="time">Should be greater than 0, entire fade process lasts this long</param> /// <param name="hasIntro">Does the track have an intro?</param> public void FadeMusic(AudioClip track, float time) { if (track.Equals("None")) { return; } currentTrack = track.name; musicSources[1].clip = track; musicSources[1].loop = true; AudioSource temp = musicSources[0]; musicSources[0] = musicSources[1]; musicSources[1] = temp; if (time > 0) { float stepTime = time / 2; if (fadeOutRoutine != null) { StopCoroutine(fadeOutRoutine); } fadeOutRoutine = StartCoroutine(FadeOutMusic(stepTime)); if (fadeInRoutine != null) { StopCoroutine(fadeInRoutine); } fadeInRoutine = StartCoroutine(FadeInMusicRoutine(stepTime)); } }
/// <summary> /// Fade in a new track /// </summary> /// <param name="track">The name of the music track</param> /// <param name="time">Should be greater than 0, entire fade process lasts this long</param> /// <param name="hasIntro">Does the track have an intro?</param> public void FadeMusicIn(AudioClip track, float time) { if (track.Equals("None")) { return; } currentTrack = track.ToString(); musicSources[1].clip = track; musicSources[1].loop = true; AudioSource temp = musicSources[0]; musicSources[0] = musicSources[1]; musicSources[1] = temp; if (time > 0) { if (fadeInRoutine != null) { StopCoroutine(fadeInRoutine); } fadeInRoutine = StartCoroutine(FadeInMusicRoutine(time)); } }
public void SetMusic(AudioClip _audioClip) { if (_audioClip.Equals(musicSource.clip) && musicSource.isPlaying) { return; } musicSource.clip = _audioClip; }
void Update() { if (!currentAudio.Equals(nextAudio)) { fadeAudioOut(); } else if (audioSource.volume <= maxAudio) { fadeAudioIn(); } else { timeIn = 0.0f; } //The world's audio is determined by where the player is in the dungeon and if they are in combat or not, because //of the way our dungeon is constructed this can be determined by the z-coordinate exclusively float zPosition = 0; if (musicFollowsMyZCoordinate != null) { zPosition = musicFollowsMyZCoordinate.transform.position.z; } switch (WorldController.instance.currentState) { case WorldController.GameState.IDLE: //Outside if (zPosition < caveStartZCoordinate) { nextAudio = outdoorMusic; //Cave } else if (zPosition < bossStartZCoordinate) { nextAudio = caveMusic; //Boss } else { nextAudio = caveMusic; } break; case WorldController.GameState.IN_COMBAT: //Not Boss if (zPosition < bossStartZCoordinate) { nextAudio = fightMusic; //Boss } else { nextAudio = fightMusic; } break; } }
public void PlaySong(AudioClip song) { if (song.Equals(GetComponent <AudioSource>().clip)) { return; } GetComponent <AudioSource>().Stop(); GetComponent <AudioSource>().clip = song; GetComponent <AudioSource>().Play(); }
public void PlayLoopAudio(AudioClip TheLoopAudio) { if (TheLoopAudio.Equals(this.transform.Find("PlayAudio").GetComponent <AudioSource>().clip)) { return; } this.transform.Find("PlayAudio").GetComponent <AudioSource>().clip = TheLoopAudio; this.transform.Find("PlayAudio").GetComponent <AudioSource>().loop = true; this.transform.Find("PlayAudio").GetComponent <AudioSource>().Play(); }
private void MusicaChanged(int novoIndiceMusica) //Atualiza música temporariamente { AudioClip VerificaMusica = ManagerSomSingletonJMF.staticSingleton.GetMusic(novoIndiceMusica); //Pega música if (!VerificaMusica.Equals(meuAudio.clip)) //Se a música for diferente { meuAudio.Stop(); //Para audio meuAudio.clip = VerificaMusica; //muda musica meuAudio.Play(); //toca musica } }
public static void PlayMusic(AudioClip clip) { if (!instance.musicMuted) { if (clip.Equals(instance.musicSource.clip)) { return; } instance.musicSource.clip = clip; instance.musicSource.Play(); } }
public void AtualizaAudio() //Atualiza audio após um cancelamento de edição { meuAudio.volume = GlobalPlayerPrefsJMF.Volume; //Ajusta volume meuAudio.mute = GlobalPlayerPrefsJMF.Mudo; //Ajusta mudo ou não AudioClip VerificaMusica = ManagerSomSingletonJMF.staticSingleton.GetMusic(GlobalPlayerPrefsJMF.IndiceMusica); //Pega música if (!VerificaMusica.Equals(meuAudio.clip)) //Se a música for diferente { meuAudio.Stop(); //Para audio meuAudio.clip = VerificaMusica; //muda musica meuAudio.Play(); //toca musica } }
/// <summary> /// Swaps the current music track with the new music track /// Music is played globally and does not change volume /// </summary> /// <param name="m">Index of the music</param> /// <param name="hasIntro">Does the clip have an intro portion that plays only once?</param> public void PlayMusic(AudioClip track) { if (track.Equals("None")) { return; } currentTrack = "Custom Audio File"; musicSources[0].clip = track; musicSources[0].loop = true; musicSources[0].spatialBlend = 0; musicSources[0].Play(); }
public override bool Equals(object obj) { if (obj is Data d) { if (clip == null && d.clip != null) { return(false); } return(clip.Equals(d.clip) && loop == d.loop); } else { return(false); } }
static AudioClip SaveAudioClip(AudioClip ac, string path) { if (ac == null || ac.Equals(null)) { return(null); } string dir = Path.GetDirectoryName(path); Directory.CreateDirectory(dir); SavWav.Save(path, ac); AssetDatabase.Refresh(); //EditorUtility.ExtractOggFile(ac, path); return(AssetDatabase.LoadAssetAtPath <AudioClip>(path)); }
/// <summary> /// Music is played in the scene and becomes quieter as you move away from the source /// 3D music source is independent from the main music source, they can overlap if you let them /// </summary> /// <param name="m">Index of the music</param> /// <param name="hasIntro">Does the clip have an intro portion that plays only once?</param> public void PlayMusic3D(AudioClip track, Transform trans) { if (track.Equals("None")) { return; } currentTrack = "Custom Audio File"; sourcePositions[sourcePositions.Length - 1] = trans; musicSources[2].clip = track; musicSources[2].loop = true; musicSources[2].Play(); }
void ChangeClip(AudioClip clip, float volume = 1.0f, float pitch = 1.0f) { if (clip == null || clip.Equals(Clip)) { return; } FadeOut(fadeOutDuration, () => { Clip = clip; Pitch = pitch; baseVolume = volume; FadeIn(fadeInDuration); }); }
// Update is called once per frame void Update() { //rigidbody.AddRelativeForce (new Vector3 (0f, 0f, forwardForce)); if (Input.GetKey("a")) { rigidbody.AddTorque(new Vector3(0f, turnSpeed * -1, 0f)); //transform.Rotate( new Vector3 (0f, turnSpeed*-1, 0f)); } else if (Input.GetKey("d")) { rigidbody.AddTorque(new Vector3(0f, turnSpeed, 0f)); //transform.Rotate( new Vector3 (0f, turnSpeed, 0f)); } else { rigidbody.angularVelocity = rigidbody.angularVelocity * .9f; } if (Input.GetKey("s")) { rigidbody.AddRelativeForce(new Vector3(forwardForce * 0.9f, 0f, 0f)); //transform.Rotate( new Vector3 (0f, turnSpeed, 0f)); } else if (Input.GetKey("w")) { rigidbody.AddRelativeForce(new Vector3(-forwardForce, 0f, 0f)); //transform.Rotate( new Vector3 (0f, turnSpeed, 0f)); } else { rigidbody.velocity = rigidbody.velocity * .999f; } if (Input.GetKeyDown("space")) { audio.PlayOneShot(currentShout, 1f); if (currentShout.Equals(shout1)) { currentShout = shout2; } else { currentShout = shout1; } } }
public void Play(AudioClip track) { try { if (Track.Equals(track) && Source.isPlaying) { return; } } catch (NullReferenceException ex) { Debug.LogWarning(ex); } finally { Track = track; } Source.clip = Track; Source.Play(); }
/// <summary> /// Returns an audioclip corresponding to its entry in the list; if nothing found -> returns null. Checks for NullRef /// </summary> /// <param name="clip">Checks for clip in cliplist</param> /// <returns></returns> public AudioClip FindClip(AudioClip clip) { if (clipList.Count <= 0) { return(null); } foreach (AudioClip c in clipList) { if (c == null) { return(null); //Prevent NullRef } if (clip.Equals(clip)) { return(c); // == operator checks for same instance and wouldn't work here } } return(null); //Nothing found }
private void OnAmbientSoundFinishedPlaying(AudioClip finishedSound) { int key = -1; foreach (KeyValuePair <int, AudioClip> ambientSound in ambientSounds) { if (finishedSound.Equals(ambientSound.Value)) { key = ambientSound.Key; break; } } if (key != -1) { AudioClip[] sounds = CityManager.Instance.AmbientSoundsAt(key); AudioClip sound = sounds[Random.Range(0, sounds.Length)]; AudioManager.Instance.PlaySound(sound, sound.length, 0, ambientSoundRatios[key], OnAmbientSoundFinishedPlaying); ambientSounds[key] = sound; } }
/// <summary> /// Crossfade music from the previous track to the new track specified /// </summary> /// <param name="track"></param> /// <param name="time"></param> public void CrossfadeMusic(AudioClip track, float time = 0) { if (track.Equals(null)) { return; } currentTrack = "Custom"; musicSources[1].clip = track; musicSources[1].loop = true; AudioSource temp = musicSources[0]; musicSources[0] = musicSources[1]; musicSources[1] = temp; musicSources[0].clip = track; musicSources[0].loop = true; musicSources[0].volume = 0; queueIntro = false; musicSources[0].Play(); if (time > 0) { if (fadeInRoutine != null) { StopCoroutine(fadeInRoutine); } fadeInRoutine = StartCoroutine(FadeInMusic(time)); if (fadeOutRoutine != null) { StopCoroutine(fadeOutRoutine); } fadeOutRoutine = StartCoroutine(FadeOutMusic(time)); } }
public bool Equals(Audio other) { //if (other == null) return false; // structs are never null return(deadClip.Equals(other.deadClip)); }