Esempio n. 1
0
 private void Pause()
 {
     if (AudioSourceLoop != null)
     {
         AudioSourceLoop.Pause();
     }
 }
Esempio n. 2
0
 private void Resume()
 {
     if (AudioSourceLoop != null && CanPlay)
     {
         AudioSourceLoop.Resume();
     }
 }
Esempio n. 3
0
        public override void Update()
        {
#if UNITY_EDITOR
            if (!Application.isPlaying || WeatherMakerScript.Instance == null)
            {
                return;
            }
            else
#endif

            if (AudioSourceLoop == null)
            {
                return;
            }
            else if (AudioSourceLoop.AudioSource.isPlaying)
            {
                // see if we need to stop
                if (!AudioSourceLoop.Stopping && ((timeRemainingToPlay -= Time.deltaTime) < 0.0f && IntervalRange.Minimum > 0.0f) || !CanStartSound())
                {
                    Stop();
                }
            }
            // check if it is the right time of day to play the ambient sound
            else if (CanStartSound())
            {
                if (timeToNextPlay <= 0.0f && IntervalRange.Minimum > 0.0f)
                {
                    CalculateNextPlay();
                }
                // check if it is time to play
                else if ((timeToNextPlay -= Time.deltaTime) < 0.0f)
                {
                    timeToNextPlay      = 0.0f;
                    timeRemainingToPlay = (!Looping || DurationRange.Maximum <= 0.0f ? float.MaxValue : DurationRange.Random());
                    float startFade = Looping ? FadeDuration.Random() : 0.0f;
                    float endFade   = Looping ? FadeDuration.Random() : 0.0f;
                    AudioSourceLoop.SetFade(startFade, endFade);
                    AudioSourceLoop.AudioSource.clip = AudioClips[UnityEngine.Random.Range(0, AudioClips.Length)];
                    AudioSourceLoop.Play(VolumeRange.Random());

#if ENABLE_DEBUG_LOG_WEATHER_MAKER_SOUNDS
                    if (Looping)
                    {
                        Debug.LogFormat("Weather Maker playing sound {0} for {1} seconds", Name, (timeRemainingToPlay == float.MaxValue ? "Infinite" : timeRemainingToPlay.ToString("0.00")));
                    }
                    else
                    {
                        Debug.LogFormat("Weather Maker playing sound {0} for {1:0.00} seconds", Name, AudioClip.length);
                    }
#endif
                }
            }
            else
            {
                timeToNextPlay = 0.0f;
            }
            AudioSourceLoop.VolumeModifier = WeatherMakerScript.Instance.cachedVolumeModifier;
            AudioSourceLoop.Update();
        }
Esempio n. 4
0
        public void Stop(float fadeOutSeconds = 0.0f, bool destroyOnStopped = false)
        {
            if (AudioSourceLoop != null && AudioSourceLoop.AudioSource != null)
            {
#if ENABLE_DEBUG_LOG_WEATHER_MAKER_SOUNDS
                Debug.LogFormat("Weather Maker stopping sound {0}", Name);
#endif

                AudioSourceLoop.Stop(fadeOutSeconds, destroyOnStopped);
                timeToNextPlay = 0.0f;
            }
        }
Esempio n. 5
0
        public void Stop()
        {
#if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                return;
            }
#endif

            if (AudioSourceLoop != null && AudioSourceLoop.AudioSource != null && AudioSourceLoop.AudioSource.isPlaying && !AudioSourceLoop.Stopping)
            {
#if ENABLE_DEBUG_LOG_WEATHER_MAKER_SOUNDS
                Debug.LogFormat("Weather Maker stopping sound {0}", Name);
#endif

                AudioSourceLoop.Stop();
                timeToNextPlay = 0.0f;
            }
        }