mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-04 04:45:53 +00:00
Weapon sounds
This commit is contained in:
parent
47f8252e65
commit
280af2fcfa
7 changed files with 158 additions and 188 deletions
55
Scripts/Weapons/WeaponSoundModule3D.cs
Normal file
55
Scripts/Weapons/WeaponSoundModule3D.cs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Weapons;
|
||||
|
||||
public partial class WeaponSoundModule3D : Node
|
||||
{
|
||||
[Export] public Weapon3D Weapon { get; private set; }
|
||||
|
||||
[Export] public AudioStreamPlayer3D ShootSound { get; private set; }
|
||||
[Export] public AudioStreamPlayer3D ReloadSound { get; private set; }
|
||||
[Export] public AudioStreamPlayer3D EmptySound { get; private set; }
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Weapon.Initialized += WeaponOnInitialized;
|
||||
}
|
||||
|
||||
private void WeaponOnInitialized()
|
||||
{
|
||||
if (Weapon?.WeaponData is null) return;
|
||||
|
||||
if (Weapon.WeaponData.ShootSound is not null)
|
||||
{
|
||||
ShootSound.Stream = Weapon.WeaponData.ShootSound;
|
||||
Weapon.Shooting += WeaponOnShooting;
|
||||
}
|
||||
|
||||
if (Weapon.WeaponData.ReloadSound is not null)
|
||||
{
|
||||
ReloadSound.Stream = Weapon.WeaponData.ReloadSound;
|
||||
Weapon.Reloading += WeaponOnReloading;
|
||||
}
|
||||
|
||||
if (Weapon.WeaponData.EmptySound is not null)
|
||||
{
|
||||
EmptySound.Stream = Weapon.WeaponData.EmptySound;
|
||||
Weapon.Empty += WeaponOnEmpty;
|
||||
}
|
||||
}
|
||||
|
||||
private void WeaponOnEmpty()
|
||||
{
|
||||
EmptySound.Play();
|
||||
}
|
||||
|
||||
private void WeaponOnReloading()
|
||||
{
|
||||
ReloadSound.Play();
|
||||
}
|
||||
|
||||
private void WeaponOnShooting()
|
||||
{
|
||||
ShootSound.Play();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue