GetSuitItemVIew.cs 7.1 KB

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