GetSuitItemVIew.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. }
  39. protected override void OnHide()
  40. {
  41. base.OnHide();
  42. if (_sceneObject != null)
  43. {
  44. GameObject.Destroy(_sceneObject);
  45. _sceneObject = null;
  46. }
  47. if (_wrapper != null)
  48. {
  49. _wrapper.wrapTarget = null;
  50. }
  51. if (this.viewCom == null || this.viewCom.root == null)
  52. {
  53. Timers.inst.CallLater((object param) =>
  54. {
  55. GetSuitItemController.TryShow(0);
  56. });
  57. }
  58. GuideController.HideGuide();
  59. GuideController.TryCompleteGuide(ConstGuideId.GET_SUIT_ITEM_VIEW_FIRST);
  60. GuideController.TryCompleteGuide(ConstGuideId.GET_SUIT_ITEM_VIEW_FULL);
  61. TryCompleteGuide();
  62. }
  63. private void OnClickBg()
  64. {
  65. int itemId = GetSuitItemController.TryShow(0);
  66. if (itemId > 0)
  67. {
  68. GuideController.HideGuide();
  69. GuideController.TryCompleteGuide(ConstGuideId.GET_SUIT_ITEM_VIEW_FIRST);
  70. GuideController.TryCompleteGuide(ConstGuideId.GET_SUIT_ITEM_VIEW_FULL);
  71. UpdateView(itemId);
  72. }
  73. else
  74. {
  75. Hide();
  76. }
  77. }
  78. private void UpdateItem(int itemdId)
  79. {
  80. UI_LuckyBoxBonusItem itemUI = _ui.m_item;
  81. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemdId);
  82. itemUI.m_icon.url = ResPathUtil.GetIconPath(itemCfg);
  83. string itemName = itemCfg.name;
  84. itemUI.m_txtName.text = itemName;
  85. RarityIconController.UpdateRarityIcon(itemUI.m_rarity, itemdId, false);
  86. itemUI.target.data = itemdId;
  87. itemUI.target.onClick.Clear();
  88. itemUI.target.onClick.Add(OnClickItemUI);
  89. }
  90. private void OnClickItemUI(EventContext context)
  91. {
  92. GComponent item = context.sender as GComponent;
  93. int itemID = (int)item.data;
  94. GoodsItemTipsController.ShowItemTips(itemID);
  95. }
  96. private void UpdateView(int itemId)
  97. {
  98. int count = 0;
  99. int totalCount = 1;
  100. int suitId = 0;
  101. int[] itemIds = null;
  102. DressUpMenuSuitDataManager.GetSuitProgressByItemId(itemId, out suitId, out count);
  103. totalCount = SuitCfgManager.Instance.GetTotalCountOfOneSuit(suitId);
  104. itemIds = SuitCfgManager.Instance.GetSuitItems(suitId);
  105. if (suitId > 0)
  106. {
  107. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(suitId);
  108. _ui.m_txtName.text = "套装·" + suitCfg.name;
  109. int targetY = (int)(_ui.m_item.target.y + _ui.m_item.target.height + 50);
  110. if (count == totalCount)
  111. {
  112. guideId = 1;
  113. GuideController.TryGuideByGuideId(null, ConstGuideId.GET_SUIT_ITEM_VIEW_FULL, 1, false, "恭喜你,集齐了第一套套装,快去换装界面穿上试试吧!点击空白区域继续", targetY);
  114. }
  115. else
  116. {
  117. guideId = 2;
  118. GuideController.TryGuideByGuideId(null, ConstGuideId.GET_SUIT_ITEM_VIEW_FIRST, 1, false, "恭喜你,获得了一件套装配件,集齐套装有惊喜哦!点击空白区域继续", targetY);
  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. protected override void UpdateToCheckGuide(object param)
  144. {
  145. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  146. if (guideId == 1) GuideController.TryGuide(null, ConstGuideId.GET_SUIT_ITEM_FULL, 1, "恭喜你,集齐了第一套套装,快去换装界面穿上试试吧!点击空白区域继续", false, 0, true, false, (int)(this.viewCom.height - 150));
  147. if (guideId == 2) GuideController.TryGuide(null, ConstGuideId.GET_SUIT_ITEM_FIRST, 1, "恭喜你,获得了一件套装配件,集齐套装有惊喜哦!点击空白区域继续", false, 0, true, false, (int)(this.viewCom.height - 150));
  148. }
  149. private void TryCompleteGuide()
  150. {
  151. GuideCfg cfg;
  152. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.GET_SUIT_ITEM_FULL);
  153. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  154. GuideController.TryCompleteGuide(ConstGuideId.GET_SUIT_ITEM_FULL, 1);
  155. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.GET_SUIT_ITEM_FIRST);
  156. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  157. GuideController.TryCompleteGuide(ConstGuideId.GET_SUIT_ITEM_FIRST, 1);
  158. }
  159. }
  160. }