UI매니저 기본 기능 구현
This commit is contained in:
@@ -21,9 +21,7 @@ public class PlayerController : MonoBehaviour
|
||||
// Managers.Resource.Instantiate("UI/UI_Button");
|
||||
|
||||
// TEMP
|
||||
UI_Button ui = Managers.UI.ShowPopupUI<UI_Button>();
|
||||
|
||||
Managers.UI.ClosePopupUI(ui);
|
||||
Managers.UI.ShowPopupUI<UI_Button>();
|
||||
}
|
||||
|
||||
public enum PlayerState
|
||||
|
||||
@@ -3,10 +3,59 @@ using UnityEngine;
|
||||
|
||||
public class UIManager
|
||||
{
|
||||
int _order = 0;
|
||||
int _order = 10;
|
||||
|
||||
Stack<UI_Popup> _popupStack = new Stack<UI_Popup>();
|
||||
UI_Scene _sceneUI = null;
|
||||
|
||||
public GameObject Root
|
||||
{
|
||||
get
|
||||
{
|
||||
GameObject root = GameObject.Find("@UI_Root");
|
||||
|
||||
if (root == null)
|
||||
{
|
||||
root = new GameObject("@UI_Root");
|
||||
}
|
||||
return root;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void SetCanvas(GameObject go, bool sort = true)
|
||||
{
|
||||
Canvas canvas = Util.GetOrAddComponent<Canvas>(go);
|
||||
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
|
||||
canvas.overrideSorting = true;
|
||||
|
||||
if (sort)
|
||||
{
|
||||
canvas.sortingOrder = _order;
|
||||
_order++;
|
||||
}
|
||||
else
|
||||
{
|
||||
canvas.sortingOrder = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public T ShowSceneUI<T>(string name = null) where T : UI_Scene
|
||||
{
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
name = typeof(T).Name;
|
||||
}
|
||||
|
||||
GameObject go = Managers.Resource.Instantiate($"UI/Scene/{name}");
|
||||
T sceneUI = Util.GetOrAddComponent<T>(go);
|
||||
_sceneUI = sceneUI;
|
||||
|
||||
go.transform.SetParent(Root.transform);
|
||||
|
||||
return sceneUI;
|
||||
}
|
||||
|
||||
public T ShowPopupUI<T>(string name = null) where T : UI_Popup
|
||||
{
|
||||
if (string.IsNullOrEmpty(name))
|
||||
@@ -18,6 +67,8 @@ public class UIManager
|
||||
T popup = Util.GetOrAddComponent<T>(go);
|
||||
_popupStack.Push(popup);
|
||||
|
||||
go.transform.SetParent(Root.transform);
|
||||
|
||||
return popup;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,13 @@ public class UI_Button : UI_Popup
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
|
||||
// Reflection
|
||||
Bind<Button>(typeof(Buttons));
|
||||
// Text 대신 TextMeshProUGUI로 변경
|
||||
|
||||
@@ -2,13 +2,13 @@ using UnityEngine;
|
||||
|
||||
public class UI_Popup : UI_Base
|
||||
{
|
||||
void Start()
|
||||
public virtual void Init()
|
||||
{
|
||||
|
||||
Managers.UI.SetCanvas(gameObject, true);
|
||||
}
|
||||
|
||||
void Update()
|
||||
public virtual void CloasePopupUI()
|
||||
{
|
||||
|
||||
Managers.UI.ClosePopupUI(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,8 @@ using UnityEngine;
|
||||
|
||||
public class UI_Scene : UI_Base
|
||||
{
|
||||
void Start()
|
||||
public virtual void Init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
|
||||
Managers.UI.SetCanvas(gameObject, false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user