-
Notifications
You must be signed in to change notification settings - Fork 0
UI System
Currently the UI System is Really Basic!
We have 2 main classes that we need to use UIManager an important class because of his core functionality and the GameDisplayBuilder.
So now lets break down how the system works.
We need a Player and a Class that imports GameDisplayBuilder
An Example class could be
public class PersonalDisplayBuilder : GameDisplayBuilder
{
private readonly StringBuilder _builder;
private string ServerName = "MySCPSL Server";
public PersonalDisplayBuilder(StringBuilder builder) : base(builder)
{
_builder = builder;
}
~PersonalDisplayBuilder() => StringBuilderPool.Shared.Return(_builder);
//Displayed When a player is not a spectator
public override void CustomUIAlive(StringBuilder builder, UIScreenZone zone)
{
if (zone == UIScreenZone.Bottom)
{
StringBuilder sb = new StringBuilder()
.SetSize(60, MeasurementUnit.Percentage)
.SetAlignment(AlignStyle.Left);
sb.SetIndent(-25, MeasurementUnit.Percentage)
.SetSize(1.5f, MeasurementUnit.Pixels)
.Append(PFP)
.CloseSize()
.CloseIndent();
sb.SetIndent(-15, MeasurementUnit.Percentage)
.AddVOffset(15, MeasurementUnit.Ems)
.Append(ServerName)
.CloseVOffset()
.CloseIndent();
builder.Append(sb.ToString());
}
}
//Displayed When a player is a spectator
public override void CustomUISpectator(StringBuilder builder, UIScreenZone zone)
{
}
}Now lets break down even more the code by the methods
- CustomUISpectator, Lets us show a gui that is for the Spectator
- CustomUIAlive, Lets us show a gui that is for the people alive (SCP Included)
Now that we know how to create and manage this Class we can now add the Component to the player and seeing the result in game
PersonalDisplayBuilder display = new PersonalDisplayBuilder(StringBuilderPool.Shared.Rent());
player.GameObject.AddComponent<UIManager>()._mainDisplay = display;Now the result in game will be

Note that a class that could be helpful is HintHelper
The advantage of this UI are endless you can send notification specific to a player (Currently its complicated but in the future it will be easier)
if (player.GameObject.TryGetComponent(out UIManager hud))
{
hud.AddMessage(UIScreenZone.Notifications, "Hey you got a notification", 10);
}This system can be used to send messages everywhere in the UI for some times.