private void PlayClip(AudioClip audioClip, float volume, PoolObjectsType poolObjectsType = PoolObjectsType.None, bool loop = false) { GameObject targetSource = null; if (ObjectPoolManager.instance != null) { AudioSource targetAudioSource = null; targetSource = ObjectPoolManager.instance.GetPoolObject(poolObjectsType); if (targetSource != null) { targetAudioSource = targetSource.GetComponent <AudioSource>(); if (targetAudioSource != null) { targetSource.SetActive(true); targetAudioSource.clip = audioClip; float randomPitch = Random.Range(minPitch, maxPitch); targetAudioSource.pitch = randomPitch; targetAudioSource.volume = volume; targetAudioSource.loop = loop; targetAudioSource.Play(); if (loop == false) { float delay = audioClip.length; StartCoroutine(ReturnObjectsToPool(targetSource, delay)); } } } } }
public GameObject GetPoolObject(PoolObjectsType poolObjectsType) { if (poolObjects != null) { foreach (var item in poolObjects) { if (item.poolObjectsType == poolObjectsType) { if (item.pooledObjects.Count > 0) { foreach (var effect in item.pooledObjects) { if (!effect.activeInHierarchy) { return(effect); } } } } } } return(null); }
public void PlaySingleClip(AudioClip audioClip, PoolObjectsType poolObjectsType = PoolObjectsType.None, bool loop = false) { PlayClip(audioClip, sfxVolume, poolObjectsType, loop); }