mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 09:35:34 +00:00
Weapon sounds
This commit is contained in:
parent
47f8252e65
commit
280af2fcfa
7 changed files with 158 additions and 188 deletions
|
|
@ -28,6 +28,9 @@ public partial class Weapon3D : Node3D
|
|||
|
||||
[Signal]
|
||||
public delegate void EmptyEventHandler();
|
||||
|
||||
[Signal]
|
||||
public delegate void InitializedEventHandler();
|
||||
|
||||
public int Ammo { get; set; } = 0;
|
||||
|
||||
|
|
@ -83,6 +86,8 @@ public partial class Weapon3D : Node3D
|
|||
{
|
||||
LoadedAmmo = WeaponData.BulletCapacity;
|
||||
}
|
||||
|
||||
EmitSignalInitialized();
|
||||
}
|
||||
|
||||
private void RechargeTimerOnTimeout()
|
||||
|
|
|
|||
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();
|
||||
}
|
||||
}
|
||||
1
Scripts/Weapons/WeaponSoundModule3D.cs.uid
Normal file
1
Scripts/Weapons/WeaponSoundModule3D.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cqwi5bt8mxykn
|
||||
Loading…
Add table
Add a link
Reference in a new issue