Skip to content
This repository was archived by the owner on Feb 20, 2025. It is now read-only.

UI System

ZeroTwo edited this page Aug 23, 2024 · 5 revisions

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 immagine

Note that a class that could be helpful is HintHelper

Clone this wiki locally