Skip to content

Commit f2abf8c

Browse files
committed
Adding CanvasGroup to PopupPanel
1 parent 5a1f826 commit f2abf8c

File tree

2 files changed

+38
-16
lines changed

2 files changed

+38
-16
lines changed

Assets/BossRoom/Prefabs/UI/SettingsPanelCanvas.prefab

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,7 @@ GameObject:
11171117
- component: {fileID: 6918681726633036010}
11181118
- component: {fileID: 2602198259095850982}
11191119
- component: {fileID: 7399699007816123072}
1120+
- component: {fileID: 1849608714128437920}
11201121
m_Layer: 5
11211122
m_Name: PopupPanel
11221123
m_TagString: Untagged
@@ -1198,6 +1199,19 @@ MonoBehaviour:
11981199
m_EditorClassIdentifier:
11991200
m_TitleText: {fileID: 4728902606848342875}
12001201
m_MainText: {fileID: 3801577438371952926}
1202+
m_CanvasGroup: {fileID: 1849608714128437920}
1203+
--- !u!225 &1849608714128437920
1204+
CanvasGroup:
1205+
m_ObjectHideFlags: 0
1206+
m_CorrespondingSourceObject: {fileID: 0}
1207+
m_PrefabInstance: {fileID: 0}
1208+
m_PrefabAsset: {fileID: 0}
1209+
m_GameObject: {fileID: 5680680656091823962}
1210+
m_Enabled: 1
1211+
m_Alpha: 1
1212+
m_Interactable: 1
1213+
m_BlocksRaycasts: 1
1214+
m_IgnoreParentGroups: 0
12011215
--- !u!1 &6154749339973089473
12021216
GameObject:
12031217
m_ObjectHideFlags: 0

Assets/BossRoom/Scripts/Client/UI/PopupPanel.cs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public PopupPanelData(string titleText, string mainText)
2626
TextMeshProUGUI m_TitleText;
2727
[SerializeField]
2828
TextMeshProUGUI m_MainText;
29+
[SerializeField]
30+
CanvasGroup m_CanvasGroup;
2931

3032
Stack<PopupPanelData> m_PopupStack = new Stack<PopupPanelData>();
3133

@@ -35,7 +37,7 @@ void Awake()
3537
{
3638
if (s_Instance != null) throw new Exception("Invalid state, instance is not null");
3739
s_Instance = this;
38-
ResetState();
40+
Hide();
3941
}
4042

4143
void OnDestroy()
@@ -45,21 +47,15 @@ void OnDestroy()
4547

4648
public void OnConfirmClick()
4749
{
48-
ResetState();
50+
m_PopupStack.Pop();
4951
if (m_PopupStack.Count > 0)
5052
{
51-
SetupPopupPanel(m_PopupStack.Pop());
53+
SetupPopupPanel(m_PopupStack.Peek());
54+
}
55+
else
56+
{
57+
Hide();
5258
}
53-
}
54-
55-
/// <summary>
56-
/// Helper method to help us reset all state for the popup.
57-
/// </summary>
58-
void ResetState()
59-
{
60-
m_TitleText.text = string.Empty;
61-
m_MainText.text = string.Empty;
62-
gameObject.SetActive(false);
6359
}
6460

6561
/// <summary>
@@ -87,12 +83,24 @@ void StackPopupPanel(PopupPanelData data)
8783

8884
void SetupPopupPanel(PopupPanelData data)
8985
{
90-
ResetState();
91-
9286
m_TitleText.text = data.TitleText;
9387
m_MainText.text = data.MainText;
9488

95-
gameObject.SetActive(true);
89+
Show();
90+
}
91+
92+
93+
94+
void Show()
95+
{
96+
m_CanvasGroup.alpha = 1f;
97+
m_CanvasGroup.blocksRaycasts = true;
98+
}
99+
100+
void Hide()
101+
{
102+
m_CanvasGroup.alpha = 0f;
103+
m_CanvasGroup.blocksRaycasts = false;
96104
}
97105
}
98106
}

0 commit comments

Comments
 (0)