GetSuitItemVIew.cs 6.9 KB

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