public override void StopAllAudiosInCategory(string categoryId) { AudioCategory ac = GetCategory(categoryId); if (ac != null) { ac.StopAllAudios(); } else { if (_isLogged) { Debug.LogFormat(this, "Audio Manager Failed to stop audios in category[{0}].", categoryId); } } }
/* * Function: Picks AudioSubItem to play, and creates the AudioObject based on the prefab passed * Parameter: transformParent is the new parent of the AudioObject if provided * Parameter: v3Point is the local position of the created AudioObject * Parameter: fVolume to be passed to the AudioObject * Parameter: pPrefab that will be used as instance for this AudioObject * Return: AudioObject created to play this sound if successfull */ public AudioObject Play(Transform transformParent, Vector3 v3Point, float fVolume, ref AudioObject pPrefab) { float fTimeElapsedSinceLastPlay = Time.realtimeSinceStartup - lastTimePlayed; if (mustShowDebugInfo) { Debug.Log("LastTimePlayed[" + lastTimePlayed + "] TimeELapsed[" + fTimeElapsedSinceLastPlay + "] MinTime[" + minTimeBetweenPlay + "] Volume[" + fVolume + "]"); } if (fTimeElapsedSinceLastPlay >= minTimeBetweenPlay || minTimeBetweenPlay <= 0.0f) { AudioObject ao = null; if (subItemsList.Count > 0) { if (pPrefab != null) { AudioSubItem asiSubItem = null; //pick subitem switch (subItemPickMode) { case SubItemPickMode.Unique: asiSubItem = subItemsList[0]; break; case SubItemPickMode.Random: asiSubItem = subItemsList[UnityEngine.Random.Range(0, subItemsList.Count)]; break; case SubItemPickMode.Ordered: asiSubItem = subItemsList[currentIndex]; AdvanceIndex(true); break; case SubItemPickMode.InverseOrdered: asiSubItem = subItemsList[currentIndex]; AdvanceIndex(false); break; default: break; } if (asiSubItem != null) { asiSubItem.SetAudioItem(this); } if (relatedCategory.onlyOneItemAllowed) { if (mustShowDebugInfo) { Debug.Log("Stopping all audios in category[" + relatedCategory.categoryId + "] because only one is allowed and will give chance for a new [" + itemId + "] audio."); } relatedCategory.StopAllAudios(); } float itemVolume = fVolume * volume; //substitute for pool manager function if (ServiceLocator.Instance.GetServiceOfType <BaseAudioManager>(SERVICE_TYPE.AUDIOMANAGER).usePooledAudioObjects) { PoolableObject apo = ServiceLocator.Instance.GetServiceOfType <BasePoolManager>(SERVICE_TYPE.POOLMANAGER).Spawn("AM_" + relatedCategory.categoryId); if (apo != null) { ao = ((AudioPooledObject)apo).audioObjReference; if (ao != null) { ao.OnAudioStarted = OnAudioStarted; ao.OnAudioStopped = OnAudioStopped; ao.InitializeAudioObject(AudioManager.audioObjInstanceCounter, asiSubItem, itemVolume); AudioManager.audioObjInstanceCounter++; ao.CachedTransform.parent = transformParent; ao.CachedTransform.localPosition = v3Point; lastTimePlayed = Time.realtimeSinceStartup; ao.Play(); RegisterAudioObject(ao); } else { if (mustShowDebugInfo) { Debug.LogWarning("There are no AudioObject reference on PooledAudioObject when playing Item[" + itemId + "]"); } } } else { if (mustShowDebugInfo) { Debug.LogWarning("There are no AudioObject Prefab instance availbale in the pool to play Item[" + itemId + "] in category[AM_" + relatedCategory.categoryId + "]"); } } } else { ao = GameObject.Instantiate(pPrefab) as AudioObject; if (ao != null) { ao.InitializeAudioObject(AudioManager.audioObjInstanceCounter, asiSubItem, itemVolume); AudioManager.audioObjInstanceCounter++; ao.CachedTransform.parent = transformParent; ao.CachedTransform.localPosition = v3Point; lastTimePlayed = Time.realtimeSinceStartup; RegisterAudioObject(ao); ao.Play(); } else { if (mustShowDebugInfo) { Debug.LogWarning("There are no AudioObject Prefab instance to play Item[" + itemId + "]"); } } } } else { if (mustShowDebugInfo) { Debug.LogWarning("There are no AudioObject Prefab to play Item[" + itemId + "]"); } } } else { if (mustShowDebugInfo) { Debug.LogWarning("There are no SubItems to play in Item[" + itemId + "]"); } } return(ao); } else { if (mustShowDebugInfo) { Debug.LogWarning("Time elpased since last[" + fTimeElapsedSinceLastPlay + "] is not enough to play Item[" + itemId + "]"); } } return(null); }