Esempio n. 1
0
        void OnCollisionEnter2D(Collision2D collision)
        {
            if (this.destroy)
            {
                return;
            }

            SfxId sfxId = SfxId.None;

            GameObject other = collision.gameObject;

            if (other.CompareTag(Constants.BallTag))
            {
                sfxId = SfxId.Ball;

                Ball otherBall = other.GetComponent <Ball>();
                if (this.type == otherBall.type)
                {
                    otherBall.destroy = true;
                    this.upgrade      = true;

                    this.color = otherBall.color = Color.white;
                }
            }
            else if (other.CompareTag(Constants.WallTag))
            {
                sfxId = SfxId.Ball;
            }

            GameHelper.PlaySound(sfxId);
        }
Esempio n. 2
0
 public void PlaySe(SfxId id)
 {
     if (this.seSource.isPlaying)
     {
         this.seSource.Stop();
     }
     this.seSource.clip = ClipById(id);
     this.seSource.Play();
 }
Esempio n. 3
0
 public static void PlaySound(SfxId id)
 {
     switch (id)
     {
     case SfxId.BUTTON_CLICK_1:
         RuntimeManager.PlayOneShot(Object.SFX_BUTTON_CLICK_1);
         break;
     }
 }
Esempio n. 4
0
        /// <summary>
        /// See the interface method for documentation on use. Implementation-wise, this method calculates
        /// the volume as the product of the master and sfx volume (both of which are 0 to 1). There is also
        /// a somewhat complicated mechanism to ensure that the audio engine is initialized. This is necessary because we may want to play multiple sounds one shortly after another.
        /// </summary>
        /// <param name="id">The sound effect to play.</param>
        /// <seealso cref="ISfxPlayerService.PlaySoundEffectAsync(SfxId)"/>
        public async Task PlaySoundEffectAsync(SfxId id)
        {
            await EnsureInitializedAsync();

            // Play sound
            if (!_gameSettings.Audio.Mute)
            {
                string file = _filenames[id];
                double gain = _gameSettings.Audio.MasterVolume * (_gameSettings.Audio.SfxVolume / 10000.0);
                await PlaySound(id, gain);
            }
        }
Esempio n. 5
0
        private AudioClip ClipById(SfxId id)
        {
            switch (id)
            {
            case SfxId.LineClear:
                return(this.lineClear);

            case SfxId.TetriminoTurn:
                return(this.turn);

            case SfxId.GameOver:
                return(this.gameOver);
            }
            return(null);
        }
Esempio n. 6
0
        /// <summary>
        /// Plays a sound file
        /// </summary>
        /// <param name="file">File</param>
        /// <param name="gain">Gain</param>
        /// <returns></returns>
        private async Task PlaySound(SfxId id, double gain)
        {
            _lastSoundId++;
            int thisSoundId = _lastSoundId;
            await Task.Delay(80);

            if (thisSoundId != _lastSoundId)
            {
                return;
            }
            var fileInputNodeResult = await _audioGraph.CreateFileInputNodeAsync(_loaded[id]);

            var fileInputNode = fileInputNodeResult.FileInputNode;

            fileInputNode.FileCompleted += FileInputNodeOnFileCompleted;
            fileInputNode.AddOutgoingConnection(_outputNode, gain);
        }
Esempio n. 7
0
        public void PlaySfx(SfxId sfxId)
        {
            var sfxInfo = _sfxSettings.GetSfxInfo(sfxId);

            switch (sfxId)
            {
            case SfxId.Shot:
                _audioViewFactory.Create(sfxInfo.AudioClip, sfxInfo.MixerGroup, Random.Range(0.8f, 1.1f), 0f);
                break;

            case SfxId.Pop:
                _audioViewFactory.Create(sfxInfo.AudioClip, sfxInfo.MixerGroup, Random.Range(0.9f, 1.1f),
                                         Random.Range(0f, 0.2f));
                break;

            case SfxId.Explosion:
                _audioViewFactory.Create(sfxInfo.AudioClip, sfxInfo.MixerGroup, 1f, 0f);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(sfxId), sfxId, null);
            }
        }
Esempio n. 8
0
 public override void Reset()
 {
     sfxId = SfxId.None;
 }
Esempio n. 9
0
 public SfxInfo GetSfxInfo(SfxId sfxId)
 {
     return(_sfxFiles.First(x => x.SfxId == sfxId));
 }
        public static void PlaySound(SfxId sfxId)
        {
            SoundMessage soundMessage = GameContext.messageDispatcher.AddMessage <SoundMessage>();

            soundMessage.sfxId = sfxId;
        }