A Razor UI component for the player's ammo display. It returns early if there is no local player or no current equipment, otherwise it renders a label with the equipment's ammo string and includes a stylesheet attribute. It also defines a Player reference and an unused WeaponComponent, and overrides BuildHash to force re-rendering based on Time.Now when a player exists.
@namespace KOTH.UI
@inherits Panel
@attribute [StyleSheet]
@if ( !Player.IsValid() )
return;
@if ( !Player.CurrentEquipment.IsValid() )
return;
<root>
<label class="ammo">@(Player.CurrentEquipment.GetAmmoString())</label>
</root>
@code
{
public PlayerPawn Player => PlayerState.Local.PlayerPawn;
public InputWeaponComponent WeaponComponent;
protected override int BuildHash()
{
if (!Player.IsValid())
return 0;
return HashCode.Combine(Time.Now);
}
}