Game/2D/UI/FloatPopupItem.razor

A UI Razor component that renders a floating popup div at a given screen position. It shows Text with an optional CSS class, supports rotation, has a lifetime, and destroys its GameObject after the lifetime expires.

File Access
@using Sandbox;
@using Sandbox.UI;
@inherits PanelComponent
@namespace Sandbox

<root style="position:absolute;left:@XPct.ToString("F1")%;top:@YPx.ToString("F0")px;width:0;height:0;overflow:visible;pointer-events:none;">
    <div class="float-popup @CssClass" style="@GetStyle()">@Text</div>
</root>




@code {
    public string Text { get; set; } = "";
    public string CssClass { get; set; } = "";
    public float XPct { get; set; }
    public float YPx { get; set; }
    public float  Rot      { get; set; } = 0f;
    public float Lifetime { get; set; } = 1.4f;

    float _spawnedAt;

    protected override void OnStart()
    {
        _spawnedAt = Time.Now;
    }

    protected override void OnUpdate()
    {
        if ( Time.Now >= _spawnedAt + Lifetime )
            GameObject.Destroy();
    }

    string GetStyle()
    {
        if (Rot == 0f) return "";
        return $"transform:rotate({Rot.ToString("F1")}deg);";
    }
}