GetSuitItemVIew.cs 6.6 KB

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