UIManagerForMe
UIManager streamlines UI management in Unity by providing a Task-based system for handling asynchronous operations across resources, servers, and other APIs. It enables seamless display and management of pages and popups with unified async task orchestration, supporting multiple resource loading strategies (Resources, AssetBundle, Addressable) through a flexible IResourceLoader interface. Built on UniTask for efficient async handling in Unity 2021.3+.
com.chickengames.uimanager 
Install via UPM
Add to Unity Package Manager using this URL
https://www.pkglnk.dev/jongseonpark-uimanager.git?path=Assets/UIManager README Markdown
Copy this to your project's README.md
## Installation
Add **UIManagerForMe** 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/jongseonpark-uimanager.git?path=Assets%2FUIManager
```
[](https://www.pkglnk.dev/pkg/jongseonpark-uimanager)Dependencies (1)
README
UIManager
์ด ํ๋ก์ ํธ๋ Task ๊ธฐ๋ฐ์ UIManager๋ฅผ ์ ์ํ๊ธฐ ์ํด ๋ง๋ค์ด์ก์ต๋๋ค. resource, server๋ฑ์ ์ฌ๋ฌ ๋น๋๊ธฐ API์ ๋์ํ๊ธฐ ์ํด ๋น๋๊ธฐ Task๋ฅผ ํตํฉ ๊ด๋ฆฌํ์ฌ Page, Popup๋ฑ์ UI๋ฅผ ๋์ฐ๋๋ก ์ค๊ณ๋์์ต๋๋ค.
Page ๊ด๋ฆฌํ๋ ๋ชจ์ต

Popup ๊ด๋ฆฌํ๋ ๋ชจ์ต

์์์
- ์ ๋ํฐ์์ ๋น๋๊ธฐ ์ฌ์ฉ์ ํจ์จ์ ์ผ๋ก ์งํํ๊ธฐ ์ํ์ฌ UniTask๋ฅผ ์ฌ์ฉํ์ต๋๋ค. ํด๋น ๋ด์ฉ์ UniTask๋ฅผ ์ฐธ์กฐ.
- ํด๋นํ๋ก์ ํธ๋ Unity 2021.3, UniTask Ver.2.3.3์์ ํ ์คํธ ๋์์ต๋๋ค.
- namespace ๋ฑ์ ํฌํจ๋ ํ์ฌ๋ช ChickenGames๋ ํ์กดํ๋ ํ์ฌ๊ฐ ์๋๋ฉฐ, ๋ง์ฝ ๋ค๋ฅธ ๊ณณ์์ ์ฌ์ฉํ๊ณ ์๋ค๋ฉด ์ ์ ๋ฌด๊ดํฉ๋๋ค.
Getting Start
Release์์ ๊ด๋ จ ์ฝ๋ ์์ ๋ฅผ ๋ค์ด ๋ฐ์ ์ ์์ต๋๋ค.
UIManager Instance ์์ฑ
์ฌ์ฉํ๊ธฐ ์ ์ Instance๋ฅผ ์์ฑํด์ฃผ์ธ์. ๋งค๊ฐ๋ณ์๋ก๋ IResourceLoader, uiRoot๋ก ๊ตฌ์ฑ๋์ด ์์ต๋๋ค. uiRoot๋ UI์ ๋ถ๋ชจ๊ฐ ๋ transform์ ๋ฃ์ด์ฃผ์๋ฉด ๋ฉ๋๋ค.
public class UI_TestMain : MonoBehaviour
{
[SerializeField]
Transform uiRoot;
void Start()
{
UIManager.CreateInstance(new UnityResourceLoader(), uiRoot);
}
}
ResourceLoader
public interface IResourceLoader
{
UniTask<Object> LoadAsync(string path);
UniTask<Object> InstantiateAsync(string path, Transform parent = null, bool instantiateInWorldSpace = false);
bool ReleaseInstance(GameObject instance);
}
IResourceLoader๋ ๋ฆฌ์์ค ๋ก๋ ๋ฐฉ๋ฒ์ ์ง์ ํ๊ธฐ ์ํ ์ธํฐํ์ด์ค์ ๋๋ค. ์ ๋ํฐ๋ ํ๊ฒฝ์ ๋ฐ๋ผ ๋ฆฌ์์ค ๋ก๋ ๋ฐฉ์์ด ๋ฌ๋ผ์ง ์ ์์ต๋๋ค.
- Resources
- AssetBundle
- Adressable
๋๋ฌธ์ UIManager์ ์ธ์คํด์ค๋ฅผ ์์ฑ๋ ์ง์ ํ๊ธฐ ์ํด ์์ฑ๋์์ต๋๋ค. ๊ทธ๋ ๊ธฐ์ ์ฌ์ฉ์๊ฐ ๊ตฌํํด ์ค์ผ ํฉ๋๋ค. ์๋๋ Unity์ Resources๋ฅผ ๊ธฐ์ค์ผ๋ก ์์ฑํ ์ฝ๋์ ๋๋ค. Example์์ ์ฝ๋๋ฅผ ํ์ธํ ์ ์์ต๋๋ค.
public class UnityResourceLoader : IResourceLoader
{
public async UniTask<Object> InstantiateAsync(string path, Transform parent = null, bool instantiateInWorldSpace = false)
{
var objRes = await Resources.LoadAsync(path);
if (objRes == null)
{
Debug.LogError($"{path} is not exist..");
return null;
}
return Object.Instantiate(objRes, parent, instantiateInWorldSpace);
}
public async UniTask<Object> LoadAsync(string path)
{
return await Resources.LoadAsync(path);
}
public bool ReleaseInstance(GameObject instance)
{
Object.Destroy(instance);
return true;
}
}
Page ์์ฑ
PageBase๋ฅผ ์์๋ฐ์ Component๋ฅผ ์์ฑํด์ฃผ์ธ์. ๊ทธ๋ฆฌ๊ณ ์๋์ ๊ฐ์ด Init๋ฅผ ์์ฑํฉ๋๋ค.
LoadFuncAsyncs์์ Task๋ฅผ ์ถ๊ฐํฉ๋๋ค. ํด๋น ํ์ด์ง๋ LoadFuncAsyncs๊ฐ ์๋ฃ๋์ง ์๋ ํ ์ด๋ฆฌ์ง ์์ต๋๋ค.
public class TestMainPage : PageBase
{
[SerializeField]
Button openSubPageButton;
public override void Init()
{
base.Init();
LoadFuncAsyncs.Add(async (p, ct) =>
{
ct.ThrowIfCancellationRequested();
await UniTask.Delay(500);
Debug.Log("Done1");
});
LoadFuncAsyncs.Add(async (p, ct) =>
{
ct.ThrowIfCancellationRequested();
await UniTask.Delay(1000);
Debug.Log("Done2");
});
openSubPageButton?.onClick.AddListener(() =>
{
UIManager.Instance.OpenPage("TestSubPage");
});
}
}
์ต์๋จ์ ์คํฌ๋ฆฝํธ๋ฅผ ํฌํจํ Prefab์ ์ ์ํฉ๋๋ค.

UIManager.Instance.OpenPage๋ฅผ ํตํด Page๋ฅผ ๋ก๋ํฉ๋๋ค. ๋งค๊ฐ๋ณ์๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
- path๋ ResourceLoader์์์ Load path์ ๋๋ค. ResourceLoader์์ ์ง์ ํ ๋ฐฉ์์ผ๋ก ๋ฆฌ์์ค๋ฅผ ๋ก๋ํฉ๋๋ค.
- ํ์์ IProgress
progress๋ฅผ ํตํด ์งํ๋๋ฅผ ์ ์ ์์ต๋๋ค. - CancellationToken cancellationToken๋ ์ค๊ฐ์ ์์ฑ Task๋ฅผ ์ทจ์ํ๊ธฐ ์ํ ํ ํฐ์ ๋๋ค.
- int delay๋ ์ฌ๋๊ฒ ๋์ด์ก์ ๋ ๋๋ ์ด ์ด๋ฒคํธ๋ฅผ ์คํํ ์๊ฐ์ ๋๋ค. ๋๋ ์ด ์ด๋ฒคํธ๋ UIInstantiateRequest๋ฅผ ํตํด ๋ฐ์์ํฌ ์ ์์ต๋๋ค. ์๋์์ ์ธ๊ธํ๊ฒ ์ต๋๋ค.
public UIInstantiateRequest OpenPage(string path, IProgress<float> progress = null, CancellationToken cancellationToken = default, int delay = 1000)
์ฌ์ฉ ์์
UIManager.Instance.OpenPage("TestSubPage");
UIInstantiateRequest
UIManager๋ฅผ ํตํด UI๋ฅผ ์์ฑ์์ UIInstantiateRequest๋ฅผ ๋ฐํํฉ๋๋ค. UIInstantiateRequest์์ ํฌํจ๋ ๋ด์ฉ์ ์๋์ ๊ฐ์ต๋๋ค.
- onLoadingDelay: ์ง์ ํ ์๊ฐ๋ณด๋ค ๋๋ ์ด ๋์์ ๋ ๋ฐ์ํ ์ด๋ฒคํธ๋ฅผ ๋ฑ๋ก
- onLoadingDelayDone: ๋ง์ฝ ๋๋ ์ด ๋์์ ๋, ๋๋ ์ด๊ฐ ๋๋ ๋ ๋ฐ์ํ ์ด๋ฒคํธ๋ฅผ ๋ฑ๋ก
- Complete: ๋ก๋ ์๋ฃ์์ ๋ฐ์ํ ์ด๋ฒคํธ๋ฅผ ๋ฑ๋ก
async UniTask StartAsync(CancellationToken ct)
{
ct.ThrowIfCancellationRequested();
openUICTS = new CancellationTokenSource();
UIInstantiateRequest request = UIManager.Instance.OpenPopup("TestLoopPopup", cancellationToken: openUICTS.Token);
// ๋๋ ์ด ๋์์ผ๋ ๋ก๋ฉ UI๋ฅผ ์์ฑํจ.
request.onLoadingDelay.AddListener(() =>
{
loadingCTS = new CancellationTokenSource();
UniTask.Void(async () =>
{
var obj = await Resources.LoadAsync<GameObject>("LoadingUI");
loadingCTS.Token.ThrowIfCancellationRequested();
loadingObject = Instantiate(obj as GameObject);
loadingObject.GetComponent<Transform>().SetParent(panelTransform, false);
});
});
// ๋๋ ์ด๊ฐ ๋๋ฌ์ผ๋ ์์ฑ๋ ๋ก๋ฉ UI๋ฅผ ์ ๊ฑฐํจ.
request.onLoadingDelayDone.AddListener(() =>
{
loadingCTS.Cancel();
loadingCTS = null;
Destroy(loadingObject);
loadingObject = null;
});
// ์์ฑ์ด ์๋ฃ ๋์์ ๋ ์์น๋ฅผ ์ก์.
request.Complete += (obj) =>
{
obj.GetComponent<Transform>().localPosition = transform.localPosition + new Vector3(10, 0);
};
await request;
openUICTS?.Dispose();
openUICTS = null;
}
์ค์น
์ด ํ๋ก์ ํธ๋ UniTask๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๋ค. ์ค์น๋ฅผ ์งํํ๊ธฐ ์ , ์ ๋ํฐ ํ๋ก์ ํธ์ UniTask๋ฅผ ์ค์น ํ ์งํํด์ฃผ์ธ์.
git URL๋ก ์ค์น


Package Manager์์ https://github.com/JongSeonPark/Unity_UIManager.git?path=Assets/UIManager๋ฅผ ๊ธฐ์
ํ์ฌ ์ถ๊ฐํ ์ ์์ต๋๋ค.
openUPM์ผ๋ก ์ค์น
openUPM์ ์์ฑ๋์ด ์์ต๋๋ค. openupm-cli๋ฅผ ์ด์ฉํด ์ค์นํ ์ ์์ต๋๋ค.
openupm add com.chickengames.uimanager
Packages/manifest.json์ ์ถ๊ฐํ์ฌ ์ค์น
Packages/manifest.json์์ ์๋ ๋ด์ฉ์ ์ถ๊ฐํ์ฌ ์ค์นํ ์ ์์ต๋๋ค.
"com.chickengames.uimanager": "https://github.com/JongSeonPark/Unity_UIManager.git?path=Assets/UIManager"
์ฝ๋๋ฅผ ํด๋ก ํ ์ฌ์ฉ
์ฝ๋ ์์ ๋ฐ ์ง์ ์ ์ด๋ฅผ ์ํ๋ค๋ฉด Git์ ํด๋ก ํ์ฌ UIManagerํด๋ ๋ถ๋ถ์ ์ฌ์ฉํด๋ ๋ฌด๋ฐฉํฉ๋๋ค.
๐ป License
์ด ํ๋ก์ ํธ๋ Unity์ธ์ ์ธ๋ถ์์ ์์ฑ๋ ์ฝ๋๋ฅผ ํฌํจํ๊ณ ์์ง ์์ผ๋ฉฐ, ์ ๊ฐ ์์ฑ๋ ์ฝ๋์ ๋ํด์๋ Beer License๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๋ค. ํ๋ณตํ์ธ์. :)
No comments yet. Be the first!