GetSuitItemVIew.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 GameObject _gameObject1;
  14. private GoWrapper _wrapper1;
  15. private int guideId = 0;//0:没有引导 1:首次获得套装2:首次获得套装部件
  16. public override void Dispose()
  17. {
  18. if (_sceneObject != null)
  19. {
  20. GameObject.Destroy(_sceneObject);
  21. _sceneObject = null;
  22. }
  23. if (_scenePrefab != null)
  24. {
  25. GFGAsset.Release(ResPathUtil.GetPrefabPath("SceneDressUp"));
  26. _scenePrefab = null;
  27. }
  28. SceneController.DestroyObjectFromView(_gameObject1, _wrapper1);
  29. if (_wrapper != null)
  30. {
  31. _wrapper.Dispose();
  32. _wrapper = null;
  33. }
  34. // for (int i = 0; i < _ui.m_listClothing.numItems; i++)
  35. // {
  36. // UI_LuckyBoxBonusItem listItem = UI_LuckyBoxBonusItem.Proxy(_ui.m_listClothing.GetChildAt(i));
  37. // listItem.m_comIcon.m_icon.Dispose();
  38. // UI_LuckyBoxBonusItem.ProxyEnd();
  39. // }
  40. if (_ui != null)
  41. {
  42. _ui.Dispose();
  43. _ui = null;
  44. }
  45. base.Dispose();
  46. }
  47. protected override void OnInit()
  48. {
  49. base.OnInit();
  50. _ui = UI_GetSuitItemUI.Create();
  51. this.viewCom = _ui.target;
  52. isfullScreen = true;
  53. _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("SceneDressUp"));
  54. _ui.m_bg.onClick.Add(OnClickBg);
  55. string resPath = ResPathUtil.GetViewEffectPath("ui_ck", "ui_ck_tz");
  56. SceneController.AddObjectToView(null, null, _ui.m_holderEffect, resPath, out _gameObject1, out _wrapper1);
  57. }
  58. protected override void OnShown()
  59. {
  60. base.OnShown();
  61. GRoot.inst.touchable = true;
  62. int suitId = (int)viewData;
  63. guideId = 0;
  64. UpdateView(suitId);
  65. Timers.inst.AddUpdate(CheckGuide);
  66. }
  67. protected override void OnHide()
  68. {
  69. base.OnHide();
  70. if (_sceneObject != null)
  71. {
  72. GameObject.Destroy(_sceneObject);
  73. _sceneObject = null;
  74. }
  75. if (_wrapper != null)
  76. {
  77. _wrapper.wrapTarget = null;
  78. }
  79. if (this.viewCom == null || this.viewCom.root == null)
  80. {
  81. Timers.inst.CallLater((object param) =>
  82. {
  83. GetSuitItemController.TryShow(0);
  84. });
  85. }
  86. TryCompleteGuide();
  87. Timers.inst.Remove(CheckGuide);
  88. }
  89. private void OnClickBg()
  90. {
  91. int suitId = GetSuitItemController.TryShow(0);
  92. if (suitId > 0)
  93. {
  94. UpdateView(suitId);
  95. }
  96. else
  97. {
  98. Hide();
  99. }
  100. }
  101. private void UpdateItem(int itemdId)
  102. {
  103. UI_LuckyBoxBonusItem itemUI = _ui.m_item;
  104. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemdId);
  105. itemUI.m_comIcon.m_icon.url = ResPathUtil.GetIconPath(itemCfg);
  106. string itemName = itemCfg.name;
  107. itemUI.m_comIcon.m_txtName.text = itemName;
  108. RarityIconController.UpdateRarityIcon(itemUI.m_comIcon.m_rarity, itemdId, false);
  109. itemUI.target.data = itemdId;
  110. itemUI.target.onClick.Clear();
  111. itemUI.target.onClick.Add(OnClickItemUI);
  112. }
  113. private void OnClickItemUI(EventContext context)
  114. {
  115. GComponent item = context.sender as GComponent;
  116. int itemID = (int)item.data;
  117. GoodsItemTipsController.ShowItemTips(itemID);
  118. }
  119. private void UpdateView(int suitId)
  120. {
  121. _ui.m_holderEffect.visible = true;
  122. int count = 0;//套装当前拥有的部件数量
  123. int totalCount = 1;
  124. // int suitId = 0;
  125. int[] itemIds = null;
  126. DressUpMenuSuitDataManager.GetSuitProgressBySuitId(suitId, out count, out totalCount);
  127. // totalCount = SuitCfgManager.Instance.GetTotalCountOfOneSuit(suitId);
  128. itemIds = SuitCfgManager.Instance.GetSuitItems(suitId);
  129. if (suitId > 0)
  130. {
  131. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(suitId);
  132. _ui.m_txtName.text = "套装·" + suitCfg.name;
  133. int targetY = (int)(_ui.m_item.target.y + _ui.m_item.target.height + 50);
  134. if (count == totalCount)
  135. {
  136. guideId = 1;
  137. }
  138. else
  139. {
  140. guideId = 2;
  141. }
  142. }
  143. _ui.m_probar.max = totalCount;
  144. _ui.m_probar.value = count;
  145. // UpdateItem(itemId);
  146. if (_sceneObject != null)
  147. {
  148. GameObject.Destroy(_sceneObject);
  149. _sceneObject = null;
  150. }
  151. _sceneObject = GameObject.Instantiate(_scenePrefab);
  152. int scale = 70;
  153. _sceneObject.transform.localScale = new Vector3(scale, scale, scale);
  154. SceneController.UpdateRole(itemIds, _sceneObject);
  155. if (_wrapper == null)
  156. {
  157. _wrapper = new GoWrapper(_sceneObject);
  158. _ui.m_holder.SetNativeObject(_wrapper);
  159. }
  160. else
  161. {
  162. _wrapper.wrapTarget = _sceneObject;
  163. }
  164. }
  165. private void CheckGuide(object param)
  166. {
  167. if (GuideDataManager.IsGuideFinish(ConstGuideId.GET_SUIT_ITEM_FULL) <= 0
  168. || GuideDataManager.IsGuideFinish(ConstGuideId.GET_SUIT_ITEM_FIRST) <= 0)
  169. {
  170. UpdateToCheckGuide(null);
  171. }
  172. else
  173. {
  174. Timers.inst.Remove(CheckGuide);
  175. }
  176. }
  177. protected override void UpdateToCheckGuide(object param)
  178. {
  179. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  180. if (guideId == 1) GuideController.TryGuide(null, ConstGuideId.GET_SUIT_ITEM_FULL, 1, "恭喜你,集齐了第一套套装,快去换装界面穿上试试吧!点击空白区域继续", -1, true, (int)(this.viewCom.height - 150));
  181. if (guideId == 2) GuideController.TryGuide(null, ConstGuideId.GET_SUIT_ITEM_FIRST, 1, "恭喜你,获得了一件套装配件,集齐套装有惊喜哦!点击空白区域继续", -1, true, (int)(this.viewCom.height - 150));
  182. }
  183. protected override void TryCompleteGuide()
  184. {
  185. GuideCfg cfg;
  186. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.GET_SUIT_ITEM_FULL);
  187. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  188. GuideController.TryCompleteGuide(ConstGuideId.GET_SUIT_ITEM_FULL, 1);
  189. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.GET_SUIT_ITEM_FIRST);
  190. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  191. GuideController.TryCompleteGuide(ConstGuideId.GET_SUIT_ITEM_FIRST, 1);
  192. }
  193. }
  194. }