Table of Contents

Class UIFactory

Namespace
S1API.UI
Assembly
S1API.dll

Utility class for constructing and configuring various UI elements in Unity.

public static class UIFactory
Inheritance
UIFactory
Inherited Members

Remarks

Provides static helpers for building complex hierarchies—panels, text, layouts, scroll views, buttons, etc.— while handling RectTransform setup, layout components, and consistent styling in one place.

Methods

BindAcceptButton(Button, Text, string, UnityAction)

Updates a button's display text and binds the supplied click callback.

public static void BindAcceptButton(Button btn, Text label, string text, UnityAction callback)

Parameters

btn Button

Button to configure.

label Text

Text component associated with the button.

text string

Text to assign to the label.

callback UnityAction

Delegate invoked when the button is clicked.

ButtonRow(string, Transform, float, TextAnchor)

Creates a container configured with a UnityEngine.UI.HorizontalLayoutGroup for arranging buttons in a row.

public static GameObject ButtonRow(string name, Transform parent, float spacing = 12, TextAnchor alignment = 4)

Parameters

name string

Name of the row GameObject.

parent Transform

Transform that will hold the row.

spacing float

Spacing between children in the layout (defaults to 12).

alignment TextAnchor

Child alignment; defaults to UnityEngine.TextAnchor.MiddleCenter.

Returns

GameObject

The created row GameObject.

ButtonWithLabel(string, string, Transform, Color, float, float)

Creates a rectangular button with a centered text label and returns useful components.

public static (GameObject, Button, Text) ButtonWithLabel(string name, string label, Transform parent, Color bgColor, float Width, float Height)

Parameters

name string

Name assigned to the button GameObject.

label string

Text displayed in the button.

parent Transform

Parent transform for the button.

bgColor Color

Background color for the button image.

Width float

Desired width in pixels.

Height float

Desired height in pixels.

Returns

(GameObject, Button, Text)

A tuple of (GameObject, Button, Text) for further configuration.

ClearChildren(Transform)

Destroys all child GameObjects of the provided parent Transform.

public static void ClearChildren(Transform parent)

Parameters

parent Transform

Transform to clear.

CreateQuestRow(string, Transform, out GameObject, out GameObject)

Constructs a quest row entry with dedicated icon/text panels and common layout settings.

public static GameObject CreateQuestRow(string name, Transform parent, out GameObject iconPanel, out GameObject textPanel)

Parameters

name string

Name suffix applied to generated GameObjects.

parent Transform

Parent transform for the row.

iconPanel GameObject

Outputs the panel intended for quest icons.

textPanel GameObject

Outputs the panel intended for quest title/description.

Returns

GameObject

The fully constructed row GameObject.

CreateRowButton(GameObject, UnityAction, bool)

Adds a UnityEngine.UI.Button component to a row container and wires up click/interactability.

public static void CreateRowButton(GameObject go, UnityAction clickHandler, bool enabled)

Parameters

go GameObject

Target GameObject that already has an UnityEngine.UI.Image for visuals.

clickHandler UnityAction

Callback to invoke on button click.

enabled bool

Whether the resulting button should start as interactable.

CreateTextBlock(Transform, string, string, bool)

Creates a stacked title/subtitle block and optionally appends a completed label.

public static void CreateTextBlock(Transform parent, string title, string subtitle, bool isCompleted)

Parameters

parent Transform

Transform that will receive the text elements.

title string

Primary heading displayed in bold.

subtitle string

Secondary descriptive text below the title.

isCompleted bool

Adds an "Already Delivered" status line when true.

FitContentHeight(RectTransform)

Ensures a content UnityEngine.RectTransform grows tall enough to fit its children.

public static void FitContentHeight(RectTransform content)

Parameters

content RectTransform

The RectTransform whose vertical size should adapt to its children.

Remarks

Adds a UnityEngine.UI.ContentSizeFitter if one is missing and configures it for preferred vertical sizing.

HorizontalLayoutOnGO(GameObject, int, int, int, int, int, TextAnchor)

Adds a UnityEngine.UI.HorizontalLayoutGroup to a GameObject and preconfigures its sizing behavior.

public static void HorizontalLayoutOnGO(GameObject go, int spacing = 10, int padLeft = 0, int padRight = 0, int padTop = 0, int padBottom = 0, TextAnchor alignment = 4)

Parameters

go GameObject

GameObject that should host the layout group.

spacing int

Spacing between children; defaults to 10.

padLeft int

Left padding value.

padRight int

Right padding value.

padTop int

Top padding value.

padBottom int

Bottom padding value.

alignment TextAnchor

Child alignment; defaults to UnityEngine.TextAnchor.MiddleCenter.

Panel(string, Transform, Color, Vector2?, Vector2?, bool)

