Example #1
0
    /// <summary>
    /// Will play the given clip at the given place. The Parameter contain a SourceID that allow to uniquely identify
    /// an event so it have to wait the given cooldown time before being able to be played again (e.g. useful for
    /// collision sound, as physic system could create multiple collisions in a short time that would lead to stutter)
    /// </summary>
    /// <param name="clip"></param>
    /// <param name="position"></param>
    /// <param name="parameters"></param>
    /// <param name="cooldownTime">Time before another PlaySFX with the same parameters.SourceID can be played again</param>
    /// <param name="isClosedCaptioned">if true, the source will display a closed caption for the given clip if the closed caption system is enabled</param>
    public void PlaySFX(AudioClip clip, Vector3 position, PlayParameters parameters, float cooldownTime = 0.5f, bool isClosedCaptioned = false)
    {
        if (clip == null)
        {
            return;
        }

        //can't play this sound again as the previous one with the same source was too early
        if (m_PlayEvents.ContainsKey(parameters.SourceID))
        {
            return;
        }

        AudioSource s   = m_SFXSourcePool[m_UsedSource];
        CCSource    ccs = m_CcSources[m_UsedSource];

        m_PlayingSources.Add(m_UsedSource);

        m_UsedSource = m_UsedSource + 1;
        if (m_UsedSource >= m_SFXSourcePool.Length)
        {
            m_UsedSource = 0;
        }

        s.gameObject.SetActive(true);
        s.transform.position = position;
        s.clip = clip;

        s.volume = parameters.Volume;
        s.pitch  = parameters.Pitch;

        m_PlayEvents.Add(parameters.SourceID, new PlayEvent()
        {
            Time = cooldownTime
        });

        ccs.enabled = isClosedCaptioned;

        s.Play();
    }
 public static void RemoveSource(CCSource source)
 {
     s_Instance.m_Sources.Remove(source);
 }
 public static void RegisterSource(CCSource source)
 {
     s_Instance.m_Sources.Add(source);
 }