|
1 | 1 | using System;
|
| 2 | +using System.Collections; |
2 | 3 | using System.Collections.Generic;
|
3 | 4 | using UnityEngine;
|
4 | 5 |
|
@@ -55,30 +56,33 @@ void DisplayPopupPanel(string titleText, string mainText)
|
55 | 56 |
|
56 | 57 | PopupPanel GetNextAvailablePopupPanel()
|
57 | 58 | {
|
58 |
| - PopupPanel popupPanel = null; |
59 |
| - foreach (var popup in m_PopupPanels) |
| 59 | + int nextAvailablePopupIndex = 0; |
| 60 | + // Find the index of the first PopupPanel that is not displaying and has no popups after it that are currently displaying |
| 61 | + for (int i = 0; i < m_PopupPanels.Count; i++) |
60 | 62 | {
|
61 |
| - if (popupPanel == null && !popup.IsDisplaying) |
| 63 | + if (m_PopupPanels[i].IsDisplaying) |
62 | 64 | {
|
63 |
| - popupPanel = popup; |
64 |
| - } |
65 |
| - else if (popup.IsDisplaying) |
66 |
| - { |
67 |
| - popupPanel = null; |
| 65 | + nextAvailablePopupIndex = i + 1; |
68 | 66 | }
|
69 | 67 | }
|
70 | 68 |
|
71 |
| - if (popupPanel == null) |
| 69 | + if (nextAvailablePopupIndex < m_PopupPanels.Count) |
| 70 | + { |
| 71 | + return m_PopupPanels[nextAvailablePopupIndex]; |
| 72 | + } |
| 73 | + |
| 74 | + // None of the current PopupPanels are available, so instantiate a new one |
| 75 | + var popupGameObject = Instantiate(m_PopupPanelPrefab, gameObject.transform); |
| 76 | + popupGameObject.transform.position += new Vector3(1, -1) * (k_Offset * m_PopupPanels.Count % k_MaxOffset); |
| 77 | + var popupPanel = popupGameObject.GetComponent<PopupPanel>(); |
| 78 | + if (popupPanel != null) |
72 | 79 | {
|
73 |
| - var popupGameObject = Instantiate(m_PopupPanelPrefab, gameObject.transform); |
74 |
| - popupGameObject.transform.position += new Vector3(1, -1) * (k_Offset * m_PopupPanels.Count % k_MaxOffset); |
75 |
| - popupPanel = popupGameObject.GetComponent<PopupPanel>(); |
76 |
| - if (popupPanel == null) |
77 |
| - { |
78 |
| - Debug.LogError("PopupPanel prefab does not have a PopupPanel component!"); |
79 |
| - } |
80 | 80 | m_PopupPanels.Add(popupPanel);
|
81 | 81 | }
|
| 82 | + else |
| 83 | + { |
| 84 | + Debug.LogError("PopupPanel prefab does not have a PopupPanel component!"); |
| 85 | + } |
82 | 86 |
|
83 | 87 | return popupPanel;
|
84 | 88 | }
|
|
0 commit comments