GetSuitItemVIew.cs 6.6 KB

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