GetSuitItemVIew.cs 6.8 KB

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