GachaPanel.cs 8.2 KB

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