GachaPanel.cs 8.4 KB

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