コード例 #1
0
 void Update()
 {
     if (m_users == 0)
     {
         m_timer -= WingroveRoot.GetDeltaTime();
         if (m_timer < 0)
         {
             if (!m_onlyUnloadOnLevelChange)
             {
                 Unload();
             }
         }
     }
     UpdateInternal();
 }
コード例 #2
0
        // Use this for initialization
        void Awake()
        {
            s_instance = this;
            GameObject pool = new GameObject("AudioSourcePool");

            pool.transform.parent = transform;
            for (int i = 0; i < m_audioSourcePoolSize; ++i)
            {
                GameObject newAudioSource = new GameObject("PooledAudioSource");
                newAudioSource.transform.parent = pool.transform;

                AudioSource aSource = newAudioSource.AddComponent <AudioSource>();

                AudioSourcePoolItem aspi = new AudioSourcePoolItem();
                aspi.m_audioSource  = aSource;
                aSource.enabled     = false;
                aSource.rolloffMode = m_defaultRolloffMode;
                aSource.maxDistance = m_defaultMaxDistance;
                aSource.minDistance = m_defaultMinDistance;
                aspi.m_index        = i;
                m_audioSourcePool.Add(aspi);
            }

            BaseEventReceiveAction[] evrs = GetComponentsInChildren <BaseEventReceiveAction>();
            foreach (BaseEventReceiveAction evr in evrs)
            {
                string[] events = evr.GetEvents();
                if (events != null)
                {
                    foreach (string ev in events)
                    {
                        if (!m_eventReceivers.ContainsKey(ev))
                        {
                            m_eventReceivers[ev] = new List <BaseEventReceiveAction>();
                        }
                        m_eventReceivers[ev].Add(evr);
                    }
                }
            }

            gameObject.AddComponent <AudioListener>();

            transform.position = Vector3.zero;
            m_lastDSPTime      = AudioSettings.dspTime;
#if UNITY_EDITOR
            m_startTime = AudioSettings.dspTime;
#endif
        }
コード例 #3
0
        void Update()
        {
            if (m_ratio != 0)
            {
                float target = 0.0f;
                // use peak
                float rmsTarg     = m_mixBusToMonitor.GetRMS() / 0.707f;
                float rmsPopRatio = Mathf.Max(0, (rmsTarg - m_threshold)) * m_ratio;
                target = Mathf.Clamp01(rmsPopRatio);

                float fadeSpeed = target > m_fadeT ? (1.0f / Mathf.Max(m_attack, 0.01f)) : (1.0f / Mathf.Max(m_release, 0.01f));

                m_fadeT += Mathf.Min(Mathf.Abs(fadeSpeed * WingroveRoot.GetDeltaTime()), Mathf.Abs(target - m_fadeT)) *
                           Mathf.Sign(target - m_fadeT);
            }
        }
コード例 #4
0
ファイル: DuckOnEvent.cs プロジェクト: tomfionn/FireBonobo
        void Update()
        {
            if (m_isActive)
            {
                if ((m_currentState == DuckState.Inactive) ||
                    (m_currentState == DuckState.Release))
                {
                    if (m_attack == 0.0f)
                    {
                        m_currentState = DuckState.Hold;
                        m_fadeT        = 1.0f;
                    }
                    else
                    {
                        m_currentState = DuckState.Attack;
                        m_faderSpeed   = (1.0f) / m_attack;
                    }
                }
            }
            else
            {
                if (m_currentState != DuckState.Inactive)
                {
                    if (m_attack == 0.0f)
                    {
                        m_currentState = DuckState.Inactive;
                        m_fadeT        = 0.0f;
                    }
                    else
                    {
                        m_currentState = DuckState.Release;
                        m_faderSpeed   = (1.0f) / m_release;
                    }
                }
            }

            switch (m_currentState)
            {
            case DuckState.Attack:
                m_fadeT += m_faderSpeed * WingroveRoot.GetDeltaTime();
                if (m_fadeT >= 1.0f)
                {
                    m_fadeT        = 1.0f;
                    m_currentState = DuckState.Hold;
                }
                break;

            case DuckState.Hold:
                m_fadeT = 1.0f;
                break;

            case DuckState.Release:
                m_fadeT -= m_faderSpeed * WingroveRoot.GetDeltaTime();
                if (m_fadeT <= 0.0f)
                {
                    m_fadeT        = 0.0f;
                    m_currentState = DuckState.Inactive;
                }
                break;

            case DuckState.Inactive:
                break;
            }
        }
