Screen Manager
Tool for managing windows and layouts in Unity.
com.endelways.screenmanager Install via UPM
Add to Unity Package Manager using this URL
https://www.pkglnk.dev/track/screenmanager.git?path=Packages/com.endelways.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
Installs Over Time
Operating Systems
No data yet
Top Countries
No data yet
Git Versions
No data yet
Embed Install Badge
Add an install count badge to your README
[](https://www.pkglnk.dev/pkg/screenmanager)<a href="https://www.pkglnk.dev/pkg/screenmanager"><img src="https://www.pkglnk.dev/badge/screenmanager.svg?style=pkglnk" alt="pkglnk installs"></a>
No comments yet. Be the first!