mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-02 11:28:19 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
51 lines
1.1 KiB
C#
51 lines
1.1 KiB
C#
namespace Sandbox;
|
|
|
|
/// <summary>
|
|
/// Implements logic for the SoundScape system
|
|
/// </summary>
|
|
[Expose]
|
|
sealed class SceneSoundscapeSystem : GameObjectSystem<SceneSoundscapeSystem>
|
|
{
|
|
public SceneSoundscapeSystem( Scene scene ) : base( scene )
|
|
{
|
|
Listen( Stage.UpdateBones, 0, Update, "TickSoundScapes" );
|
|
}
|
|
|
|
SoundscapeTrigger active;
|
|
RealTimeSince timeSinceUpdate;
|
|
|
|
void Update()
|
|
{
|
|
if ( Scene.IsEditor )
|
|
return;
|
|
|
|
if ( timeSinceUpdate < 0.2f )
|
|
return;
|
|
|
|
timeSinceUpdate = 0;
|
|
|
|
var head = Sound.Listener;
|
|
|
|
// Find the closest soundscape, sphere and box take priority over point.
|
|
var best = Scene.GetAllComponents<SoundscapeTrigger>()
|
|
.Where( x => x.TestListenerPosition( head.Position ) )
|
|
.MinBy( x => (x.Type == SoundscapeTrigger.TriggerType.Point ? 1 : 0, x.WorldPosition.DistanceSquared( head.Position )) );
|
|
|
|
if ( best == active )
|
|
return;
|
|
|
|
if ( best == null && active.StayActiveOnExit )
|
|
return;
|
|
|
|
if ( active is not null )
|
|
active.Playing = false;
|
|
|
|
active = best;
|
|
|
|
if ( active is not null )
|
|
active.Playing = true;
|
|
|
|
|
|
}
|
|
}
|