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); }
public void PlaySe(SfxId id) { if (this.seSource.isPlaying) { this.seSource.Stop(); } this.seSource.clip = ClipById(id); this.seSource.Play(); }
public static void PlaySound(SfxId id) { switch (id) { case SfxId.BUTTON_CLICK_1: RuntimeManager.PlayOneShot(Object.SFX_BUTTON_CLICK_1); break; } }
/// <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); } }
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); }
/// <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); }
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); } }
public override void Reset() { sfxId = SfxId.None; }
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; }