GetSuitItemVIew.cs 6.9 KB

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