コード例 #5
0
        void Update()
        {
            bool hasActiveCues = false;

            foreach (BaseWingroveAudioSource was in m_audioSources)
            {
                if (was.HasActiveCues())
                {
                    hasActiveCues = true;
                }
            }

            if (hasActiveCues)
            {
                if ((m_currentState == DuckState.Inactive) ||
                    (m_currentState == DuckState.Release))
                {
                    if (m_attack == 0.0f)
                    {
                        m_currentState = DuckState.Hold;
                        m_fadeT        = 1.0f;
                    }
                    else
                    {
                        m_currentState = DuckState.Attack;
                        m_faderSpeed   = (1.0f) / m_attack;
                    }
                }
            }
            else
            {
                if (m_currentState != DuckState.Inactive)
                {
                    if (m_attack == 0.0f)
                    {
                        m_currentState = DuckState.Inactive;
                        m_fadeT        = 0.0f;
                    }
                    else
                    {
                        m_currentState = DuckState.Release;
                        m_faderSpeed   = (1.0f) / m_release;
                    }
                }
            }

            switch (m_currentState)
            {
            case DuckState.Attack:
                m_fadeT += m_faderSpeed * WingroveRoot.GetDeltaTime();
                if (m_fadeT >= 1.0f)
                {
                    m_fadeT        = 1.0f;
                    m_currentState = DuckState.Hold;
                }
                break;

            case DuckState.Hold:
                m_fadeT = 1.0f;
                break;

            case DuckState.Release:
                m_fadeT -= m_faderSpeed * WingroveRoot.GetDeltaTime();
                if (m_fadeT <= 0.0f)
                {
                    m_fadeT        = 0.0f;
                    m_currentState = DuckState.Inactive;
                }
                break;

            case DuckState.Inactive:
                break;
            }
        }
