Пример #1
0
 public void Refresh()
 {
     // Init references
     if (_instrument == null)
     {
         _instrument = Instrument.AllInstruments[_instrumentIndex];
     }
     _source     = MusicManager.Instance.GetAudioSource(_instrument);
     _distortion = _source.GetComponent <AudioDistortionFilter>();
     _tremolo    = _source.GetComponent <AudioTremoloFilter>();
     _chorus     = _source.GetComponent <AudioChorusFilter>();
     _flanger    = _source.GetComponent <AudioFlangerFilter>();
     _echo       = _source.GetComponent <AudioEchoFilter>();
     _reverb     = _source.GetComponent <AudioReverbFilter>();
 }
Пример #2
0
        /// <summary>
        /// Coroutine to load instruments.
        /// </summary>
        IEnumerator LoadInstruments()
        {
            List <string> loadMessages = new List <string>()
            {
                "Renting instruments...",
                "Grabbing instruments...",
                "Unpacking instruments..."
            };

            // Update loading message
            LoadingScreen.Instance.SetLoadingMessage(loadMessages.Random());

            // Mark start time
            float startTime = Time.realtimeSinceStartup;
            int   numLoaded = 0;

            // Init audio source dict
            _instrumentAudioSources = new Dictionary <Instrument, AudioSource>();

            // Foreach instrument
            for (int i = 0; i < Instrument.AllInstruments.Count; i++)
            {
                // Load instrument data
                Instrument.AllInstruments[i].Load();

                // Create instrument AudioSource GameObject
                GameObject  obj    = new GameObject(Instrument.AllInstruments[i].Name);
                AudioSource source = obj.AddComponent <AudioSource>();

                // Group instrument under MusicManager
                obj.transform.parent = transform.parent;

                // Connect AudioSource to mixer
                source.outputAudioMixerGroup = _mixer.FindMatchingGroups(obj.name)[0];

                // Connect instrument to AudioSource
                _instrumentAudioSources.Add(Instrument.AllInstruments[i], source);

                // Add distortion filter
                AudioDistortionFilter distortion = obj.AddComponent <AudioDistortionFilter>();
                distortion.enabled = false;

                // Add tremolo filter
                AudioTremoloFilter tremolo = obj.AddComponent <AudioTremoloFilter>();
                tremolo.enabled = false;

                // Add chorus filter
                AudioChorusFilter chorus = obj.AddComponent <AudioChorusFilter>();
                chorus.enabled = false;

                // Add flanger filter
                AudioFlangerFilter flanger = obj.AddComponent <AudioFlangerFilter>();
                flanger.enabled = false;

                // Add echo filter
                AudioEchoFilter echo = obj.AddComponent <AudioEchoFilter>();
                echo.enabled = false;

                // Add reverb filter based on MusicManager's reverb filter
                AudioReverbFilter reverb       = obj.AddComponent <AudioReverbFilter>();
                AudioReverbFilter masterReverb = GetComponent <AudioReverbFilter>();
                reverb.dryLevel         = masterReverb.dryLevel;
                reverb.room             = masterReverb.room;
                reverb.roomHF           = masterReverb.roomHF;
                reverb.roomLF           = masterReverb.roomLF;
                reverb.decayTime        = masterReverb.decayTime;
                reverb.decayHFRatio     = masterReverb.decayHFRatio;
                reverb.reflectionsLevel = masterReverb.reflectionsLevel;
                reverb.reflectionsDelay = masterReverb.reflectionsDelay;
                reverb.reverbLevel      = masterReverb.reverbLevel;
                reverb.hfReference      = masterReverb.hfReference;
                reverb.lfReference      = masterReverb.lfReference;
                reverb.diffusion        = masterReverb.diffusion;
                reverb.density          = masterReverb.density;
                reverb.enabled          = false;

                numLoaded++;

                // If over time
                if (Time.realtimeSinceStartup - startTime > GameManager.LoadingTargetDeltaTime)
                {
                    yield return(null);

                    startTime = Time.realtimeSinceStartup;
                    GameManager.Instance.ReportLoaded(numLoaded);
                    numLoaded = 0;
                }
            }

            // When done, start building scales
            if (_instrumentAudioSources.Count == Instrument.AllInstruments.Count)
            {
                KeyManager.Instance.DoBuildScales();
            }
            yield return(null);
        }