Ejemplo n.º 1
0
    private IEnumerator IE_LoopAudio(AudioLoopInfo loopInfo)
    {
        float elapsedTime = 0f;

        while (true)
        {
            elapsedTime += Time.deltaTime;
            yield return(null);

            if (!loopInfo.isActive)
            {
                loopAudioDic.Remove(loopInfo.LoopKey);
                yield break;
            }
            if (elapsedTime >= loopInfo.LoopTime)
            {
                loopInfo.Source.PlayOneShot(loopInfo.Source.clip);
                elapsedTime = 0f;
            }
        }
    }
Ejemplo n.º 2
0
    public void StartAudioLoop(string loopKey, string audioKey, float loopTime)
    {
        AudioLoopInfo foundLoop;

        if (loopAudioDic.TryGetValue(loopKey, out foundLoop))
        {
            return;
        }
        else
        {
            AudioSource foundSource = null;
            if (audioDic.TryGetValue(audioKey, out foundSource))
            {
                AudioLoopInfo newLoop = new AudioLoopInfo(loopKey, foundSource, loopTime, true);
                loopAudioDic.Add(loopKey, newLoop);
                StartCoroutine(IE_LoopAudio(newLoop));
            }
            else
            {
                Debug.Log($"SoundManager : {audioKey} 를 key로 사용하는 AudioSource 없음");
                return;
            }
        }
    }