public bool IsPlaying(string clipName) { AudioItem audioItem = audioDictionary.Find(a => a.name == clipName); if (audioItem != null) { Transform audioObject = tRoot.FindChild(audioItem.name); if (!audioItem.loop && audioItem.isUnique) { audioObject = tRoot.FindChild(audioItem.name + "(Clone)"); } if (audioObject != null) { AudioSource audioComponent = audioObject.GetComponent <AudioSource>(); if (audioComponent.isPlaying) { return(true); } else { return(false); } } } return(false); }
public void SetTagSpawn(string clipName, Transform tag) { if (!string.IsNullOrEmpty(clipName) && tag != null) { AudioItem audioItem = audioDictionary.Find(a => a.name == clipName); audioItem.tagSpawn = tag; } }
public bool AudioExists(string clipName) { AudioItem audioItem = audioDictionary.Find(a => a.name == clipName); if (audioItem != null) { return(true); } return(false); }
public void StopFadeOut(string clipName, float seconds) { AudioItem audioItem = audioDictionary.Find(a => a.name == clipName); AudioSource audioSource = GetAudioSource(audioItem.name); StartCoroutine(audioItem.FadeOut(audioSource, seconds)); if (audioSource.volume == 0) { audioSource.Stop(); } }
/// <summary> /// Detiene la reproduccion de una pista cuyo nombre en el diccionario sea igual a la especificada en un GameObject. /// </summary> /// <param name="clipName">Nombre del item en el diccionario.</param> public void Stop(string clipName) { AudioItem audioItem = audioDictionary.Find(a => a.name == clipName); if (audioItem != null) { if (!audioItem.loop) { clipName = audioItem.name + "(Clone)"; } tRoot.FindChild(clipName).gameObject.SetActive(false); } }
public void PlayFadeIn(string clipName, float seconds) { AudioItem audioItem = audioDictionary.Find(a => a.name == clipName); if (!IsPlaying(clipName)) { Play(audioItem.name); } AudioSource audioSource = GetAudioSource(audioItem.name); StartCoroutine(audioItem.FadeIn(audioSource, seconds)); if (audioSource.volume >= audioItem.VolumeProperty) { //Debug.Log("PlayFadeIn Completa"); } }
/// <summary> /// Agrega un componente AudioSource en un GameObject especificado. /// </summary> /// <param name="audioSpawned">GameObject al cual se le agregara el componente AudioSource.</param> /// <param name="audioItem">Objeto AudioItem que contiene la informacion para crear el componente AudioSource.</param> /// <param name="inRoot"></param> /// <returns></returns> private AudioSource AddAudioSource(GameObject audioSpawned, AudioItem audioItem, bool inRoot = true) { AudioSource audioSource = audioSpawned.AddComponent <AudioSource>(); audioSource.clip = audioItem.audioClip; audioSource.mute = audioItem.mute; audioSource.bypassEffects = audioItem.bypassEffects; audioSource.bypassListenerEffects = audioItem.bypassListenerEffects; audioSource.bypassReverbZones = audioItem.bypassReverbZones; audioSource.playOnAwake = audioItem.playOnAwake; audioSource.loop = audioItem.loop; audioSource.pitch = audioItem.pitch; audioSource.volume = audioItem.volume; audioSource.priority = audioItem.priority; audioSource.dopplerLevel = audioItem.dopplerLevel; audioSource.minDistance = audioItem.minDistance; audioSource.spatialBlend = audioItem.spatialBlend; audioSource.panStereo = audioItem.stereoPan; audioSource.spread = audioItem.spread; audioSource.maxDistance = audioItem.maxDistance; audioSource.reverbZoneMix = audioItem.reverbZoneMix; audioSource.rolloffMode = audioItem.audioRolloffMode; DestroyAfterAudioFinish destroyAfterAudioFinish = audioSpawned.AddComponent <DestroyAfterAudioFinish>(); PooledItem pooledItem = audioSpawned.AddComponent <PooledItem>(); if (!audioSource.loop) { if (audioItem.isAutoDisable) { pooledItem.timeToDisable = audioItem.audioClip.length; } } pooledItem.autoDisable = audioItem.isAutoDisable; destroyAfterAudioFinish.isPooled = true; destroyAfterAudioFinish.auto = audioItem.isAutoDisable; return(audioSource); }
public static AudioSource FromAudioManager(this AudioSource audioSource, AudioItem audioItem) { audioSource.clip = audioItem.audioClip; audioSource.mute = audioItem.mute; audioSource.bypassEffects = audioItem.bypassEffects; audioSource.bypassListenerEffects = audioItem.bypassListenerEffects; audioSource.bypassReverbZones = audioItem.bypassReverbZones; audioSource.playOnAwake = audioItem.playOnAwake; audioSource.loop = audioItem.loop; audioSource.pitch = audioItem.pitch; audioSource.volume = audioItem.volume; audioSource.priority = audioItem.priority; audioSource.dopplerLevel = audioItem.dopplerLevel; audioSource.minDistance = audioItem.minDistance; audioSource.spatialBlend = audioItem.spatialBlend; audioSource.panStereo = audioItem.stereoPan; audioSource.spread = audioItem.spread; audioSource.maxDistance = audioItem.maxDistance; audioSource.reverbZoneMix = audioItem.reverbZoneMix; audioSource.rolloffMode = audioItem.audioRolloffMode; return(audioSource); }
public void Inizialice(AudioItem audioItem) { VolumeProperty = this.volume; this.audioClip = audioItem.audioClip; this.mute = audioItem.mute; this.bypassEffects = audioItem.bypassEffects; this.bypassListenerEffects = audioItem.bypassListenerEffects; this.bypassReverbZones = audioItem.bypassReverbZones; this.playOnAwake = audioItem.playOnAwake; this.loop = audioItem.loop; this.pitch = audioItem.pitch; this.volume = audioItem.volume; this.priority = audioItem.priority; this.dopplerLevel = audioItem.dopplerLevel; this.minDistance = audioItem.minDistance; this.spatialBlend = audioItem.spatialBlend; this.stereoPan = audioItem.stereoPan; this.spread = audioItem.spread; this.maxDistance = audioItem.maxDistance; this.reverbZoneMix = audioItem.reverbZoneMix; this.audioRolloffMode = audioItem.audioRolloffMode; }
public AudioSource GetAudioSource(string clipName) { AudioItem audioItem = audioDictionary.Find(a => a.name == clipName); if (audioItem != null) { Transform audioObject = tRoot.FindChild(audioItem.name); if (!audioItem.loop && audioItem.isUnique) { audioObject = tRoot.FindChild(audioItem.name + "(Clone)"); } if (audioObject != null) { AudioSource audioComponent = audioObject.GetComponent <AudioSource>(); if (audioComponent != null) { return(audioComponent); } } } return(null); }
/// <summary> /// Reproduce una pista cuyo nombre en el diccionario sea igual a la especificada en un GameObject. /// </summary> /// <param name="clipName">Nombre del item en el diccionario.</param> /// <returns></returns> public GameObject Play(string clipName) { if (tRoot == null) { tRoot = transform.FindChild(rootPath); } // obtiene el objeto AudioItem AudioItem audioItem = audioDictionary.Find(a => a.name == clipName); if (audioItem != null) { bool isUnique = false; Transform root = null; Vector3 pos = audioItem.tagSpawn.position; Quaternion rot = audioItem.tagSpawn.rotation; Transform tChild = null; Transform tChildPooled = null; // establece el transform root en el que se buscaran los objetos de audio if (audioItem.inRoot) { root = tRoot; } else { root = audioItem.tagSpawn; } // si es unico if (audioItem.isUnique) { tChild = root.FindChild(clipName); // establece el gameobject con al componente audiosource tChildPooled = root.FindChild(audioItem.name + "_pooledbase"); // establece el gameobject con el pooledobject if (tChild) { PooledObject po = tChildPooled.GetComponent <PooledObject>(); // obtiene el componente pooledobject if ((po && po.pooledObjects.Count > 0 && po.pooledObjects.Any(p => p.activeSelf)) || (tChild && tChild.gameObject.activeSelf)) { isUnique = true; } } } if (!isUnique) { if (!audioItem.loop) { PooledObject po = root.FindChild(audioItem.name + "_pooledbase").GetComponent <PooledObject>(); GameObject obj = po.GetPooledObject(pos, rot); obj.transform.parent = tRoot; if (obj == null) { return(null); } obj.transform.rotation = rot; obj.transform.position = pos; obj.SetActive(true); } else { root.FindChild(clipName).gameObject.SetActive(true); } } return(root.FindChild(clipName).gameObject); } return(null); }