From install to your first screen
Install the package, open the UI Setup Manager and show a screen from code. The Tutorial walks through every step with screenshots and videos.
Requirements
| Unity | 2022.3 or newer (the showcase project uses Unity 6) |
|---|---|
| Addressables | 1.21.0 or newer, installed automatically as a dependency |
| UI | UGUI (com.unity.ugui). Any content works inside your scenes: Text, TextMeshPro, images, your own components |
| Platforms | Everything Unity and Addressables support. All animation runs on unscaled time |
1. Install the package
In Unity, open and paste:
https://github.com/dawaniyah-games/UiFramework.git?path=Packages/com.dawaniyahgames.uiframeworkTo pin a version, append #vX.Y.Z (see Releases), or add it to Packages/manifest.json:
{
"dependencies": {
"com.dawaniyahgames.uiframework": "https://github.com/dawaniyah-games/UiFramework.git?path=Packages/com.dawaniyahgames.uiframework#v1.3.6"
}
}2. Set up the project
- Open .
- In the General tab press Create Config. Set your script and scene folders and your game's namespaces on the created
UiEditorConfig. - Check the Global Canvas Settings in the same tab: every new element scene starts with them.
3. Make your first screen
- Elements tab → ➕ New Element → name it
MainMenuUiElement→ Create. You get the script and a scene laid out asMainMenuUiElementRoot → Canvas → Root. - Build your UI under
Rootand pick a show and hide animation in the element's Animations section. - States tab → type
MainMenuUiStatenext to New state → ➕. Add theMainMenuUiElementscene to it. - General tab → Build Runtime UiConfig. Run it again after every state or scene change.
4. Show it from code
UiManager creates itself; don't add it to a scene. It loads the generated config from Addressables.
using System;
using UiFramework.Runtime.Manager;
using UnityEngine;
public class GameBootstrap : MonoBehaviour
{
// async void is fine for Unity messages, as long as exceptions are caught and logged.
private async void Start()
{
try
{
if (!UiManager.IsInitialized)
{
await UiManager.InitializeAsync();
}
await UiManager.ShowState<MainMenuUiState>();
}
catch (Exception exception)
{
Debug.LogError("[GameBootstrap] UI failed to start: " + exception);
}
}
}With the Addressables play mode set to Use Asset Database (), the screen appears right away. For a player build, build Addressables content first.
5. Give the screen its data
Whatever you pass to ShowState reaches every element of the state in Populate. Keep Populate idempotent: it runs again when another state reuses the scene.
using UiFramework.Core;
using UnityEngine;
using UnityEngine.UI;
public class MainMenuParams : UiPopulationParams
{
public string PlayerName { get; set; }
}
public class MainMenuUiElement : UiElement
{
[SerializeField] private Text welcomeLabel;
public override void Populate(object context = null)
{
base.Populate(context);
MainMenuParams data = context as MainMenuParams;
if (data == null)
{
return;
}
welcomeLabel.text = "Welcome back, " + data.PlayerName;
}
}MainMenuParams data = new MainMenuParams();
data.PlayerName = "Alex";
await UiManager.ShowState<MainMenuUiState>(data);Context is just an object. Pass a primitive and read it with context is int coins.
Default project layout
All paths are settings on your UiEditorConfig; these are the defaults.
| What | Where |
|---|---|
| Element scripts | Assets/Scripts/Ui/UiElements |
| Element scenes | Assets/Scenes/UiElements |
| State scripts | Assets/Scripts/Ui/UiStates |
| State definitions | Assets/UiConfigs/UiStateDefinitions |
| Runtime config (generated) | Assets/UiConfigs/RuntimeUiConfig.asset |
| Global canvas settings | Assets/UiConfigs/UiGlobalCanvasSettings.asset |