GetSuitItemVIew.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. int itemId = (int)viewData;
  41. guideId = 0;
  42. UpdateView(itemId);
  43. }
  44. protected override void OnHide()
  45. {
  46. base.OnHide();
  47. if (_sceneObject != null)
  48. {
  49. GameObject.Destroy(_sceneObject);
  50. _sceneObject = null;
  51. }
  52. if (_wrapper != null)
  53. {
  54. _wrapper.wrapTarget = null;
  55. }
  56. if (this.viewCom == null || this.viewCom.root == null)
  57. {
  58. Timers.inst.CallLater((object param) =>
  59. {
  60. GetSuitItemController.TryShow(0);
  61. });
  62. }
  63. TryCompleteGuide();
  64. }
  65. private void OnClickBg()
  66. {
  67. int itemId = GetSuitItemController.TryShow(0);
  68. if (itemId > 0)
  69. {
  70. UpdateView(itemId);
  71. }
  72. else
  73. {
  74. Hide();
  75. }
  76. }
  77. private void UpdateItem(int itemdId)
  78. {
  79. UI_LuckyBoxBonusItem itemUI = _ui.m_item;
  80. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemdId);
  81. itemUI.m_comIcon.m_icon.url = ResPathUtil.GetIconPath(itemCfg);
  82. string itemName = itemCfg.name;
  83. itemUI.m_comIcon.m_txtName.text = itemName;
  84. RarityIconController.UpdateRarityIcon(itemUI.m_comIcon.m_rarity, itemdId, false);
  85. itemUI.target.data = itemdId;
  86. itemUI.target.onClick.Clear();
  87. itemUI.target.onClick.Add(OnClickItemUI);
  88. }
  89. private void OnClickItemUI(EventContext context)
  90. {
  91. GComponent item = context.sender as GComponent;
  92. int itemID = (int)item.data;
  93. GoodsItemTipsController.ShowItemTips(itemID);
  94. }
  95. private void UpdateView(int itemId)
  96. {
  97. _ui.m_holderEffect.visible = true;
  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. }
  114. else
  115. {
  116. guideId = 2;
  117. }
  118. }
  119. _ui.m_probar.max = totalCount;
  120. _ui.m_probar.value = count;
  121. UpdateItem(itemId);
  122. if (_sceneObject != null)
  123. {
  124. GameObject.Destroy(_sceneObject);
  125. _sceneObject = null;
  126. }
  127. _sceneObject = GameObject.Instantiate(_scenePrefab);
  128. int scale = 70;
  129. _sceneObject.transform.localScale = new Vector3(scale, scale, scale);
  130. SceneController.UpdateRole(itemIds, _sceneObject);
  131. if (_wrapper == null)
  132. {
  133. _wrapper = new GoWrapper(_sceneObject);
  134. _ui.m_holder.SetNativeObject(_wrapper);
  135. }
  136. else
  137. {
  138. _wrapper.wrapTarget = _sceneObject;
  139. }
  140. }
  141. protected override void UpdateToCheckGuide(object param)
  142. {
  143. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  144. if (guideId == 1) GuideController.TryGuide(null, ConstGuideId.GET_SUIT_ITEM_FULL, 1, "恭喜你,集齐了第一套套装,快去换装界面穿上试试吧!点击空白区域继续", -1, true, (int)(this.viewCom.height - 150));
  145. if (guideId == 2) GuideController.TryGuide(null, ConstGuideId.GET_SUIT_ITEM_FIRST, 1, "恭喜你,获得了一件套装配件,集齐套装有惊喜哦!点击空白区域继续", -1, true, (int)(this.viewCom.height - 150));
  146. }
  147. protected override void TryCompleteGuide()
  148. {
  149. GuideCfg cfg;
  150. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.GET_SUIT_ITEM_FULL);
  151. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  152. GuideController.TryCompleteGuide(ConstGuideId.GET_SUIT_ITEM_FULL, 1);
  153. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.GET_SUIT_ITEM_FIRST);
  154. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  155. GuideController.TryCompleteGuide(ConstGuideId.GET_SUIT_ITEM_FIRST, 1);
  156. }
  157. }
  158. }