Creates a UI panel GameObject with an Image background and configurable anchoring.

public static GameObject Panel(string name, Transform parent, Color bgColor, Vector2? anchorMin = null, Vector2? anchorMax = null, bool fullAnchor = false)

Parameters

name string

Name of the panel GameObject.

parent Transform

Transform that becomes the parent of the panel.

bgColor Color

Color applied to the panel background.

anchorMin Vector2?

Optional minimum anchor; defaults to centered anchor.

anchorMax Vector2?

Optional maximum anchor; defaults to centered anchor.

fullAnchor bool

When true, stretches the panel to fill its parent regardless of anchor arguments.

Returns

GameObject

The created panel GameObject (with RectTransform/Image components attached).

RoundedButtonWithLabel(string, string, Transform, Color, float, float, int, Color)

Creates a rounded button composed of a mask container, button, and centered text label.

public static (GameObject, Button, Text) RoundedButtonWithLabel(string name, string label, Transform parent, Color bgColor, float width, float height, int fontSize, Color textColor)

Parameters

name string

Name of the underlying button GameObject.

label string

Text shown inside the button.

parent Transform

Parent transform for the mask container.

bgColor Color

Background color applied to the inner button.

width float

Preferred width for the control (also applied to a LayoutElement).

height float

Preferred height for the control.

fontSize int

Font size for the label.

textColor Color

Color of the label text.

Returns

(GameObject, Button, Text)

The tuple (mask container GameObject, Button component, Text component).

ScrollableVerticalList(string, Transform, out ScrollRect)

Builds a ScrollRect hierarchy configured for vertical scrolling and returns the content RectTransform.

public static RectTransform ScrollableVerticalList(string name, Transform parent, out ScrollRect scrollRect)

Parameters

name string

Name of the root scroll view GameObject.

parent Transform

Transform that will own the scroll view.

scrollRect ScrollRect

Outputs the created UnityEngine.UI.ScrollRect component.

Returns

RectTransform

The RectTransform of the content container where list items should be added.

SetIcon(Sprite, Transform)

Sets an icon as a child of the specified parent transform with the given sprite.

public static void SetIcon(Sprite sprite, Transform parent)

Parameters

sprite Sprite

The sprite to be used as the icon.

parent Transform

The transform that will act as the parent of the icon.

SetLayoutGroupPadding(LayoutGroup, int, int, int, int)

Convenience helper to configure the padding on any UnityEngine.UI.LayoutGroup.

public static void SetLayoutGroupPadding(LayoutGroup layoutGroup, int left, int right, int top, int bottom)

Parameters

layoutGroup LayoutGroup

Target layout group.

left int

Left padding value.

right int

Right padding value.

top int

Top padding value.

bottom int

Bottom padding value.

Text(string, string, Transform, int, TextAnchor, FontStyle)

Creates a UnityEngine.UI.Text element configured with the supplied content and styling.

public static Text Text(string name, string content, Transform parent, int fontSize = 14, TextAnchor anchor = 0, FontStyle style = 0)

Parameters

name string

Name of the GameObject to create.

content string

Initial string displayed inside the text component.

parent Transform

Transform that will contain the new text element.

fontSize int

Font size to apply, defaults to 14.

anchor TextAnchor

Text alignment; defaults to UnityEngine.TextAnchor.UpperLeft.

style FontStyle

Font style flag; defaults to UnityEngine.FontStyle.Normal.

Returns

Text

The configured Text(string, string, Transform, int, TextAnchor, FontStyle) component.

TopBar(string, Transform, string, float, int, int, int, int)

Creates a top-bar container with padding, title text, and layout metadata.

public static GameObject TopBar(string name, Transform parent, string title, float topbarSize, int paddingLeft, int paddingRight, int paddingTop, int paddingBottom)

Parameters

name string

Name of the bar GameObject.

parent Transform

Transform that will contain the bar.

title string

Display text shown in the bar.

topbarSize float

Normalized height (Y anchor) reserved for the bar.

paddingLeft int

Left padding applied by the layout group.

paddingRight int

Right padding applied by the layout group.

paddingTop int

Top padding applied by the layout group.

paddingBottom int

Bottom padding applied by the layout group.

Returns

GameObject

The instantiated bar GameObject.

VerticalLayoutOnGO(GameObject, int, RectOffset?)

Adds and configures a UnityEngine.UI.VerticalLayoutGroup on the supplied GameObject.

public static void VerticalLayoutOnGO(GameObject go, int spacing = 10, RectOffset? padding = null)

Parameters

go GameObject

GameObject that should host the layout.

spacing int

Spacing between children in pixels (default 10).

padding RectOffset

Optional padding override; defaults to 10px on every side.