GetSuitItemVIew.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. using UI.CommonGame;
  2. using FairyGUI;
  3. using UnityEngine;
  4. using static UnityEditor.Progress;
  5. namespace GFGGame
  6. {
  7. public class GetSuitItemVIew : BaseWindow
  8. {
  9. private UI_GetSuitItemUI _ui;
  10. private GameObject _scenePrefab;
  11. private GameObject _sceneObject;
  12. private GoWrapper _wrapper;
  13. private int guideId = 0;//0:没有引导 1:首次获得套装2:首次获得套装部件
  14. public override void Dispose()
  15. {
  16. if (_scenePrefab != null)
  17. {
  18. GameObject.Destroy(_scenePrefab);
  19. _scenePrefab = null;
  20. }
  21. base.Dispose();
  22. }
  23. protected override void OnInit()
  24. {
  25. base.OnInit();
  26. _ui = UI_GetSuitItemUI.Create();
  27. this.viewCom = _ui.target;
  28. isfullScreen = true;
  29. _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("SceneDressUp"));
  30. _ui.m_bg.onClick.Add(OnClickBg);
  31. }
  32. protected override void OnShown()
  33. {
  34. base.OnShown();
  35. int itemId = (int)viewData;
  36. guideId = 0;
  37. UpdateView(itemId);
  38. }
  39. protected override void OnHide()
  40. {
  41. base.OnHide();
  42. if (_sceneObject != null)
  43. {
  44. GameObject.Destroy(_sceneObject);
  45. _sceneObject = null;
  46. }
  47. if (_wrapper != null)
  48. {
  49. _wrapper.wrapTarget = null;
  50. }
  51. if (this.viewCom == null || this.viewCom.root == null)
  52. {
  53. Timers.inst.CallLater((object param) =>
  54. {
  55. GetSuitItemController.TryShow(0);
  56. });
  57. }
  58. TryCompleteGuide();
  59. }
  60. private void OnClickBg()
  61. {
  62. int itemId = GetSuitItemController.TryShow(0);
  63. if (itemId > 0)
  64. {
  65. UpdateView(itemId);
  66. }
  67. else
  68. {
  69. Hide();
  70. }
  71. }
  72. private void UpdateItem(int itemdId)
  73. {
  74. UI_LuckyBoxBonusItem itemUI = _ui.m_item;
  75. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemdId);
  76. itemUI.m_icon.url = ResPathUtil.GetIconPath(itemCfg);
  77. string itemName = itemCfg.name;
  78. itemUI.m_txtName.text = itemName;
  79. RarityIconController.UpdateRarityIcon(itemUI.m_rarity, itemdId, false);
  80. itemUI.target.data = itemdId;
  81. itemUI.target.onClick.Clear();
  82. itemUI.target.onClick.Add(OnClickItemUI);
  83. }
  84. private void OnClickItemUI(EventContext context)
  85. {
  86. GComponent item = context.sender as GComponent;
  87. int itemID = (int)item.data;
  88. GoodsItemTipsController.ShowItemTips(itemID);
  89. }
  90. private void UpdateView(int itemId)
  91. {
  92. int count = 0;
  93. int totalCount = 1;
  94. int suitId = 0;
  95. int[] itemIds = null;
  96. DressUpMenuSuitDataManager.GetSuitProgressByItemId(itemId, out suitId, out count);
  97. totalCount = SuitCfgManager.Instance.GetTotalCountOfOneSuit(suitId);
  98. itemIds = SuitCfgManager.Instance.GetSuitItems(suitId);
  99. if (suitId > 0)
  100. {
  101. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(suitId);
  102. _ui.m_txtName.text = "套装·" + suitCfg.name;
  103. int targetY = (int)(_ui.m_item.target.y + _ui.m_item.target.height + 50);
  104. if (count == totalCount)
  105. {
  106. guideId = 1;
  107. }
  108. else
  109. {
  110. guideId = 2;
  111. }
  112. }
  113. _ui.m_probar.max = totalCount;
  114. _ui.m_probar.value = count;
  115. UpdateItem(itemId);
  116. if (_sceneObject != null)
  117. {
  118. GameObject.Destroy(_sceneObject);
  119. _sceneObject = null;
  120. }
  121. _sceneObject = GameObject.Instantiate(_scenePrefab);
  122. int scale = 70;
  123. _sceneObject.transform.localScale = new Vector3(scale, scale, scale);
  124. SceneController.UpdateRole(itemIds, _sceneObject);
  125. if (_wrapper == null)
  126. {
  127. _wrapper = new GoWrapper(_sceneObject);
  128. _ui.m_holder.SetNativeObject(_wrapper);
  129. }
  130. else
  131. {
  132. _wrapper.wrapTarget = _sceneObject;
  133. }
  134. }
  135. protected override void UpdateToCheckGuide(object param)
  136. {
  137. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  138. if (guideId == 1) GuideController.TryGuide(null, ConstGuideId.GET_SUIT_ITEM_FULL, 1, "恭喜你,集齐了第一套套装,快去换装界面穿上试试吧!点击空白区域继续", false, 0, true, false, (int)(this.viewCom.height - 150));
  139. if (guideId == 2) GuideController.TryGuide(null, ConstGuideId.GET_SUIT_ITEM_FIRST, 1, "恭喜你,获得了一件套装配件,集齐套装有惊喜哦!点击空白区域继续", false, 0, true, false, (int)(this.viewCom.height - 150));
  140. }
  141. protected override void TryCompleteGuide()
  142. {
  143. GuideCfg cfg;
  144. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.GET_SUIT_ITEM_FULL);
  145. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  146. GuideController.TryCompleteGuide(ConstGuideId.GET_SUIT_ITEM_FULL, 1);
  147. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.GET_SUIT_ITEM_FIRST);
  148. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  149. GuideController.TryCompleteGuide(ConstGuideId.GET_SUIT_ITEM_FIRST, 1);
  150. }
  151. }
  152. }