A Blazor-like Razor UI component that renders a grid of local spawnable entities. It queries ScriptedEntity resources, filters by developer flag and optional category, and displays each as a SpawnMenuIcon with its resource identifier, title and developer marker.
@using Sandbox;
@using Sandbox.UI;
@inherits Panel
@namespace Sandbox
<VirtualGrid Items=@Entities ItemSize=@(160)>
<Item Context="item">
@if (item is ScriptedEntity entry)
{
<SpawnMenuIcon Ident=@($"entity:{entry.ResourcePath}") [email protected] [email protected]></SpawnMenuIcon>
}
</Item>
</VirtualGrid>
@code
{
public string Category { get; set; }
List<ScriptedEntity> Entities = [];
protected override void OnParametersSet()
{
base.OnParametersSet();
var all = ResourceLibrary.GetAll<ScriptedEntity>()
.Where( e => !e.Developer || ServerSettings.ShowDeveloperEntities );
Entities = (Category is null
? all
: all.Where( e => (string.IsNullOrWhiteSpace( e.Category ) ? "Other" : e.Category) == Category )
).ToList();
}
}