GachaPanel.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. using System;
  2. using System.Collections.Generic;
  3. using Core.Audio;
  4. using Core.Language;
  5. using Core.Utility;
  6. using Excel2Json;
  7. using Fort23.Core;
  8. using Fort23.UTool;
  9. using GameLogic.Bag;
  10. using UnityEngine;
  11. using Random = UnityEngine.Random;
  12. namespace Fort23.Mono
  13. {
  14. [UIBinding(prefab = "GachaPanel")]
  15. public partial class GachaPanel : UIPanel
  16. {
  17. List<WidgetItem> widgetItems = new List<WidgetItem>();
  18. private List<ItemInfo> itemInfos;
  19. private int type;
  20. private OpenBoxConfig _openBoxConfig;
  21. List<GameObjectPool> _gameObjectPools = new List<GameObjectPool>();
  22. List<EnergyWidget> _energyWidgets = new List<EnergyWidget>();
  23. private void Init()
  24. {
  25. isAddStack = true;
  26. IsShowAppBar = false;
  27. }
  28. protected override void AddEvent()
  29. {
  30. }
  31. protected override void DelEvent()
  32. {
  33. }
  34. public override void AddButtonEvent()
  35. {
  36. tenButton.onClick.AddListener(() => { UIManager.Instance.HideUIUIPanel<GachaPanel>(); });
  37. oneButton.onClick.AddListener(async () =>
  38. {
  39. if (type == 1)
  40. {
  41. itemInfos = await BoxHelper.OneBox(_openBoxConfig.ID);
  42. }
  43. else if (type == 2)
  44. {
  45. itemInfos = await BoxHelper.TenBox(_openBoxConfig.ID);
  46. }
  47. if (itemInfos == null)
  48. return;
  49. for (var i = 0; i < _imageMoveContainers.Count; i++)
  50. {
  51. _imageMoveContainers[i].Dispose();
  52. }
  53. _imageMoveContainers.Clear();
  54. tenButton.gameObject.SetActive(false);
  55. oneButton.gameObject.SetActive(false);
  56. for (var i = 0; i < widgetItems.Count; i++)
  57. {
  58. widgetItems[i].SetActive(false);
  59. widgetItems[i].InitWidget(itemInfos[i]);
  60. }
  61. CusstomInit();
  62. });
  63. }
  64. public async override CTask<bool> AsyncInit(object[] uiData)
  65. {
  66. itemInfos = uiData[0] as List<ItemInfo>;
  67. type = (int)uiData[1];
  68. _openBoxConfig = ConfigComponent.Instance.Get<OpenBoxConfig>((int)uiData[2]);
  69. foreach (var widget in _energyWidgets)
  70. {
  71. UIManager.Instance.DormancyGComponent(widget);
  72. }
  73. _energyWidgets.Clear();
  74. EnergyWidget energyWidget = await UIManager.Instance.CreateGComponent<EnergyWidget>(null, Group_ResourceBar);
  75. energyWidget.CustomInit(GlobalParam.Item_Coin_ID);
  76. _energyWidgets.Add(energyWidget);
  77. energyWidget = await UIManager.Instance.CreateGComponent<EnergyWidget>(null, Group_ResourceBar);
  78. energyWidget.CustomInit(GlobalParam.Item_Diamond_ID);
  79. _energyWidgets.Add(energyWidget);
  80. if (type == 1)
  81. {
  82. text_btnText.text = LanguageManager.Instance.Text(1046);
  83. Trxt_Cion.text = "x" + _openBoxConfig.oneConsume;
  84. }
  85. else if (type == 2)
  86. {
  87. text_btnText.text = LanguageManager.Instance.Text(1047);
  88. Trxt_Cion.text = "x" + _openBoxConfig.tenConsume;
  89. }
  90. foreach (var itemInfo in itemInfos)
  91. {
  92. WidgetItem widgetItem = await UIManager.Instance.CreateGComponent<WidgetItem>(null, GridItem, isActive: false);
  93. widgetItem.InitWidget(itemInfo);
  94. widgetItems.Add(widgetItem);
  95. }
  96. return await base.AsyncInit(uiData);
  97. }
  98. private float timer = 0;
  99. private List<ImageMoveContainer> _imageMoveContainers = new List<ImageMoveContainer>();
  100. [CustomMethod(CustomMethodType.Update)]
  101. public void Update()
  102. {
  103. foreach (var imageMoveContainer in _imageMoveContainers)
  104. {
  105. imageMoveContainer.RenderUpdateCallBack();
  106. }
  107. }
  108. public async CTask CusstomInit()
  109. {
  110. foreach (var gameObjectPool in _gameObjectPools)
  111. {
  112. gameObjectPool.own.GetComponent<RectTransform>().anchoredPosition = transform.worldToLocalMatrix * fxpos.position;
  113. UIManager.Instance.DormancyGComponent(gameObjectPool);
  114. }
  115. _gameObjectPools.Clear();
  116. for (var i = 0; i < widgetItems.Count; i++)
  117. {
  118. animTween.Play("click", false);
  119. fx_ui_box_click.gameObject.SetActive(true);
  120. fx_ui_box_click.Play();
  121. ImageMoveContainer imageMoveContainer = new ImageMoveContainer();
  122. GameObjectPool gameObjectPool = null;
  123. if (widgetItems[i].itemInfo.config.quality >= 1 && widgetItems[i].itemInfo.config.quality <= 3)
  124. {
  125. gameObjectPool = await GObjectPool.Instance.FetchAsync<GameObjectPool>("fx_ui_box_click_1");
  126. }
  127. else if (widgetItems[i].itemInfo.config.quality > 3 && widgetItems[i].itemInfo.config.quality <= 5)
  128. {
  129. gameObjectPool = await GObjectPool.Instance.FetchAsync<GameObjectPool>("fx_ui_box_click_2");
  130. }
  131. else
  132. {
  133. gameObjectPool = await GObjectPool.Instance.FetchAsync<GameObjectPool>("fx_ui_box_click_3");
  134. }
  135. _gameObjectPools.Add(gameObjectPool);
  136. gameObjectPool.own.transform.GetComponent<RectTransform>().anchoredPosition = transform.worldToLocalMatrix * fxpos.position;
  137. gameObjectPool.own.transform.SetParent(this.transform);
  138. Vector2 pos = transform.worldToLocalMatrix * fxpos.position;
  139. Vector2 pos1 = transform.worldToLocalMatrix * (PosRoot[i] as RectTransform).position;
  140. gameObjectPool.own.GetComponent<RectTransform>().anchoredPosition = pos;
  141. // gameObjectPool.own.SetActive(true);
  142. imageMoveContainer.AddACurve(pos, pos1, 0, 3f, gameObjectPool);
  143. _imageMoveContainers.Add(imageMoveContainer);
  144. int index = i;
  145. TimerComponent.Instance.AddTimer(300, () =>
  146. {
  147. fx_ui_box_click.gameObject.SetActive(false);
  148. widgetItems[index].SetActive(true);
  149. // widgetItems[index].PlayerAnim();
  150. });
  151. await TimerComponent.Instance.WaitAsync(180 + Random.Range(0, 100));
  152. // await TimerComponent.Instance.WaitAsync(200);
  153. }
  154. tenButton.gameObject.SetActive(true);
  155. oneButton.gameObject.SetActive(true);
  156. }
  157. public override void Close()
  158. {
  159. foreach (var widgetItem in widgetItems)
  160. {
  161. UIManager.Instance.DormancyGComponent(widgetItem);
  162. }
  163. widgetItems.Clear();
  164. for (var i = 0; i < _imageMoveContainers.Count; i++)
  165. {
  166. _imageMoveContainers[i].Dispose();
  167. }
  168. _imageMoveContainers.Clear();
  169. _gameObjectPools.Clear();
  170. tenButton.gameObject.SetActive(false);
  171. oneButton.gameObject.SetActive(false);
  172. foreach (var widget in _energyWidgets)
  173. {
  174. UIManager.Instance.DormancyGComponent(widget);
  175. }
  176. _energyWidgets.Clear();
  177. base.Close();
  178. }
  179. public async static CTask OpenPanel(List<ItemInfo> itemInfos, int type, int configId)
  180. {
  181. if (UIManager.Instance.GetComponent<GachaPanel>() == null || UIManager.Instance.GetComponent<GachaPanel>().IsClose)
  182. {
  183. GachaPanel gachaPanel = await UIManager.Instance.LoadAndOpenPanel<GachaPanel>(null, UILayer.Top, uiData: new object[] { itemInfos, type, configId });
  184. await TimerComponent.Instance.WaitAsync(300);
  185. gachaPanel.CusstomInit();
  186. }
  187. }
  188. }
  189. }