mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-03 03:48:24 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
38 lines
872 B
C#
38 lines
872 B
C#
|
|
namespace Sandbox;
|
|
|
|
public partial class GameObject
|
|
{
|
|
/// <summary>
|
|
/// Play this sound on this GameObject. The sound will follow the position of the GameObject.
|
|
/// You'll be able to use GameObject.StopAllSounds to stop all sounds that are following this GameObject.
|
|
/// </summary>
|
|
[ActionGraphInclude]
|
|
public SoundHandle PlaySound( SoundEvent sound, Vector3 positionOffset = default )
|
|
{
|
|
if ( !sound.IsValid() )
|
|
return default;
|
|
|
|
var sh = Sound.Play( sound, WorldPosition );
|
|
|
|
if ( sh is null )
|
|
return default;
|
|
|
|
sh.Parent = this;
|
|
sh.FollowParent = true;
|
|
sh.LocalTransform = new Transform( positionOffset );
|
|
|
|
return sh;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Stop any sounds playing on this GameObject
|
|
/// </summary>
|
|
[ActionGraphInclude]
|
|
public void StopAllSounds( float fadeOutTime = 0.0f )
|
|
{
|
|
SoundHandle.StopAllWithParent( this, fadeOutTime );
|
|
}
|
|
|
|
}
|