UI/MoneyWaft.razor

A Razor UI component that displays a floating money popup. It reads an integer value from the GameObject name (format "MoneyWaft:<value>"), animates the world position upward with random drift, fades the UI over a fixed lifetime, and destroys the GameObject when done.

File Access
@using System
@using Sandbox
@using Sandbox.UI
@namespace BrickJam.UI
@inherits PanelComponent

<root>
	<span class="value">+$@Value</span>
</root>

@code {
	private const float Lifetime = 1.2f;

	private int Value;
	private Vector3 direction;
	private float speed;
	private TimeSince since;

	protected override void OnStart()
	{
		// Value is passed via the GameObject name ("MoneyWaft:150") so the spawning gameplay code
		// doesn't have to reference this razor type.
		var name = GameObject.Name ?? "";
		var colon = name.IndexOf( ':' );
		if ( colon >= 0 )
			int.TryParse( name[(colon + 1)..], out Value );

		direction = (Vector3.Up + Vector3.Random * 0.35f).Normal;
		speed = 60f + Random.Shared.NextSingle() * 70f;
		since = 0f;
	}

	protected override void OnUpdate()
	{
		WorldPosition += direction * speed * Time.Delta;

		var frac = ((float)since / Lifetime).Clamp( 0f, 1f );
		if ( Panel is not null )
			Panel.Style.Opacity = 1f - frac;

		if ( since >= Lifetime )
			GameObject.Destroy();
	}

	protected override int BuildHash() => HashCode.Combine( Value );
}

<style>
	MoneyWaft {
		justify-content: center;
		align-items: center;

		.value {
			font-size: 54px;
			font-family: alagard;
			color: rgba(50,205,50,1);
			text-shadow: 3px 3px 0px black;
		}
	}
</style>