コード例 #6
0
        void Update()
        {
            bool queueEnableAndPlay = false;

            if (m_currentAudioSource == null)
            {
                // don't bother stealing if we're going to be silent anyway...
                if (GetTheoreticalVolume() > 0)
                {
                    m_currentAudioSource = WingroveRoot.Instance.TryClaimPoolSource(this);
                }
                if (m_currentAudioSource != null)
                {
                    m_currentAudioSource.m_audioSource.clip = m_audioClipSource.GetAudioClip();
                    if (!m_isPaused)
                    {
                        m_currentAudioSource.m_audioSource.loop = m_audioClipSource.GetLooping();
                        queueEnableAndPlay = true;
                    }
                }
                else
                {
                    if (!m_isPaused)
                    {
                        if (m_hasStartedEver)
                        {
                            m_currentPosition += (int)(WingroveRoot.GetDeltaTime() * m_audioClipSource.GetAudioClip().frequency *GetMixPitch());
                        }
                        if (m_currentPosition > m_audioClipSource.GetAudioClip().samples)
                        {
                            if (m_audioClipSource.GetLooping())
                            {
                                m_currentPosition -= m_audioClipSource.GetAudioClip().samples;
                            }
                            else
                            {
                                StopInternal();
                            }
                        }
                    }
                }
            }
            else
            {
                if (!m_isPaused)
                {
                    m_currentPosition = m_currentAudioSource.m_audioSource.timeSamples;
                }
            }

            if (!m_isPaused)
            {
                switch (m_currentState)
                {
                case CueState.Initial:
                    break;

                case CueState.Playing:
                    m_fadeT = 1;
                    break;

                case CueState.PlayingFadeIn:
                    m_fadeT += m_fadeSpeed * WingroveRoot.GetDeltaTime();
                    if (m_fadeT >= 1)
                    {
                        m_fadeT        = 1.0f;
                        m_currentState = CueState.Playing;
                    }
                    break;

                case CueState.PlayingFadeOut:
                    m_fadeT -= m_fadeSpeed * WingroveRoot.GetDeltaTime();
                    if (m_fadeT <= 0)
                    {
                        m_fadeT = 0.0f;
                        StopInternal();
                        // early return!!!!
                        return;
                    }
                    break;
                }

                if (!m_audioClipSource.GetLooping())
                {
                    if (m_currentPosition > m_audioClipSource.GetAudioClip().samples - 1000)
                    {
                        StopInternal();
                        return;
                    }
                }
            }

            SetMix();

            if (queueEnableAndPlay)
            {
                if (m_currentAudioSource != null)
                {
                    m_currentAudioSource.m_audioSource.enabled     = true;
                    m_currentAudioSource.m_audioSource.timeSamples = m_currentPosition;
                    Audio3DSetting settings = m_audioClipSource.Get3DSettings();
                    if (settings == null)
                    {
                        WingroveRoot.Instance.SetDefault3DSettings(m_currentAudioSource.m_audioSource);
                    }
                    else
                    {
                        AudioRolloffMode rolloffMode = settings.GetRolloffMode();
                        if (rolloffMode != AudioRolloffMode.Custom)
                        {
                            m_currentAudioSource.m_audioSource.rolloffMode = rolloffMode;
                            m_currentAudioSource.m_audioSource.minDistance = settings.GetMinDistance();
                            m_currentAudioSource.m_audioSource.maxDistance = settings.GetMaxDistance();
                        }
                        else
                        {
                            m_currentAudioSource.m_audioSource.rolloffMode = AudioRolloffMode.Linear;
                            m_currentAudioSource.m_audioSource.minDistance = float.MaxValue;
                            m_currentAudioSource.m_audioSource.maxDistance = float.MaxValue;
                        }
                    }
                    if ((m_hasDSPStartTime) && (m_dspStartTime > AudioSettings.dspTime))
                    {
                        m_currentAudioSource.m_audioSource.timeSamples = m_currentPosition = 0;
                        m_currentAudioSource.m_audioSource.PlayScheduled(m_dspStartTime);
                    }
                    else
                    {
                        m_currentAudioSource.m_audioSource.Play();
                    }
                }
            }

            m_hasStartedEver = true;
        }
コード例 #7
0
        // Use this for initialization
        void Awake()
        {
            s_instance = this;
            GameObject pool = new GameObject("AudioSourcePool");
            pool.transform.parent = transform;
            for (int i = 0; i < m_audioSourcePoolSize; ++i)
            {
                GameObject newAudioSource = new GameObject("PooledAudioSource");
                newAudioSource.transform.parent = pool.transform;

                AudioSource aSource = newAudioSource.AddComponent<AudioSource>();

                AudioSourcePoolItem aspi = new AudioSourcePoolItem();
                aspi.m_audioSource = aSource;
                aSource.enabled = false;
                aSource.rolloffMode = m_defaultRolloffMode;
                aSource.maxDistance = m_defaultMaxDistance;
                aSource.minDistance = m_defaultMinDistance;
                aspi.m_index = i;
                m_audioSourcePool.Add(aspi);
            }

            BaseEventReceiveAction[] evrs = GetComponentsInChildren<BaseEventReceiveAction>();
            foreach (BaseEventReceiveAction evr in evrs)
            {
                string[] events = evr.GetEvents();
                if (events != null)
                {
                    foreach (string ev in events)
                    {
                        if (!m_eventReceivers.ContainsKey(ev))
                        {
                            m_eventReceivers[ev] = new List<BaseEventReceiveAction>();
                        }
                        m_eventReceivers[ev].Add(evr);
                    }
                }
            }

            gameObject.AddComponent<AudioListener>();

            transform.position = Vector3.zero;
            m_lastDSPTime = AudioSettings.dspTime;
            #if UNITY_EDITOR
            m_startTime = AudioSettings.dspTime;
            #endif
        }