top of page
Unity UI System screenshot

Unity UI System:
Diecast Scalper

My highest graded artefact from my degree so far is this retained UI System I built from the ground up in Unity showcased through a small demo: Diecast Scalper. I was able to construct a UI system with a clean structure and consistent in-game functionality. The UI system provides the core features required to create a dynamic, interactive UI for a game. I demonstrated the system’s practical viability through the creation of a UI-based gameplay demo.

This was developed in Unity, programmed using C#. Source Code is available at the bottom of the page. 

DiecastScalper.mp4
00:00/00:00

UI System Architecture

The UI components were created using inheritance and polymorphism. The system includes UI elements such as containers, buttons, labels, and progress bars, all of which inherit from a base class UIControl. This class provides the basic variables and functionality of an onscreen UI element, as well as overridable functions that can be adjusted to suit the needs of other UI elements.

 

Below is a UML diagram that shows the inheritance structure of UI elements. 

Screenshot 2026-05-28 112825.png

Retained UI System

Interactive UI elements' states are updated via functions and finite-state machines, with states stored as enumerators. This allows the UI system to follow the retained structure whilst being able to update dynamically without the use of any tick method.

Button.mp4

The tweening for UI elements such as buttons and timed progress bars was implemented using Unity's IEnumerator. This provides a smooth transition that can be executed when necessary, while avoiding the cost of running a tick method every frame. These IEnumerators are invoked via functions. Below shows the button tweening logic.

Screenshot 2026-05-28 105727.png

To invoke the functions of interactive UI elements, I created a pointer control script. This casts a ray from the mouse's position when the mouse is moved. The ray gets the first UI element it makes contact with and executes the MouseEnter. Mouse interaction triggers the MouseDown and MouseUp functions, and upon leaving the UI element, MouseExit is called. As mouse interaction functions are declared in the UIControl, all UI elements have the ability to interact with the mouse.

UI Interaction.mp4

UI Elements

The base UI element is the control, this contains a brush as well as interaction functionality.

UIControl

Screenshot 2026-05-28 121527.png

This contains the same properties as the UIControl, he only difference being that it displays text. The text properties such as centre, alignment, and font can all be adjusted.

UILabel

Screenshot 2026-05-28 121650.png

This acts as a container for UI elements, calling functions such as SetVisibility, Enable, and Disable will affect all UI elements in the container

UIContainer

Screenshot 2026-05-28 121830.png

This is a varient of the UIContainer that organises UI elements into a Vertical, Horizontal, or Grid list. Properties such as spacing, centre, and list type can be manually adjusted in the inspector.

UIList

UIList.mp4
Screenshot 2026-05-28 122036.png

The button contains a brush for its default, hovered, pressed, and disabled states. Different states are applied through invoking the mouse interaction, enable, and disable functions. Smooth or instant transitions between states can be toggled by the user, transition speed can also be adjusted.

UIButton

UIButtonTrans.mp4
Screenshot 2026-05-28 123831.png

The progress bar contains a bar and filler brush. The direction of the filler can be changed in the inspector, Progress can be added by invoking the SetFillAmount function.

UIProgressBar

Screenshot 2026-05-28 124132.png

The timed progress bar progresses at a constant rate defined by it target time. This inherits the same functionality as the normal progress bar, however removes the functionality of SetFillAmount to avoid any overwriting of the progress.

UITimedProgressBar

Screenshot 2026-05-28 124207.png

Abstract Classes

The abstract classes contain data that define common properties of the UI elements. The variable's protection level in these classes are protected and can only be accessed in the editor; however, each class contains public setters and getters to adjust their values. The classes also contain a constructor and empty constructor that can be used to instantiate a new properties in code. 

This contains the basic components of a brush that can be used display an image. This includes a sprite, color, and pixels per unit.

UIBrush

Screenshot 2026-05-28 121033.png

This contains the basic components required to display text. This includes variables such as string, alignment, and font properties.

UIText

Screenshot 2026-05-28 121058.png

Code path: Assets/Scripts/BaseUIScripts 

bottom of page