1. 버튼 설정은 했음 - 근데 이걸 이제 플레이어라든가 다른데 연결 시키는거 인풋매니저랑 연결시킨다든가 하는걸 해야 할 것 같음 - 기존에는 공격 버튼은 공격버튼으로 만 사용되어서 인풋매니저에서 관리해서 독점적인 관리가 가능했는데 UIButton으로 뺌으로 인해서 이러한 독점 관리가 아니게 되었으므로 이에 대한 처리가 필요로 하다.
95 lines
2.6 KiB
C#
95 lines
2.6 KiB
C#
using System.Collections.Generic;
|
|
using JetBrains.Annotations;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
public class UIManager : IManager
|
|
{
|
|
private Canvas _canvas;
|
|
private List<string> _uiList = new ();
|
|
public List<string> UIList
|
|
{
|
|
get { return _uiList; }
|
|
set
|
|
{
|
|
_uiList = value ?? new List<string>();
|
|
foreach (var ui in _uiList)
|
|
{
|
|
string path = Define.MapPath(ui);
|
|
CreateObject(path, ui);
|
|
}
|
|
}
|
|
}
|
|
|
|
private readonly Dictionary<string, GameObject> _objects = new ();
|
|
private readonly Dictionary<string, GameObject> _instances = new();
|
|
private readonly Dictionary<string, bool> _switchObjects = new ();
|
|
|
|
public void Init()
|
|
{
|
|
_canvas = GameObject.Find("@Canvas").GetComponent<Canvas>();
|
|
}
|
|
|
|
private void CreateObject(string path, string prefabName)
|
|
{
|
|
GameObject createObj = Manager.Resource.Load<GameObject>(path);
|
|
if (createObj != null)
|
|
{
|
|
_objects.Add(prefabName, createObj);
|
|
_switchObjects.Add(prefabName, false);
|
|
}
|
|
}
|
|
|
|
public T SwitchOnObject<T>(string name, bool isOn) where T : MonoBehaviour
|
|
{
|
|
if (_switchObjects.ContainsKey(name) && (_switchObjects[name] != isOn))
|
|
_switchObjects[name] = isOn;
|
|
else return null;
|
|
|
|
GameObject instance;
|
|
if (!_instances.ContainsKey(name))
|
|
{
|
|
instance = Manager.Resource.Instantiate(_objects[name], _canvas.transform);
|
|
// instance.name = name;
|
|
_instances.Add(name, instance);
|
|
}
|
|
else instance = _instances[name];
|
|
|
|
if (_switchObjects.ContainsKey(name) && _switchObjects[name])
|
|
{
|
|
instance.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
instance.SetActive(false);
|
|
}
|
|
|
|
// T component = instance.GetComponent<T>();
|
|
// if (action != null && component is UIButton button) button.Bind(action);
|
|
|
|
return instance.GetComponent<T>();
|
|
}
|
|
|
|
#region UI Object 특화 메서드
|
|
|
|
#region ExpBar 메서드
|
|
public void ExclusiveExpBar()
|
|
{
|
|
PlayerController player = GameObject.FindObjectOfType<PlayerController>();
|
|
if (player != null)
|
|
{
|
|
player.OnExpChanged -= UpdateExpBar;
|
|
player.OnExpChanged += UpdateExpBar;
|
|
}
|
|
}
|
|
|
|
private void UpdateExpBar(int level, float currentExp, float maxExp)
|
|
{
|
|
ExpBar expBar = _instances["ExpBar"].GetComponent<ExpBar>();
|
|
expBar.UpdateValue(level, currentExp, maxExp);
|
|
}
|
|
#endregion
|
|
|
|
#endregion
|
|
}
|