LuckyBoxBonusShowView.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using UnityEngine;
  2. using FairyGUI;
  3. using UI.LuckyBox;
  4. using System.Collections.Generic;
  5. using System.Collections;
  6. namespace GFGGame
  7. {
  8. public class LuckyBoxBonusShowView : BaseWindow
  9. {
  10. private UI_LuckBoxBonusShowUI _ui;
  11. private List<ItemData> _rewardList = new List<ItemData>();
  12. private List<GameObject> _gameobjects = new List<GameObject>();
  13. private List<GoWrapper> _wrappers = new List<GoWrapper>();
  14. private GameObject _gameobject;
  15. private GoWrapper _wrapper;
  16. private int _effectIndex = 0;
  17. public override void Dispose()
  18. {
  19. base.Dispose();
  20. for (int i = 0; i < _gameobjects.Count; i++)
  21. {
  22. SceneController.DestroyObjectFromView(_gameobjects[i], _wrappers[i]);
  23. }
  24. SceneController.DestroyObjectFromView(_gameobject, _wrapper);
  25. if (_ui != null)
  26. {
  27. _ui.Dispose();
  28. _ui = null;
  29. }
  30. }
  31. protected override void OnInit()
  32. {
  33. base.OnInit();
  34. packageName = UI_LuckBoxBonusShowUI.PACKAGE_NAME;
  35. _ui = UI_LuckBoxBonusShowUI.Create();
  36. this.viewCom = _ui.target;
  37. isfullScreen = true;
  38. _ui.m_loaBg.onClick.Add(this.Hide);
  39. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("zx_bg");
  40. }
  41. protected override void OnShown()
  42. {
  43. base.OnShown();
  44. _rewardList.AddRange(this.viewData as List<ItemData>);
  45. _effectIndex = 0;
  46. if (_rewardList.Count == 1)
  47. {
  48. _ui.m_c1.selectedIndex = 0;
  49. UpdateItem(_ui.m_itemOne.target, 0);
  50. }
  51. else
  52. {
  53. for (int i = 0; i < _rewardList.Count; i++)
  54. {
  55. UpdateItem(_ui.target.GetChild("item" + i).asCom, i);
  56. }
  57. }
  58. }
  59. protected override void OnHide()
  60. {
  61. base.OnHide();
  62. }
  63. private void UpdateItem(GComponent com, int index)
  64. {
  65. UI_LuckyBoxBonusShowItem item = UI_LuckyBoxBonusShowItem.Proxy(com);
  66. ItemData itemData = _rewardList[index];
  67. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  68. item.m_comIcon.m_c1.selectedIndex = itemData.rarity;
  69. item.m_comIcon.m_txtName.text = itemCfg.name;
  70. item.m_comIcon.m_icon.url = ResPathUtil.GetIconPath(itemCfg);
  71. if (itemData.rarity > 2)
  72. {
  73. string resPath = ResPathUtil.GetViewEffectPath("ui_LuckyBox", itemData.rarity == ConstDressRarity.Rarity_TIANYI ? "CK_all_02" : "CK_all_01");
  74. if (_effectIndex >= _gameobjects.Count)
  75. {
  76. GameObject gameObject = _gameobjects[_effectIndex];
  77. GoWrapper wrapper = _wrappers[_effectIndex];
  78. SceneController.AddObjectToView(gameObject, wrapper, item.m_comIcon.m_holder, resPath, out gameObject, out wrapper);
  79. }
  80. else
  81. {
  82. SceneController.AddObjectToView(null, null, item.m_comIcon.m_holder, resPath, out GameObject gameObject, out GoWrapper wrapper);
  83. _gameobjects.Add(gameObject);
  84. _wrappers.Add(wrapper);
  85. }
  86. _effectIndex++;
  87. }
  88. int count = 0;
  89. bool isFirst = false;
  90. for (int i = 0; i < _rewardList.Count; i++)
  91. {
  92. if (_rewardList[i].id == itemData.id) count++;
  93. if (count == 1 && i == index) isFirst = true;
  94. }
  95. item.m_comIcon.m_imgNew.visible = count == ItemDataManager.GetItemNum(itemData.id) && isFirst;
  96. UI_LuckyBoxBonusShowItem.ProxyEnd();
  97. }
  98. }
  99. }