GetSuitItemVIew.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. }
  45. protected override void OnHide()
  46. {
  47. base.OnHide();
  48. if (_sceneObject != null)
  49. {
  50. GameObject.Destroy(_sceneObject);
  51. _sceneObject = null;
  52. }
  53. if (_wrapper != null)
  54. {
  55. _wrapper.wrapTarget = null;
  56. }
  57. if (this.viewCom == null || this.viewCom.root == null)
  58. {
  59. Timers.inst.CallLater((object param) =>
  60. {
  61. GetSuitItemController.TryShow(0);
  62. });
  63. }
  64. TryCompleteGuide();
  65. }
  66. private void OnClickBg()
  67. {
  68. int suitId = GetSuitItemController.TryShow(0);
  69. if (suitId > 0)
  70. {
  71. UpdateView(suitId);
  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_comIcon.m_icon.url = ResPathUtil.GetIconPath(itemCfg);
  83. string itemName = itemCfg.name;
  84. itemUI.m_comIcon.m_txtName.text = itemName;
  85. RarityIconController.UpdateRarityIcon(itemUI.m_comIcon.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 suitId)
  97. {
  98. _ui.m_holderEffect.visible = true;
  99. int count = 0;//套装当前拥有的部件数量
  100. int totalCount = 1;
  101. // int suitId = 0;
  102. int[] itemIds = null;
  103. DressUpMenuSuitDataManager.GetSuitProgressBySuitId(suitId, out count, out totalCount);
  104. // totalCount = SuitCfgManager.Instance.GetTotalCountOfOneSuit(suitId);
  105. itemIds = SuitCfgManager.Instance.GetSuitItems(suitId);
  106. if (suitId > 0)
  107. {
  108. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(suitId);
  109. _ui.m_txtName.text = "套装·" + suitCfg.name;
  110. int targetY = (int)(_ui.m_item.target.y + _ui.m_item.target.height + 50);
  111. if (count == totalCount)
  112. {
  113. guideId = 1;
  114. }
  115. else
  116. {
  117. guideId = 2;
  118. }
  119. }
  120. _ui.m_probar.max = totalCount;
  121. _ui.m_probar.value = count;
  122. // UpdateItem(itemId);
  123. if (_sceneObject != null)
  124. {
  125. GameObject.Destroy(_sceneObject);
  126. _sceneObject = null;
  127. }
  128. _sceneObject = GameObject.Instantiate(_scenePrefab);
  129. int scale = 70;
  130. _sceneObject.transform.localScale = new Vector3(scale, scale, scale);
  131. SceneController.UpdateRole(itemIds, _sceneObject);
  132. if (_wrapper == null)
  133. {
  134. _wrapper = new GoWrapper(_sceneObject);
  135. _ui.m_holder.SetNativeObject(_wrapper);
  136. }
  137. else
  138. {
  139. _wrapper.wrapTarget = _sceneObject;
  140. }
  141. }
  142. protected override void UpdateToCheckGuide(object param)
  143. {
  144. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  145. if (guideId == 1) GuideController.TryGuide(null, ConstGuideId.GET_SUIT_ITEM_FULL, 1, "恭喜你,集齐了第一套套装,快去换装界面穿上试试吧!点击空白区域继续", -1, true, (int)(this.viewCom.height - 150));
  146. if (guideId == 2) GuideController.TryGuide(null, ConstGuideId.GET_SUIT_ITEM_FIRST, 1, "恭喜你,获得了一件套装配件,集齐套装有惊喜哦!点击空白区域继续", -1, true, (int)(this.viewCom.height - 150));
  147. }
  148. protected override void TryCompleteGuide()
  149. {
  150. GuideCfg cfg;
  151. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.GET_SUIT_ITEM_FULL);
  152. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  153. GuideController.TryCompleteGuide(ConstGuideId.GET_SUIT_ITEM_FULL, 1);
  154. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.GET_SUIT_ITEM_FIRST);
  155. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  156. GuideController.TryCompleteGuide(ConstGuideId.GET_SUIT_ITEM_FIRST, 1);
  157. }
  158. }
  159. }