Screen Manager
Screen Manager streamlines window and layout management in Unity applications by providing a flexible, service-based system for controlling UI screens. Extend the base Screen class to create custom windows, pass data through ScreenOptions, and leverage reusable screens that persist state without destruction. Prefabs are automatically loaded from a configurable Resources folder, reducing boilerplate code and enabling efficient UI workflows.
com.endelways.screenmanager 
Install via UPM
Add to Unity Package Manager using this URL
https://www.pkglnk.dev/screenmanager.git?path=Packages/com.endelways.screenmanager README Markdown
Copy this to your project's README.md
## Installation
Add **Screen Manager** to your Unity project via Package Manager:
1. Open **Window > Package Manager**
2. Click **+** > **Add package from git URL**
3. Enter:
```
https://www.pkglnk.dev/screenmanager.git?path=Packages%2Fcom.endelways.screenmanager
```
[](https://www.pkglnk.dev/pkg/screenmanager)README
It's a small unity package, which give you ability for control windows in your application
Documentation
You can use Screen as base type for create your own window type
Example:
public class InventoryScreen : Screen
{
[SerializeField] private Transform inventoryGrid;
[SerializeField] private InventoryMoneyView moneyView;
private InventorySlotView[] _itemSlots;
private Inventory _inventory;
[Inject]
private void Setup(Inventory inventory)
{
_inventory = inventory;
}
public override void OnOpened(IScreenOptions options)
{
base.OnOpened(options);
_itemSlots = inventoryGrid.GetComponentsInChildren<InventorySlotView>();
foreach (var item in _inventory.GetItemList())
{
if (item.Item.IsNotSlotItem)
{
moneyView.SetText(item.Count.ToString());
continue;
}
_itemSlots[item.SlotId].SetItem(item);
}
}
}
In inspector you can use checkbox IsReusableScreen for describes YourScreen as reusable screen.

Reusable screen can be hided without destroying and will be showed with previous data in future.
Now you need add this script as component in root object of window prefab.

${\Huge{\textsf{\color{red}{Important:}}}}$ All screen prefabs must be in specifed folder - Resources/Screens
Resources folder can be in any folder
In Screens folder you can create any subfolder
Full path example - Assets/Prefabs/Resources/Screens/InventoryScreens/ChestInventoryScreen.prefab
You can then manage this window using the service
First you need create serivce, for example in di installer:
Container.BindInstance(new ScreenService(screenContainer)).AsSingle().NonLazy();
As argument you need to use some transform which will parent for all windows.
When you use Show() method, window prefab will be instantiated as child of this transform.
You can use next methods of ScreenService:
Show<YourScreen>(ISceenOptions options)- Instantiates or shows previously disabled prefab withYourScreencomponent in the specifed root transform
You can useScreenOptionsclass for transfer data toYourScreencomponent
Example:In place where you executing show method from service:
int a = 5; Show<YourScreen>(new ScreenOptions<int>(a)) // - send data to YourScreen componentIn YourScreen class:
public override void OnOpened(IScreenOptions options) // recive data { base.OnOpened(options); if (options.Value is not int data) return; // check if data correct and cast object to your data type Debug.Log(data); - use data }if prefab with Component YourSceen doesn't exist, it throws exeption
if prefab was instantiated previously and now enabled nothing will happenClose<YourScreen>()- Destroys prefab with YourScreen component in the specifed root transform
if prefab with Component didnt't instantiated it throws exceptionHide<YourScreen>()- Disables prefab with YourScreen component in the specifed root transform
if prefab with Component didnt't instantiated it throws exception
if YourScreen prefab is not ReusableScreen it will be work asClose<YourScreen>()
You can use some events in YourScreen script for recive data or control lifecycle of your objects, you need override it for use:
YourScreen.OnOpened(IScreenOptions options)- executes every time when prefab with YourScreen component instatiates
options is null by defaultYourScreen.OnDisplay()- executes every time when prefab with YourScreen component instatiates, and when hided prefabs shows againYourScreen.OnClosed()- executes every time when prefab with YourScreen component destroysYourScreen.OnHide()- executes every time when prefab with YourScreen component destroys and when reusableView hides
Comments
No comments yet. Be the first!
Sign in to join the conversation
Sign In