GetSuitItemVIew.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. using UI.CommonGame;
  2. using FairyGUI;
  3. using UnityEngine;
  4. namespace GFGGame
  5. {
  6. public class GetSuitItemVIew : BaseWindow
  7. {
  8. private UI_GetSuitItemUI _ui;
  9. private GameObject _scenePrefab;
  10. private GameObject _sceneObject;
  11. private GoWrapper _wrapper;
  12. private GameObject _gameObject1;
  13. private GoWrapper _wrapper1;
  14. private int guideId = 0;//0:没有引导 1:首次获得套装2:首次获得套装部件
  15. public override void Dispose()
  16. {
  17. if (_sceneObject != null)
  18. {
  19. GameObject.Destroy(_sceneObject);
  20. _sceneObject = null;
  21. }
  22. SceneController.DestroyObjectFromView(_gameObject1, _wrapper1);
  23. if (_wrapper != null)
  24. {
  25. _wrapper.Dispose();
  26. _wrapper = null;
  27. }
  28. if (_ui != null)
  29. {
  30. _ui.Dispose();
  31. _ui = null;
  32. }
  33. base.Dispose();
  34. }
  35. protected override void OnInit()
  36. {
  37. base.OnInit();
  38. _ui = UI_GetSuitItemUI.Create();
  39. this.viewCom = _ui.target;
  40. isfullScreen = true;
  41. _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("SceneDressUp"));
  42. _ui.m_bg.onClick.Add(OnClickBg);
  43. string resPath = ResPathUtil.GetViewEffectPath("ui_ck", "ui_ck_tz");
  44. SceneController.AddObjectToView(null, null, _ui.m_holderEffect, resPath, out _gameObject1, out _wrapper1);
  45. }
  46. protected override void OnShown()
  47. {
  48. base.OnShown();
  49. GRoot.inst.touchable = true;
  50. int suitId = (int)viewData;
  51. guideId = 0;
  52. UpdateView(suitId);
  53. }
  54. protected override void OnHide()
  55. {
  56. base.OnHide();
  57. if (_sceneObject != null)
  58. {
  59. GameObject.Destroy(_sceneObject);
  60. _sceneObject = null;
  61. }
  62. if (_wrapper != null)
  63. {
  64. _wrapper.wrapTarget = null;
  65. }
  66. if (this.viewCom == null || this.viewCom.root == null)
  67. {
  68. Timers.inst.CallLater((object param) =>
  69. {
  70. GetSuitItemController.TryShow(0);
  71. });
  72. }
  73. TryCompleteGuide();
  74. }
  75. private void OnClickBg()
  76. {
  77. int suitId = GetSuitItemController.TryShow(0);
  78. if (suitId > 0)
  79. {
  80. UpdateView(suitId);
  81. }
  82. else
  83. {
  84. Hide();
  85. }
  86. }
  87. private void UpdateItem(int itemdId)
  88. {
  89. UI_LuckyBoxBonusItem itemUI = _ui.m_item;
  90. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemdId);
  91. itemUI.m_comIcon.m_icon.url = ResPathUtil.GetIconPath(itemCfg);
  92. string itemName = itemCfg.name;
  93. itemUI.m_comIcon.m_txtName.text = itemName;
  94. RarityIconController.UpdateRarityIcon(itemUI.m_comIcon.m_rarity, itemdId, false);
  95. itemUI.target.data = itemdId;
  96. itemUI.target.onClick.Clear();
  97. itemUI.target.onClick.Add(OnClickItemUI);
  98. }
  99. private void OnClickItemUI(EventContext context)
  100. {
  101. GComponent item = context.sender as GComponent;
  102. int itemID = (int)item.data;
  103. GoodsItemTipsController.ShowItemTips(itemID);
  104. }
  105. private void UpdateView(int suitId)
  106. {
  107. _ui.m_holderEffect.visible = true;
  108. int count = 0;//套装当前拥有的部件数量
  109. int totalCount = 1;
  110. // int suitId = 0;
  111. int[] itemIds = null;
  112. DressUpMenuSuitDataManager.GetSuitProgressBySuitId(suitId, out count, out totalCount);
  113. // totalCount = SuitCfgManager.Instance.GetTotalCountOfOneSuit(suitId);
  114. itemIds = SuitCfgManager.Instance.GetSuitItems(suitId);
  115. if (suitId > 0)
  116. {
  117. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(suitId);
  118. _ui.m_txtName.text = "套装·" + suitCfg.name;
  119. int targetY = (int)(_ui.m_item.target.y + _ui.m_item.target.height + 50);
  120. if (count == totalCount)
  121. {
  122. guideId = 1;
  123. }
  124. else
  125. {
  126. guideId = 2;
  127. }
  128. }
  129. _ui.m_probar.max = totalCount;
  130. _ui.m_probar.value = count;
  131. // UpdateItem(itemId);
  132. if (_sceneObject != null)
  133. {
  134. GameObject.Destroy(_sceneObject);
  135. _sceneObject = null;
  136. }
  137. _sceneObject = GameObject.Instantiate(_scenePrefab);
  138. int scale = 70;
  139. _sceneObject.transform.localScale = new Vector3(scale, scale, scale);
  140. SceneController.UpdateRole(itemIds, _sceneObject);
  141. if (_wrapper == null)
  142. {
  143. _wrapper = new GoWrapper(_sceneObject);
  144. _ui.m_holder.SetNativeObject(_wrapper);
  145. }
  146. else
  147. {
  148. _wrapper.wrapTarget = _sceneObject;
  149. }
  150. }
  151. }
  152. }