UIManager 생성 및 PopupUI 기능 구현
This commit is contained in:
@@ -16,9 +16,14 @@ public class PlayerController : MonoBehaviour
|
||||
// Managers.Input.KeytAction += OnKyeboard;
|
||||
Managers.Input.MouseAction -= OnMouseClicked;
|
||||
Managers.Input.MouseAction += OnMouseClicked;
|
||||
|
||||
|
||||
// UI 생성
|
||||
// Managers.Resource.Instantiate("UI/UI_Button");
|
||||
|
||||
// TEMP
|
||||
UI_Button ui = Managers.UI.ShowPopupUI<UI_Button>();
|
||||
|
||||
Managers.UI.ClosePopupUI(ui);
|
||||
}
|
||||
|
||||
public enum PlayerState
|
||||
|
||||
@@ -7,8 +7,10 @@ public class Managers : MonoBehaviour
|
||||
|
||||
InputManager _input = new InputManager();
|
||||
ResourceManager _resource = new ResourceManager();
|
||||
UIManager _ui = new UIManager();
|
||||
public static InputManager Input { get { return Instance._input; } }
|
||||
public static ResourceManager Resource { get { return Instance._resource; } }
|
||||
public static UIManager UI { get { return Instance._ui; } }
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
|
||||
62
Assets/Scripts/Managers/UIManager.cs
Normal file
62
Assets/Scripts/Managers/UIManager.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class UIManager
|
||||
{
|
||||
int _order = 0;
|
||||
|
||||
Stack<UI_Popup> _popupStack = new Stack<UI_Popup>();
|
||||
|
||||
public T ShowPopupUI<T>(string name = null) where T : UI_Popup
|
||||
{
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
name = typeof(T).Name;
|
||||
}
|
||||
|
||||
GameObject go = Managers.Resource.Instantiate($"UI/Popup/{name}");
|
||||
T popup = Util.GetOrAddComponent<T>(go);
|
||||
_popupStack.Push(popup);
|
||||
|
||||
return popup;
|
||||
}
|
||||
|
||||
public void ClosePopupUI(UI_Popup popup)
|
||||
{
|
||||
if (_popupStack.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_popupStack.Peek() != popup)
|
||||
{
|
||||
Debug.Log("Close Popup Failed!");
|
||||
return;
|
||||
}
|
||||
|
||||
ClosePopupUI();
|
||||
}
|
||||
|
||||
public void ClosePopupUI()
|
||||
{
|
||||
if (_popupStack.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
UI_Popup popup = _popupStack.Pop();
|
||||
Managers.Resource.Destroy(popup.gameObject);
|
||||
popup = null;
|
||||
|
||||
_order--;
|
||||
}
|
||||
|
||||
public void CloseAllPopupUI()
|
||||
{
|
||||
while (_popupStack.Count > 0)
|
||||
{
|
||||
ClosePopupUI();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
2
Assets/Scripts/Managers/UIManager.cs.meta
Normal file
2
Assets/Scripts/Managers/UIManager.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3df02b34806f40049bb192bcd0d5f3ae
|
||||
@@ -5,7 +5,7 @@ using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class UI_Button : UI_Base
|
||||
public class UI_Button : UI_Popup
|
||||
{
|
||||
enum Buttons
|
||||
{
|
||||
@@ -1,6 +1,6 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class UI_Popup : MonoBehaviour
|
||||
public class UI_Popup : UI_Base
|
||||
{
|
||||
void Start()
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class UI_Scene : MonoBehaviour
|
||||
public class UI_Scene : UI_Base
|
||||
{
|
||||
void Start()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user