GameScreenView.Panels.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using TMPro;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. public partial class GameScreenView
  7. {
  8. const string FailReasonTimeUp = "time_up";
  9. const string FailReasonNoMoves = "no_moves";
  10. TMP_Text pauseModeInfo;
  11. TMP_Text pauseMovesCount;
  12. TMP_Text pauseFruitsLeftCount;
  13. TMP_Text pauseServedCount;
  14. GameObject winPanel;
  15. GameObject losePanel;
  16. TMP_Text winModeInfo;
  17. TMP_Text winSummary;
  18. TMP_Text winLevelBonusValue;
  19. TMP_Text winMovesBonusValue;
  20. TMP_Text winServedValue;
  21. TMP_Text winTotalReward;
  22. GameObject winTicketBadge;
  23. TMP_Text winTicketText;
  24. TMP_Text winNextLabel;
  25. TMP_Text loseTimeUpModeInfo;
  26. TMP_Text loseNoMovesModeInfo;
  27. TMP_Text loseMessage;
  28. GameObject loseTimeUpGroup;
  29. GameObject loseNoMovesGroup;
  30. TMP_Text loseServedLabel;
  31. TMP_Text loseServedValue;
  32. TMP_Text loseFruitLeftLabel;
  33. TMP_Text loseFruitLeftValue;
  34. TMP_Text loseMovesLeftLabel;
  35. TMP_Text loseMovesLeftValue;
  36. TMP_Text loseNextLabel;
  37. bool resultIsWin;
  38. string resultFailTitle = "";
  39. void BuildBanner()
  40. {
  41. var bannerGo = new GameObject("Banner", typeof(RectTransform), typeof(CanvasGroup));
  42. bannerGo.transform.SetParent(transform, false);
  43. var rect = (RectTransform)bannerGo.transform;
  44. rect.anchorMin = new Vector2(0.5f, 0.5f);
  45. rect.anchorMax = new Vector2(0.5f, 0.5f);
  46. rect.pivot = new Vector2(0.5f, 0.5f);
  47. rect.anchoredPosition = new Vector2(0f, 95f);
  48. rect.sizeDelta = new Vector2(640f, 110f);
  49. bannerGroup = bannerGo.GetComponent<CanvasGroup>();
  50. bannerGroup.alpha = 0f;
  51. bannerGroup.blocksRaycasts = false;
  52. bannerGroup.interactable = false;
  53. bannerText = CreateText(bannerGo.transform, "BannerText", textTemplate, "NICE!", 44f, new Color(1f, 0.85f, 0.32f, 1f), TextAlignmentOptions.Center, Vector2.zero, new Vector2(640f, 110f));
  54. if (bannerText != null)
  55. {
  56. var outline = bannerText.gameObject.AddComponent<Outline>();
  57. outline.effectColor = new Color(0.28f, 0.07f, 0.01f, 1f);
  58. outline.effectDistance = new Vector2(3f, -3f);
  59. }
  60. }
  61. void BuildPanels()
  62. {
  63. BuildPausePanel();
  64. BuildWinPanel();
  65. BuildLosePanel();
  66. BuildPopView();
  67. }
  68. GameObject InstantiatePanel(string resourcePath, string panelName)
  69. {
  70. GameObject prefab = Resources.Load<GameObject>(resourcePath);
  71. if (prefab == null)
  72. {
  73. Debug.LogError("[GameScreen] Missing panel prefab: " + resourcePath);
  74. return null;
  75. }
  76. GameObject panel = Instantiate(prefab, transform, false);
  77. panel.name = panelName;
  78. panel.SetActive(false);
  79. return panel;
  80. }
  81. static Transform PanelChild(GameObject panel, string path)
  82. {
  83. if (panel == null)
  84. return null;
  85. Transform child = panel.transform.Find(path);
  86. if (child == null)
  87. Debug.LogWarning("[GameScreen] Missing panel node: " + path);
  88. return child;
  89. }
  90. static TMP_Text PanelText(GameObject panel, string path)
  91. {
  92. Transform child = PanelChild(panel, path);
  93. TMP_Text text = child != null ? child.GetComponent<TMP_Text>() : null;
  94. if (child != null && text == null)
  95. Debug.LogWarning("[GameScreen] Panel node is not TMP text: " + path);
  96. return text;
  97. }
  98. static Button PanelButton(GameObject panel, string path)
  99. {
  100. Transform child = PanelChild(panel, path);
  101. return child != null ? UIViewUtility.EnsureButton(child) : null;
  102. }
  103. void BuildPausePanel()
  104. {
  105. pausePanel = InstantiatePanel("Prefab/08_pause", "PausePanel");
  106. if (pausePanel == null)
  107. return;
  108. pauseModeInfo = PanelText(pausePanel, "IMG_BG/IMG_PauseModeBadge/TMP_PauseModeInfo");
  109. pauseMovesCount = PanelText(pausePanel, "IMG_BG/IMG_PauseStatsBG/TMP_MovesCount");
  110. pauseFruitsLeftCount = PanelText(pausePanel, "IMG_BG/IMG_PauseStatsBG/TMP_FruitsLeftCount");
  111. pauseServedCount = PanelText(pausePanel, "IMG_BG/IMG_PauseStatsBG/TMP_ServedCount");
  112. UIViewUtility.Bind(PanelButton(pausePanel, "IMG_BG/BTN_ClosePause"), ResumeGame);
  113. UIViewUtility.Bind(PanelButton(pausePanel, "IMG_BG/BTN_Resume"), ResumeGame);
  114. UIViewUtility.Bind(PanelButton(pausePanel, "IMG_BG/BTN_Quit"), HandleBack);
  115. UILocaleScreens.ApplyPausePanel(pausePanel != null ? pausePanel.transform : null);
  116. }
  117. void BuildWinPanel()
  118. {
  119. winPanel = InstantiatePanel("Prefab/09_win", "WinPanel");
  120. if (winPanel == null)
  121. return;
  122. winModeInfo = PanelText(winPanel, "IMG_BG/IMG_PauseModeBadge/TMP_PauseModeInfo");
  123. winSummary = PanelText(winPanel, "IMG_BG/IMG_StandEmptySummaryBG/TMP_StandEmptySummary");
  124. winLevelBonusValue = PanelText(winPanel, "IMG_BG/IMG_ClearedScoreBG/GRP_SetsServed/TMP_Value");
  125. winMovesBonusValue = PanelText(winPanel, "IMG_BG/IMG_ClearedScoreBG/GRP_FruitLeft/TMP_Value");
  126. winServedValue = PanelText(winPanel, "IMG_BG/IMG_ClearedScoreBG/GRP_MovesLeft/TMP_Value");
  127. winTotalReward = PanelText(winPanel, "IMG_BG/IMG_TotalRewardBG/OBJ_Content/TMP_Reward_Coin");
  128. winTicketBadge = PanelChild(winPanel, "IMG_BG/IMG_DrawTicketBadgeBG")?.gameObject;
  129. winTicketText = PanelText(winPanel, "IMG_BG/IMG_DrawTicketBadgeBG/OBJ_Content/TMP_Reward_Ticket");
  130. winNextLabel = PanelText(winPanel, "IMG_BG/BTN_NextLevel/TMP_Label");
  131. UIViewUtility.Bind(PanelButton(winPanel, "IMG_BG/BTN_ClosePause"), HandleBack);
  132. UIViewUtility.Bind(PanelButton(winPanel, "IMG_BG/BTN_Back"), HandleBack);
  133. UIViewUtility.Bind(PanelButton(winPanel, "IMG_BG/BTN_NextLevel"), HandleResultAction);
  134. UILocaleScreens.ApplyWinPanel(winPanel != null ? winPanel.transform : null);
  135. }
  136. void BuildLosePanel()
  137. {
  138. losePanel = InstantiatePanel("Prefab/10_lose", "LosePanel");
  139. if (losePanel == null)
  140. return;
  141. loseTimeUpGroup = PanelChild(losePanel, "IMG_BG/GRP_TimeUp")?.gameObject;
  142. loseNoMovesGroup = PanelChild(losePanel, "IMG_BG/GRP_NoMoves")?.gameObject;
  143. loseTimeUpModeInfo = PanelText(losePanel, "IMG_BG/GRP_TimeUp/IMG_PauseModeBadge/TMP_PauseModeInfo");
  144. loseNoMovesModeInfo = PanelText(losePanel, "IMG_BG/GRP_NoMoves/IMG_PauseModeBadge/TMP_PauseModeInfo");
  145. loseMessage = PanelText(losePanel, "IMG_BG/TMP_Message");
  146. loseServedLabel = PanelText(losePanel, "IMG_BG/IMG_ClearedScoreBG/GRP_SetsServed/TMP_Label");
  147. loseServedValue = PanelText(losePanel, "IMG_BG/IMG_ClearedScoreBG/GRP_SetsServed/TMP_Value");
  148. loseFruitLeftLabel = PanelText(losePanel, "IMG_BG/IMG_ClearedScoreBG/GRP_FruitLeft/TMP_Label");
  149. loseFruitLeftValue = PanelText(losePanel, "IMG_BG/IMG_ClearedScoreBG/GRP_FruitLeft/TMP_Value");
  150. loseMovesLeftLabel = PanelText(losePanel, "IMG_BG/IMG_ClearedScoreBG/GRP_MovesLeft/TMP_Label");
  151. loseMovesLeftValue = PanelText(losePanel, "IMG_BG/IMG_ClearedScoreBG/GRP_MovesLeft/TMP_Value");
  152. loseNextLabel = PanelText(losePanel, "IMG_BG/BTN_NextLevel/TMP_Label");
  153. UIViewUtility.Bind(PanelButton(losePanel, "IMG_BG/BTN_ClosePause"), HandleBack);
  154. UIViewUtility.Bind(PanelButton(losePanel, "IMG_BG/BTN_Back"), HandleBack);
  155. UIViewUtility.Bind(PanelButton(losePanel, "IMG_BG/BTN_NextLevel"), HandleResultAction);
  156. }
  157. void HandleResultAction()
  158. {
  159. int next = resultIsWin
  160. ? (levelNumber >= GameDefinitions.MaxLevel ? GameDefinitions.MaxLevel : levelNumber + 1)
  161. : levelNumber;
  162. HidePanels();
  163. NextLevelRequested?.Invoke(next);
  164. }
  165. bool IsResultVisible()
  166. {
  167. return (winPanel != null && winPanel.activeSelf) || (losePanel != null && losePanel.activeSelf);
  168. }
  169. void PauseGame()
  170. {
  171. if (paused || ended)
  172. return;
  173. if (IsResultVisible())
  174. return;
  175. paused = true;
  176. toolMode = "";
  177. ClearSelection();
  178. RefreshPausePanel();
  179. ShowOverlay(pausePanel);
  180. }
  181. void RefreshPausePanel()
  182. {
  183. UILocaleScreens.ApplyPausePanel(pausePanel != null ? pausePanel.transform : null);
  184. if (pauseModeInfo != null)
  185. pauseModeInfo.text = GameLocale.ModeLevelLine(modeKey, levelNumber);
  186. if (pauseMovesCount != null)
  187. pauseMovesCount.text = state.MovesLeft.ToString();
  188. if (pauseFruitsLeftCount != null)
  189. pauseFruitsLeftCount.text = state.RemainingFruits.ToString();
  190. if (pauseServedCount != null)
  191. pauseServedCount.text = state.Served.ToString();
  192. }
  193. void ResumeGame()
  194. {
  195. paused = false;
  196. if (pausePanel != null)
  197. pausePanel.SetActive(false);
  198. }
  199. void HidePanels()
  200. {
  201. paused = false;
  202. if (pausePanel != null)
  203. pausePanel.SetActive(false);
  204. if (winPanel != null)
  205. winPanel.SetActive(false);
  206. if (losePanel != null)
  207. losePanel.SetActive(false);
  208. if (popView != null)
  209. popView.Hide();
  210. }
  211. void ShowOverlay(GameObject overlay)
  212. {
  213. if (overlay == null)
  214. return;
  215. overlay.SetActive(true);
  216. overlay.transform.SetAsLastSibling();
  217. var group = overlay.GetComponent<CanvasGroup>();
  218. if (group == null)
  219. return;
  220. if (!Application.isPlaying)
  221. {
  222. group.alpha = 1f;
  223. return;
  224. }
  225. StartCoroutine(FadeOverlay(group));
  226. }
  227. IEnumerator FadeOverlay(CanvasGroup group)
  228. {
  229. group.alpha = 0f;
  230. float elapsed = 0f;
  231. while (elapsed < 0.18f)
  232. {
  233. elapsed += Time.unscaledDeltaTime;
  234. group.alpha = Mathf.Clamp01(elapsed / 0.18f);
  235. yield return null;
  236. }
  237. group.alpha = 1f;
  238. }
  239. void ShowBanner(string message, float hold, float size)
  240. {
  241. if (bannerText == null || bannerGroup == null)
  242. return;
  243. bannerText.text = message;
  244. bannerText.fontSize = size;
  245. if (!Application.isPlaying)
  246. {
  247. bannerGroup.alpha = 0f;
  248. return;
  249. }
  250. if (bannerRoutine != null)
  251. StopCoroutine(bannerRoutine);
  252. bannerRoutine = StartCoroutine(BannerRoutine(hold));
  253. }
  254. IEnumerator BannerRoutine(float hold)
  255. {
  256. bannerGroup.alpha = 0f;
  257. var rect = bannerText.rectTransform;
  258. rect.localScale = Vector3.one * 0.82f;
  259. float elapsed = 0f;
  260. while (elapsed < 0.14f)
  261. {
  262. elapsed += Time.unscaledDeltaTime;
  263. float t = Mathf.Clamp01(elapsed / 0.14f);
  264. bannerGroup.alpha = t;
  265. rect.localScale = Vector3.one * Mathf.Lerp(0.82f, 1.04f, t);
  266. yield return null;
  267. }
  268. rect.localScale = Vector3.one;
  269. yield return new WaitForSecondsRealtime(Mathf.Max(0.05f, hold));
  270. elapsed = 0f;
  271. while (elapsed < 0.22f)
  272. {
  273. elapsed += Time.unscaledDeltaTime;
  274. bannerGroup.alpha = 1f - Mathf.Clamp01(elapsed / 0.22f);
  275. yield return null;
  276. }
  277. bannerGroup.alpha = 0f;
  278. bannerRoutine = null;
  279. }
  280. void WinLevel()
  281. {
  282. if (ended)
  283. return;
  284. ended = true;
  285. busy = false;
  286. toolMode = "";
  287. ClearSelection();
  288. ApplyWinRewards();
  289. GameAudio.PlaySfx(GameSfx.Win);
  290. if (Application.isPlaying)
  291. StartCoroutine(WinSequence());
  292. else
  293. ShowResult(true, "", "");
  294. }
  295. IEnumerator WinSequence()
  296. {
  297. ShowBanner(L.Get("game.banner.stand_empty"), 1.1f, 54f);
  298. bool reduce = SaveService.Data.settings.reduceMotion;
  299. if (!reduce)
  300. yield return new WaitForSecondsRealtime(0.95f);
  301. ShowResult(true, "", "");
  302. }
  303. void FailLevel(string title, string subtitle)
  304. {
  305. if (ended)
  306. return;
  307. ended = true;
  308. busy = false;
  309. toolMode = "";
  310. ClearSelection();
  311. GameAudio.PlaySfx(GameSfx.Fail);
  312. if (title == FailReasonNoMoves && CanOfferAdRevive())
  313. OfferAdRevive(title, subtitle);
  314. else
  315. ShowResult(false, title, subtitle);
  316. }
  317. void ApplyWinRewards()
  318. {
  319. var save = SaveService.Data;
  320. int previous = save.cleared.Get(modeKey);
  321. bool firstClear = levelNumber > previous;
  322. lastRewardCoins = definition.BaseReward + state.MovesLeft * 8;
  323. lastServedCoins = state.Served * 2;
  324. lastTicket = 0;
  325. if (firstClear && levelNumber == 1)
  326. lastTicket = 1;
  327. else if (firstClear && UnityEngine.Random.value < 0.35f)
  328. lastTicket = 1;
  329. SaveService.AddCoins(lastRewardCoins + lastServedCoins, "ledger.game_clear|" + modeKey + "|" + levelNumber);
  330. save.cleared.Set(modeKey, Mathf.Max(previous, levelNumber));
  331. save.stats.clears += 1;
  332. save.stats.served += state.Served;
  333. save.stats.best = Mathf.Max(save.stats.best, state.Score);
  334. save.tickets += lastTicket;
  335. SaveService.SaveNow();
  336. }
  337. void ShowResult(bool win, string title, string subtitle)
  338. {
  339. if (AdMobEngagement.RecordRoundCompleted())
  340. AdMobService.NotifyNonRewardedAdsUnlocked();
  341. resultIsWin = win;
  342. resultFailTitle = title;
  343. if (pausePanel != null)
  344. pausePanel.SetActive(false);
  345. if (win)
  346. {
  347. if (lastRewardCoins + lastServedCoins > 0)
  348. GameAudio.PlaySfx(GameSfx.Coin);
  349. UpdateWinPanel();
  350. ShowOverlay(winPanel);
  351. if (losePanel != null)
  352. losePanel.SetActive(false);
  353. PlayConfetti();
  354. }
  355. else
  356. {
  357. UpdateLosePanel(title, subtitle);
  358. ShowOverlay(losePanel);
  359. if (winPanel != null)
  360. winPanel.SetActive(false);
  361. }
  362. }
  363. void UpdateWinPanel()
  364. {
  365. UILocaleScreens.ApplyWinPanel(winPanel != null ? winPanel.transform : null);
  366. if (winModeInfo != null)
  367. winModeInfo.text = GameLocale.ModeLevelLine(modeKey, levelNumber);
  368. if (winSummary != null)
  369. winSummary.text = L.F("result.win_summary", state.Served, state.MovesLeft);
  370. if (winLevelBonusValue != null)
  371. winLevelBonusValue.text = "+" + definition.BaseReward;
  372. if (winMovesBonusValue != null)
  373. winMovesBonusValue.text = "+" + (state.MovesLeft * 8);
  374. if (winServedValue != null)
  375. winServedValue.text = state.Served.ToString();
  376. if (winTotalReward != null)
  377. winTotalReward.text = "+" + (lastRewardCoins + lastServedCoins);
  378. if (winTicketBadge != null)
  379. winTicketBadge.SetActive(lastTicket > 0);
  380. if (winTicketText != null)
  381. winTicketText.text = L.F("result.draw_ticket", lastTicket);
  382. if (winNextLabel != null)
  383. winNextLabel.text = levelNumber >= GameDefinitions.MaxLevel
  384. ? L.F("result.replay_max", GameDefinitions.MaxLevel)
  385. : L.Get("result.next_level");
  386. }
  387. void UpdateLosePanel(string title, string subtitle)
  388. {
  389. UILocaleScreens.ApplyLosePanel(losePanel != null ? losePanel.transform : null);
  390. bool timeUp = title == FailReasonTimeUp;
  391. string modeInfo = GameLocale.ModeLevelLine(modeKey, levelNumber);
  392. if (loseTimeUpModeInfo != null)
  393. loseTimeUpModeInfo.text = modeInfo;
  394. if (loseNoMovesModeInfo != null)
  395. loseNoMovesModeInfo.text = modeInfo;
  396. if (loseTimeUpGroup != null)
  397. loseTimeUpGroup.SetActive(timeUp);
  398. if (loseNoMovesGroup != null)
  399. loseNoMovesGroup.SetActive(!timeUp);
  400. if (loseMessage != null)
  401. {
  402. loseMessage.text = timeUp
  403. ? L.Get("result.lose_time_msg")
  404. : L.Get("result.lose_moves_msg");
  405. }
  406. if (loseServedLabel != null)
  407. loseServedLabel.text = L.Get("result.sets_served");
  408. if (loseServedValue != null)
  409. loseServedValue.text = state.Served.ToString();
  410. if (loseFruitLeftLabel != null)
  411. loseFruitLeftLabel.text = L.Get("result.fruit_left");
  412. if (loseFruitLeftValue != null)
  413. loseFruitLeftValue.text = state.RemainingFruits.ToString();
  414. if (loseMovesLeftLabel != null)
  415. loseMovesLeftLabel.text = L.Get("result.moves_left");
  416. if (loseMovesLeftValue != null)
  417. loseMovesLeftValue.text = state.MovesLeft.ToString();
  418. if (loseNextLabel != null)
  419. loseNextLabel.text = L.Get("common.retry");
  420. }
  421. class ConfettiData
  422. {
  423. public RectTransform rect;
  424. public Vector2 velocity;
  425. public float spin;
  426. public Image image;
  427. }
  428. void PlayConfetti()
  429. {
  430. if (winPanel == null || SaveService.Data.settings.reduceMotion)
  431. return;
  432. ClearConfetti();
  433. Color[] colors =
  434. {
  435. new Color(1f, 0.78f, 0.2f, 1f),
  436. new Color(1f, 0.25f, 0.56f, 1f),
  437. new Color(0.36f, 0.9f, 0.52f, 1f),
  438. new Color(0.33f, 0.91f, 0.89f, 1f),
  439. new Color(1f, 0.95f, 0.72f, 1f)
  440. };
  441. var pieces = new List<ConfettiData>();
  442. for (int i = 0; i < 54; i++)
  443. {
  444. var go = new GameObject("Confetti", typeof(RectTransform), typeof(CanvasRenderer), typeof(Image));
  445. go.transform.SetParent(winPanel.transform, false);
  446. var rect = (RectTransform)go.transform;
  447. rect.anchorMin = new Vector2(0.5f, 0.5f);
  448. rect.anchorMax = new Vector2(0.5f, 0.5f);
  449. rect.pivot = new Vector2(0.5f, 0.5f);
  450. rect.anchoredPosition = new Vector2(UnityEngine.Random.Range(-350f, 350f), UnityEngine.Random.Range(420f, 760f));
  451. rect.sizeDelta = new Vector2(UnityEngine.Random.Range(7f, 13f), UnityEngine.Random.Range(12f, 22f));
  452. var image = go.GetComponent<Image>();
  453. image.color = colors[UnityEngine.Random.Range(0, colors.Length)];
  454. image.raycastTarget = false;
  455. pieces.Add(new ConfettiData
  456. {
  457. rect = rect,
  458. image = image,
  459. velocity = new Vector2(UnityEngine.Random.Range(-90f, 90f), UnityEngine.Random.Range(-220f, -520f)),
  460. spin = UnityEngine.Random.Range(-220f, 220f)
  461. });
  462. }
  463. StartCoroutine(ConfettiRoutine(pieces));
  464. }
  465. IEnumerator ConfettiRoutine(List<ConfettiData> pieces)
  466. {
  467. float elapsed = 0f;
  468. while (elapsed < 2.1f)
  469. {
  470. float dt = Time.unscaledDeltaTime;
  471. elapsed += dt;
  472. for (int i = 0; i < pieces.Count; i++)
  473. {
  474. var piece = pieces[i];
  475. if (piece.rect == null)
  476. continue;
  477. piece.velocity.y -= 780f * dt;
  478. piece.rect.anchoredPosition += piece.velocity * dt;
  479. piece.rect.Rotate(0f, 0f, piece.spin * dt);
  480. if (piece.image != null)
  481. {
  482. Color color = piece.image.color;
  483. color.a = Mathf.Clamp01(1f - (elapsed - 1.4f) / 0.7f);
  484. piece.image.color = color;
  485. }
  486. }
  487. yield return null;
  488. }
  489. for (int i = 0; i < pieces.Count; i++)
  490. {
  491. if (pieces[i].rect != null)
  492. Destroy(pieces[i].rect.gameObject);
  493. }
  494. }
  495. void ClearConfetti()
  496. {
  497. if (confetti.Count > 0)
  498. {
  499. for (int i = 0; i < confetti.Count; i++)
  500. {
  501. if (confetti[i] != null)
  502. DestroyObject(confetti[i]);
  503. }
  504. confetti.Clear();
  505. }
  506. if (winPanel == null)
  507. return;
  508. for (int i = winPanel.transform.childCount - 1; i >= 0; i--)
  509. {
  510. Transform child = winPanel.transform.GetChild(i);
  511. if (child.name == "Confetti")
  512. DestroyObject(child.gameObject);
  513. }
  514. }
  515. }