1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
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<UIManager>
{
private Dictionary<PanelType, string> m_Panels = new Dictionary<PanelType, string>();
private Dictionary<PanelType, PanelBase> m_OpenedPanels = new Dictionary<PanelType, PanelBase>();
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<PanelBase>(m_Panels[type]);
if (prefab == null)
{
Debug.LogError("UI Prefab in not available, path=" + m_Panels[type]);
return null;
}
PanelBase panel = UnityEngine.Object.Instantiate<PanelBase>(prefab);
panel.name = prefab.name;
panel.transform.SetParent(m_Canvas.transform);
panel.Set(param);
panel.InitRectTransform();
panel.gameObject.SetActive(true);
return panel;
}
public PanelBase GetPanel(PanelType type)
{
if(m_OpenedPanels.ContainsKey(type))
{
return m_OpenedPanels[type];
}
return null;
}
public bool IsPanelOpen(PanelType type)
{
return m_OpenedPanels.ContainsKey(type);
}
}
|