Ejemplo n.º 1
0
    private AudioClip getAudioClip(SfxItem sfxItem)
    {
        switch (sfxItem)
        {
        case SfxItem.Player_PickUp:
            return(this.playerPickupClip);

        case SfxItem.Player_Drop:
            return(this.playerDropClip);

        case SfxItem.Block_Enter1:
            return(this.blockEnter1Clip);

        case SfxItem.Block_Enter2:
            return(this.blockEnter2Clip);

        case SfxItem.Block_Enter3:
            return(this.blockEnter3Clip);

        case SfxItem.Block_EnterIncorrect:
            return(this.blockEnterIncorrectClip);

        case SfxItem.Block_EnterCorrect:
            return(this.blockEnterCorrectClip);

        case SfxItem.Game_Start:
            return(this.gameStartClip);

        case SfxItem.Game_TimeOut:
            return(this.gameTimeOutClip);

        default:
            return(null);
        }
    }
Ejemplo n.º 2
0
    public void PlaySfxClip(SfxItem sfxItem)
    {
        audioSource.Stop();

        AudioClip audioClip = this.getAudioClip(sfxItem);

        if (!audioClip)
        {
            return;
        }

        audioSource.clip = audioClip;
        audioSource.Play();
    }
Ejemplo n.º 3
0
        private SfxItem GetFreeSfx(string fileName)
        {
            var requireFreshReload = !_fileNames.Contains(fileName);

            if (requireFreshReload)
            {
                _fileNames.Add(fileName);
            }

            SfxItem sfx;

            if (!requireFreshReload)
            {
                SfxItem template = null;

                foreach (var item in _items)
                {
                    if (item.FileName != fileName)
                    {
                        continue;
                    }

                    template = item;

                    if (!item.IsPlaying)
                    {
                        return(item);
                    }
                }

                if (template != null)
                {
                    sfx = template.Extend();

                    lock (_syncObject) {
                        _items.Add(sfx);
                    }

                    return(sfx);
                }
            }

            sfx = LoadSfx(fileName);
            lock (_syncObject) {
                _items.Add(sfx);
            }

            return(sfx);
        }
Ejemplo n.º 4
0
            public SfxItem Extend()
            {
                var sfx = new SfxItem {
                    FileName   = FileName,
                    Data       = Data,
                    SampleRate = SampleRate,
                    TotalTime  = TotalTime
                };

                sfx.AudioSource = new AudioSource(AudioSource.Context);
                sfx.AudioBuffer = new AudioBuffer(AudioBuffer.Context);
                sfx.AudioBuffer.BufferData(sfx.Data, sfx.SampleRate);
                sfx.AudioSource.Bind(sfx.AudioBuffer);

                return(sfx);
            }
Ejemplo n.º 5
0
        private SfxItem LoadSfx(string fileName)
        {
            if (!_fileNames.Contains(fileName))
            {
                _fileNames.Add(fileName);
            }

            var sfx = new SfxItem();

            byte[]   data;
            int      sampleRate;
            TimeSpan totalTime;

            using (var waveReader = new WaveFileReader(fileName)) {
                sampleRate = waveReader.WaveFormat.SampleRate;
                totalTime  = waveReader.TotalTime;

                WaveStream waveStream;

                if (AudioManager.NeedsConversion(waveReader.WaveFormat, AudioManager.StandardFormat))
                {
                    waveStream = new WaveFormatConversionStream(AudioManager.StandardFormat, waveReader);
                }
                else
                {
                    waveStream = waveReader;
                }

                using (var offsetStream = new WaveOffsetStream(waveStream)) {
                    offsetStream.StartTime = PreviewingSettings.SfxOffset;
                    data = offsetStream.ReadToEnd();
                }
            }

            sfx.AudioBuffer = new AudioBuffer(_audioManager.AudioContext);
            sfx.AudioSource = new AudioSource(_audioManager.AudioContext);
            sfx.AudioBuffer.BufferData(data, sampleRate);
            sfx.AudioSource.Bind(sfx.AudioBuffer);
            sfx.Data       = data;
            sfx.FileName   = fileName;
            sfx.SampleRate = sampleRate;
            sfx.TotalTime  = totalTime;

            return(sfx);
        }
Ejemplo n.º 6
0
        public CustomButton(SfxItem _btn)
        {
            this.Button = _btn;

            switch (Button.category)
            {
            case 1: { Source = "alert_unpressed"; } break;

            case 2: { Source = "animal_unpressed"; } break;

            case 3: { Source = "meme_unpressed"; } break;

            case 4: { Source = "music_unpressed"; } break;

            case 5: { Source = "sfx_unpressed"; } break;
            }

            ButtonPressedCommand = new Command(ButtonPressed);

            playMulti = true;
        }