using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public enum PanelType { None, PanelLevelBar, PanelPropBar, PanelWeaponBar, PanelTopSuffBar, PanelBossHpBar, } public partial class UIManager : Singleton { private Dictionary m_Panels = new Dictionary(); private Dictionary m_OpenedPanels = new Dictionary(); private Canvas m_Canvas; public void SetRootCanvas(Canvas canvas) { m_Canvas = canvas; } void SetPanels() { AddPanel(PanelType.PanelLevelBar, "PanelLevelBar"); AddPanel(PanelType.PanelPropBar, "PanelPropBar"); AddPanel(PanelType.PanelWeaponBar, "PanelWeaponBar"); AddPanel(PanelType.PanelTopSuffBar, "PanelTopSuffBar"); AddPanel(PanelType.PanelBossHpBar, "PanelBossHpBar"); } void AddPanel(PanelType type, string path) { m_Panels.Add(type, "prefabs/ui/" + path); } public PanelBase OpenPanel(PanelType type, object param = null) { if(m_OpenedPanels.ContainsKey(type)) { return m_OpenedPanels[type]; } PanelBase prefab = ResourceManager.Instance.Load(m_Panels[type]); if (prefab == null) { Debug.LogError("UI Prefab in not available, path=" + m_Panels[type]); return null; } PanelBase panel = UnityEngine.Object.Instantiate(prefab); panel.name = prefab.name; panel.transform.SetParent(m_Canvas.transform); panel.Set(param); panel.InitRectTransform(); panel.gameObject.SetActive(true); return panel; } }