Exemplo n.º 1
0
        public AudioSystem(SystemConfig inConfig) : base(inConfig)
        {
            if (_instance == null)
            {
                _instance = this;
            }
            if (inConfig != null)
            {
                _config = inConfig as AudioConfig;
            }

            var sourcesHolder = new GameObject("AudioSources Holder");

            sourcesHolder.transform.SetParent(GameState.GameHolder);
            sourcesHolder.transform.SetPositionAndRotation(Vector3.zero, Quaternion.identity);

            //- fill the audio pool
            for (var i = 0; i < _config.bufferSize; i++)
            {
                var src = sourcesHolder.AddComponent <AudioSource>();
                AudioPool.AddToPool(src);
            }

            //- assign audio map
            _audioMap = new Dictionary <AudioLabel, AudioData>();
            _config.audios.ForEach(audio => _audioMap.Add(audio.label, audio));
        }
Exemplo n.º 2
0
        public void Tick()
        {
            if (_sources == null || _sources.Count == 0)
            {
                return;
            }

            var completedSrc = _sources.Where(src => !src.Source.isPlaying && !src.Source.loop);

            foreach (var audioSource in completedSrc.ToList())
            {
                AudioPool.AddToPool(audioSource.Source);
                _sources.Remove(audioSource);
            }
        }