Example #1
0
        private IEnumerator WaitForEndOfEvent(PlayingEvent e)
        {
            yield return(new WaitForSeconds(_duration));

            Debug.Log(string.Format("Duration of event -> {0} done", _eventName));
            Stop(e);
        }
        public override PlayingEvent Play()
        {
            // Setting weights if needed
            float[] weights = _givenWeights;
            if (!_specifyWeights || _clips.Length != _givenWeights.Length)
            {
                weights = new float[_clips.Length];
                for (int i = 0; i < _clips.Length; ++i)
                {
                    weights[i] = 1.0f / (float)_clips.Length;
                }
            }

            Debug.Log(string.Format("Playing the audio event -> {0}", _eventName));

            PlayingEvent      e      = new PlayingEvent(this, Time.time);
            PooledAudioSource pooled = AudioManager.Instance.PoolSource(_channel);

            pooled.Source.clip = SelectRandomClip(weights);
            e.Sources.Add(pooled);
            _playing.Add(e);
            _playingRoutine = AudioManager.Instance.StartCoroutine(WaitForEndOfEvent(e));

            return(e);
        }
Example #3
0
        public override PlayingEvent Play()
        {
            Debug.Log(string.Format("Playing the audio event -> {0}", _eventName));

            PlayingEvent      e      = new PlayingEvent(this, Time.time);
            PooledAudioSource pooled = AudioManager.Instance.PoolSource(_channel);

            pooled.Source.clip = _clip;
            e.Sources.Add(pooled);
            _playing.Add(e);
            _playingRoutine = AudioManager.Instance.StartCoroutine(WaitForEndOfEvent(e));

            return(e);
        }
Example #4
0
        public override void StopNewest()
        {
            Debug.Log(string.Format("Stopping the newest of audio event -> {0}", _eventName));
            PlayingEvent toStop = null;
            float        max    = float.MinValue;

            for (int i = 0; i < _playing.Count; ++i)
            {
                if (_playing[i].StartTime > max)
                {
                    toStop = _playing[i];
                    max    = _playing[i].StartTime;
                }
            }

            Stop(toStop);
        }
Example #5
0
        public override void StopOldest()
        {
            Debug.Log(string.Format("Stopping the oldest of audio event -> {0}", _eventName));
            PlayingEvent toStop = null;
            float        min    = float.MaxValue;

            for (int i = 0; i < _playing.Count; ++i)
            {
                if (_playing[i].StartTime < min)
                {
                    toStop = _playing[i];
                    min    = _playing[i].StartTime;
                }
            }

            Stop(toStop);
        }
 public PlayingEvent PlayEvent(string name, float delay)
 {
     if (Mathf.Approximately(delay, 0.0f))
     {
         AudioEventBase e = _db.FindEventDataByName(name);
         if (e != null)
         {
             PlayingEvent p = e.Play();
             Log(string.Format("Started playing event {0}", name));
             return(p);
         }
         else
         {
             Log(string.Format("Could not find audio event: {0}", name));
         }
     }
     else
     {
         _component.StartCoroutine(DelayedPlayEvent(name, delay));
     }
     return(null);
 }
Example #7
0
        public override void Stop(PlayingEvent e)
        {
            if (e == null)
            {
                Debug.Log(string.Format("Could not find the event to stop for -> {0}", _eventName));
                return;
            }

            Debug.Log(string.Format("Ending the audio event -> {0}, returning source(s) to pools", _eventName));
            if (_playingRoutine != null)
            {
                AudioManager.Instance.StopCoroutine(_playingRoutine);
                _playingRoutine = null;
            }

            foreach (PooledAudioSource src in e.Sources)
            {
                AudioManager.Instance.ReturnSource(src);
            }

            _playing.Remove(e);
        }
 public void Stop(PlayingEvent e)
 {
     e.Event.Stop(e);
 }
Example #9
0
 public abstract void Stop(PlayingEvent e);
 public override void Stop(PlayingEvent e)
 {
 }