Exemplo n.º 1
0
 public void fadeOutAllMusicSources(float fadeout_len = -1f, CAudioMusicSource exceptsrc = null)
 {
     print("fadeout all " + exceptsrc);
     CAudioMusicSource[] srcs = transform.GetComponentsInChildren<CAudioMusicSource>();
     foreach (CAudioMusicSource src in srcs)
     {
         if (src != exceptsrc)
         {
             src.m_playImmediately = false; // Cancel play at Start or duplicate
             if (src.isPlaying)
                 src.fadeOut(fadeout_len);
         }
     }
 }
Exemplo n.º 2
0
 public void playMusic(CAudioMusicSource byval)
 {
     if (!byval.isPlaying)
         activateMusicSource(byval);
 }
Exemplo n.º 3
0
 void activateMusicSource(CAudioMusicSource newsrc)
 {
     // Fadeout everything but this, according to their predef fadeout time
     fadeOutAllMusicSources(-1, newsrc);
     newsrc.gameObject.active = true;
 }
Exemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        #if UNITY_EDITOR || UNITY_WEBPLAYER || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
        if (m_playing && Input.GetKeyDown(KeyCode.RightArrow))
        {
            audio.time += 5f;
        }
        #endif
        if (!m_playing)
            return;

        float atime = audio.time;
        if (atime < m_fadeInAt)
        {
            atime = audio.time = m_fadeInAt;
            if (!audio.isPlaying)
                audio.Play();
        }

        if (m_fadingIn)
        {
            if ((m_baseVolume += Time.deltaTime / m_fadeInLength) >= 1f)
            {
                m_fadingIn = false;
                m_baseVolume = 1f;
            }
            audio.volume = m_baseVolume * m_origVolume * CAudioManager.g.m_musicVolume;
        }
        else if (m_fadingOut)
        {
            if ((m_baseVolume -= Time.deltaTime / m_fadeOutLength) <= 0f)
            {
                m_fadingOut = false;
                m_baseVolume = 0f;
                play(false);
                if (m_destroyWhenComplete)
                    Destroy(gameObject);
                else
                    gameObject.active = false;
            }
            audio.volume = m_baseVolume * m_origVolume * CAudioManager.g.m_musicVolume;
        }

        float now = Time.time;
        if (now >= m_nextCheck)
        {
            m_nextCheck = now + CHECK_FREQ;

            if (!m_fadingOut &&
                atime >= m_fadeOutAt)
                m_fadingOut = true;

            if (atime >= m_activateSourceAt &&
                m_activateSource != null)
            {
             	if (!m_activateSource.gameObject.active)
                    m_activateSource.gameObject.active = true;
                else if (m_activateSource == this && m_playImmediately)
                    duplicate();

                m_activateSource = null;
            }

        #if UNITY_EDITOR
            m_currentTime = audio.time;
        #endif
        }
    }