codeAPI Reference
ReloadSoundEntry record struct
ReloadSoundEntry Record Struct
Defines a timed sound event to play during s&box weapon reload animations.
Properties
- Time (float) - Seconds after reload starts to play this sound
- Sound (SoundEvent) - The sound event to play
Usage
Used in ViewModel to define multiple timed sounds during reload sequences:
CSHARP
[Property, Group( "Reload Sounds" )]
public List<ReloadSoundEntry> ReloadSoundEvents { get; set; } = new();The ViewModel plays these sounds asynchronously during reload using Task.DelaySeconds():
CSHARP
private async Task PlaySoundsAsync( List<ReloadSoundEntry> events, CancellationToken ct )
{
var sorted = events.OrderBy( e => e.Time ).ToList();
var elapsed = 0f;
foreach ( var entry in sorted )
{
var delay = entry.Time - elapsed;
if ( delay > 0f )
await Task.DelaySeconds( delay, ct );
if ( ct.IsCancellationRequested )
return;
if ( entry.Sound is not null )
GameObject.PlaySound( entry.Sound );
elapsed = entry.Time;
}
}Related Properties
- ReloadSoundEvents - Timed sounds for standard reload
- IncrementalReloadSoundEvents - Timed sounds for each incremental reload cycle
- IncrementalReloadStartSounds - Timed sounds when starting incremental reload
- IncrementalReloadFinishSounds - Timed sounds when finishing incremental reload
Location
File: d:\GitHubStuff\sandbox\code\Game\Weapon\WeaponModel\ViewModel.cs
Was this helpful?