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]
44 lines
847 B
C#
44 lines
847 B
C#
namespace Sandbox;
|
|
|
|
/// <summary>
|
|
/// A gib is a prop that is treated slightly different. It will fade out after a certain amount of time.
|
|
/// </summary>
|
|
[Expose]
|
|
[Title( "Gib" )]
|
|
[Category( "Game" )]
|
|
[Icon( "broken_image" )]
|
|
public class Gib : Prop
|
|
{
|
|
public float FadeTime { get; set; }
|
|
|
|
protected override void OnEnabled()
|
|
{
|
|
base.OnEnabled();
|
|
|
|
if ( FadeTime > 0 && !Scene.IsEditor )
|
|
{
|
|
_ = RunGib();
|
|
}
|
|
}
|
|
|
|
async Task RunGib()
|
|
{
|
|
await Task.DelaySeconds( FadeTime + Random.Shared.Float( 0, 2.0f ) );
|
|
|
|
if ( !IsValid )
|
|
return;
|
|
|
|
var modelComponent = Components.Get<ModelRenderer>();
|
|
if ( modelComponent is not null )
|
|
{
|
|
for ( float f = modelComponent.Tint.a; f > 0.0f; f -= Time.Delta )
|
|
{
|
|
modelComponent.Tint = modelComponent.Tint.WithAlpha( f );
|
|
await Task.Frame();
|
|
}
|
|
}
|
|
|
|
GameObject.Destroy();
|
|
}
|
|
}
|