// plays the sound effect of an on-entry event private IEnumerator CoroPlayStateEnterSound(AnimatorNodeEntryEvent eventInfo) { if (eventInfo.m_SoundStartDelaySeconds > 0) { yield return(new WaitForSeconds(eventInfo.m_SoundStartDelaySeconds)); } if (!m_ActiveNodes.Contains(eventInfo.m_AnimatorNodeNameHash)) { yield break; } if (!eventInfo.m_LoopSound) { m_AudioSources[0].PlayOneShot(eventInfo.m_SoundEffect, eventInfo.m_VolumeMultiplier); } else { AudioSource audioSource = GetAudioSourceForLooping(); if (!audioSource) { yield break; // we're using all our audio sources already. just give up } audioSource.volume = eventInfo.m_VolumeMultiplier; audioSource.loop = true; audioSource.clip = eventInfo.m_SoundEffect; audioSource.Play(); while (m_ActiveNodes.Contains(eventInfo.m_AnimatorNodeNameHash) && audioSource.isPlaying) { yield return(new WaitForFixedUpdate()); } audioSource.Stop(); } }
// creates and manages the graphics prefab (but not the sound effect) of an on-enter event private IEnumerator CoroPlayStateEnterFX(AnimatorNodeEntryEvent eventInfo) { if (eventInfo.m_PrefabSpawnDelaySeconds > 0) { yield return(new WaitForSeconds(eventInfo.m_PrefabSpawnDelaySeconds)); } if (!m_ActiveNodes.Contains(eventInfo.m_AnimatorNodeNameHash)) { yield break; } var instantiatedFX = Instantiate(eventInfo.m_Prefab, m_Animator.transform); // now we just need to watch and see if we end up needing to prematurely end these new graphics if (eventInfo.m_PrefabCanBeAbortedUntilSecs > 0) { float timeRemaining = eventInfo.m_PrefabCanBeAbortedUntilSecs - eventInfo.m_PrefabSpawnDelaySeconds; while (timeRemaining > 0 && instantiatedFX) { yield return(new WaitForFixedUpdate()); timeRemaining -= Time.fixedDeltaTime; if (!m_ActiveNodes.Contains(eventInfo.m_AnimatorNodeNameHash)) { // the node we were in has ended! Shut down the FX if (instantiatedFX) { instantiatedFX.Shutdown(); } } } } }