GetSuitItemVIew.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 int guideId = 0;//0:没有引导 1:首次获得套装2:首次获得套装部件
  14. public override void Dispose()
  15. {
  16. if (_scenePrefab != null)
  17. {
  18. GameObject.Destroy(_scenePrefab);
  19. _scenePrefab = null;
  20. }
  21. base.Dispose();
  22. }
  23. protected override void OnInit()
  24. {
  25. base.OnInit();
  26. _ui = UI_GetSuitItemUI.Create();
  27. this.viewCom = _ui.target;
  28. isfullScreen = true;
  29. _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("SceneDressUp"));
  30. _ui.m_bg.onClick.Add(OnClickBg);
  31. }
  32. protected override void OnShown()
  33. {
  34. base.OnShown();
  35. int itemId = (int)viewData;
  36. guideId = 0;
  37. UpdateView(itemId);
  38. Timers.inst.AddUpdate(UpdateToCheckGuide);
  39. }
  40. protected override void OnHide()
  41. {
  42. base.OnHide();
  43. if (_sceneObject != null)
  44. {
  45. GameObject.Destroy(_sceneObject);
  46. _sceneObject = null;
  47. }
  48. if (_wrapper != null)
  49. {
  50. _wrapper.wrapTarget = null;
  51. }
  52. if (this.viewCom == null || this.viewCom.root == null)
  53. {
  54. Timers.inst.CallLater((object param) =>
  55. {
  56. GetSuitItemController.TryShow(0);
  57. });
  58. }
  59. GuideController.HideGuide();
  60. GuideController.TryCompleteGuide(ConstGuideId.GET_SUIT_ITEM_VIEW_FIRST);
  61. GuideController.TryCompleteGuide(ConstGuideId.GET_SUIT_ITEM_VIEW_FULL);
  62. Timers.inst.Remove(UpdateToCheckGuide);
  63. TryCompleteGuide();
  64. }
  65. private void OnClickBg()
  66. {
  67. int itemId = GetSuitItemController.TryShow(0);
  68. if (itemId > 0)
  69. {
  70. GuideController.HideGuide();
  71. GuideController.TryCompleteGuide(ConstGuideId.GET_SUIT_ITEM_VIEW_FIRST);
  72. GuideController.TryCompleteGuide(ConstGuideId.GET_SUIT_ITEM_VIEW_FULL);
  73. UpdateView(itemId);
  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_icon.url = ResPathUtil.GetIconPath(itemCfg);
  85. string itemName = itemCfg.name;
  86. itemUI.m_txtName.text = itemName;
  87. RarityIconController.UpdateRarityIcon(itemUI.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 itemId)
  99. {
  100. int count = 0;
  101. int totalCount = 1;
  102. int suitId = 0;
  103. int[] itemIds = null;
  104. DressUpMenuSuitDataManager.GetSuitProgressByItemId(itemId, out suitId, out count);
  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. GuideController.TryGuideByGuideId(null, ConstGuideId.GET_SUIT_ITEM_VIEW_FULL, 1, false, "恭喜你,集齐了第一套套装,快去换装界面穿上试试吧!点击空白区域继续", targetY);
  116. }
  117. else
  118. {
  119. guideId = 2;
  120. GuideController.TryGuideByGuideId(null, ConstGuideId.GET_SUIT_ITEM_VIEW_FIRST, 1, false, "恭喜你,获得了一件套装配件,集齐套装有惊喜哦!点击空白区域继续", targetY);
  121. }
  122. }
  123. _ui.m_probar.max = totalCount;
  124. _ui.m_probar.value = count;
  125. UpdateItem(itemId);
  126. if (_sceneObject != null)
  127. {
  128. GameObject.Destroy(_sceneObject);
  129. _sceneObject = null;
  130. }
  131. _sceneObject = GameObject.Instantiate(_scenePrefab);
  132. int scale = 70;
  133. _sceneObject.transform.localScale = new Vector3(scale, scale, scale);
  134. SceneController.UpdateRole(itemIds, _sceneObject);
  135. if (_wrapper == null)
  136. {
  137. _wrapper = new GoWrapper(_sceneObject);
  138. _ui.m_holder.SetNativeObject(_wrapper);
  139. }
  140. else
  141. {
  142. _wrapper.wrapTarget = _sceneObject;
  143. }
  144. }
  145. private void UpdateToCheckGuide(object param)
  146. {
  147. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  148. if (guideId == 1) GuideController.TryGuide(null, ConstGuideId.GET_SUIT_ITEM_FULL, 1, "恭喜你,集齐了第一套套装,快去换装界面穿上试试吧!点击空白区域继续", false, 0, true, false, (int)(this.viewCom.height - 150));
  149. if (guideId == 2) GuideController.TryGuide(null, ConstGuideId.GET_SUIT_ITEM_FIRST, 1, "恭喜你,获得了一件套装配件,集齐套装有惊喜哦!点击空白区域继续", false, 0, true, false, (int)(this.viewCom.height - 150));
  150. }
  151. private void TryCompleteGuide()
  152. {
  153. GuideCfg cfg;
  154. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.GET_SUIT_ITEM_FULL);
  155. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  156. GuideController.TryCompleteGuide(ConstGuideId.GET_SUIT_ITEM_FULL, 1);
  157. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.GET_SUIT_ITEM_FIRST);
  158. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  159. GuideController.TryCompleteGuide(ConstGuideId.GET_SUIT_ITEM_FIRST, 1);
  160. }
  161. }
  162. }