Ejemplo n.º 1
0
 protected SFXAudioBase PlayClip(int sourceID, AudioClip _clip, float _volume, bool _loop, Vector3 _position)
 {
     if (_volume == 0)
     {
         return(null);
     }
     return(TGameObjectPool_Static <int, SFXAudioBase> .Spawn(0, null, _position, Quaternion.identity).Play(sourceID, _clip, _volume, _loop, null));
 }
Ejemplo n.º 2
0
    public virtual void Init()
    {
        GameObject obj = new GameObject("Prefab 3D");

        obj.transform.SetParent(transform);
        AudioSource source = obj.AddComponent <AudioSource>();

        source.spatialBlend = 1;
        TGameObjectPool_Static <int, SFXAudioBase> .Register(0, obj.AddComponent <SFXAudioBase>(), 20);

        obj = new GameObject("Prefab 2D");
        obj.transform.SetParent(transform);
        source = obj.AddComponent <AudioSource>();
        source.spatialBlend = 0;
        TGameObjectPool_Static <int, SFXAudioBase> .Register(1, obj.AddComponent <SFXAudioBase>(), 20);
    }
Ejemplo n.º 3
0
    protected virtual void Update()
    {
        float deltaTime = Time.unscaledDeltaTime;

        m_AudioBG.volume = m_BGVolume;

        if (m_Clip == null)
        {
            if (m_AudioBG.isPlaying)
            {
                m_baseVolume = Mathf.Lerp(m_baseVolume, 0f, deltaTime * 2);
                if (m_baseVolume <= .05f)
                {
                    m_AudioBG.Stop();
                }
            }
            return;
        }
        else
        {
            if (m_AudioBG.clip == m_Clip)
            {
                m_baseVolume = Mathf.Lerp(m_baseVolume, 1f, deltaTime * 2);
            }
            else
            {
                m_baseVolume = Mathf.Lerp(m_baseVolume, 0f, deltaTime * 2);
                if (m_baseVolume <= .05f)
                {
                    m_AudioBG.clip = m_Clip;
                    m_AudioBG.Play();
                }
            }
        }
        TGameObjectPool_Static <int, SFXAudioBase> .TraversalAllActive((SFXAudioBase audio) => { audio.Tick(deltaTime); });
    }
Ejemplo n.º 4
0
 protected void SetSFXVolume(float volume) => TGameObjectPool_Static <int, SFXAudioBase> .TraversalAllActive((SFXAudioBase audio) => audio.SetVolume(volume));
Ejemplo n.º 5
0
 public virtual void Destroy() => TGameObjectPool_Static <int, SFXAudioBase> .Destroy();