MagicWeaponWidget.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. using Common.Utility.CombatEvent;
  2. using Core.Language;
  3. using Excel2Json;
  4. using Fort23.Core;
  5. using Fort23.UTool;
  6. using GameLogic.Combat.Buff;
  7. using GameLogic.Combat.CombatTool;
  8. using GameLogic.Combat.Hero;
  9. using UnityEngine;
  10. namespace Fort23.Mono
  11. {
  12. [UIBinding(prefab = "MagicWeaponWidget")]
  13. public partial class MagicWeaponWidget : UIComponent
  14. {
  15. private CombatMagicWeaponEntity combatMagicWeaponEntity;
  16. private bool isChargedFinish;
  17. private bool isForewarn;
  18. private ParticleSystemPool noshifang;
  19. private ParticleSystemPool chargedFinish;
  20. // private ParticleSystemPool chargedFinish;
  21. private void Init()
  22. {
  23. }
  24. public override void AddEvent()
  25. {
  26. StaticUpdater.Instance.AddLateUpdateCallBack(Update);
  27. CombatEventManager.Instance.AddEventListener(CombatEventType.AddBuff, AddBuff);
  28. CombatEventManager.Instance.AddEventListener(CombatEventType.UseMagicWeapon, UseMagicWeapon);
  29. CombatEventManager.Instance.AddEventListener(CombatEventType.RemoveBuff, RemoveBuff);
  30. }
  31. public override void DelEvent()
  32. {
  33. StaticUpdater.Instance.RemoveLateUpdateCallBack(Update);
  34. CombatEventManager.Instance.RemoveEventListener(CombatEventType.AddBuff, AddBuff);
  35. CombatEventManager.Instance.RemoveEventListener(CombatEventType.UseMagicWeapon, UseMagicWeapon);
  36. CombatEventManager.Instance.RemoveEventListener(CombatEventType.RemoveBuff, RemoveBuff);
  37. }
  38. private void UseMagicWeapon(IEventData iEventData)
  39. {
  40. UseMagicWeaponEventData useMagicWeaponEventData = iEventData as UseMagicWeaponEventData;
  41. if (useMagicWeaponEventData.combatMagicWeaponEntity == combatMagicWeaponEntity)
  42. {
  43. isChargedFinish = false;
  44. isForewarn = false;
  45. GObjectPool.Instance.Recycle(chargedFinish);
  46. chargedFinish = null;
  47. icon.IsGray = true;
  48. }
  49. }
  50. private void AddBuff(IEventData iEventData)
  51. {
  52. BuffEventData buffEventData = iEventData as BuffEventData;
  53. if (buffEventData.target == combatMagicWeaponEntity)
  54. {
  55. if (buffEventData.BuffBasic is b_1008)
  56. {
  57. GObjectPool.Instance.FetchAsync<ParticleSystemPool>("fx_ui_fb_Noshifang",
  58. delegate(ParticleSystemPool pool)
  59. {
  60. pool.transform.SetParent(transform);
  61. pool.transform.localPosition = new Vector3(0, 0, 0);
  62. pool.transform.SetAsLastSibling();
  63. noshifang = pool;
  64. });
  65. // feng.SetActive(true);
  66. }
  67. }
  68. }
  69. private void RemoveBuff(IEventData iEventData)
  70. {
  71. BuffEventData buffEventData = iEventData as BuffEventData;
  72. if (buffEventData.target == combatMagicWeaponEntity)
  73. {
  74. if (buffEventData.BuffBasic is b_1008)
  75. {
  76. GObjectPool.Instance.Recycle(noshifang);
  77. noshifang = null;
  78. }
  79. }
  80. }
  81. public override void AddButtonEvent()
  82. {
  83. myButton.onClick.AddListener(async () =>
  84. {
  85. if (combatMagicWeaponEntity.IsEnemy)
  86. {
  87. // SkillConfig skillConfig = SkillBasic.SelfSkillConfig;
  88. CombatController.currActiveCombat.isUpdate = false;
  89. SkillInfopanel skillInfopanel = await SkillInfopanel.OpenPanle(combatMagicWeaponEntity.FaBaoInfo);
  90. skillInfopanel.UIClosed(() => { CombatController.currActiveCombat.isUpdate = true; });
  91. // SkillMassgePanel.OpenSkillSelectPanel(
  92. // LanguageManager.Instance.Text(combatMagicWeaponEntity.FaBaoInfo.FabaoConfig.name),
  93. // LanguageManager.Instance.Text(combatMagicWeaponEntity.FaBaoInfo.FabaoConfig.model),
  94. // delegate() { CombatController.currActiveCombat.isUpdate = true; });
  95. return;
  96. }
  97. if (combatMagicWeaponEntity == null || !combatMagicWeaponEntity.IsCanUse())
  98. {
  99. return;
  100. }
  101. b_1008 b1008 = combatMagicWeaponEntity.BuffControl.GetBuffBasicForType<b_1008>();
  102. if (b1008 != null)
  103. {
  104. return;
  105. }
  106. if (PlayerGuideManager.Instance.GuideIsCanDo(9,1))
  107. {
  108. PlayerGuideManager.Instance.NextGuide();
  109. }
  110. combatMagicWeaponEntity.UseMagicWeapon();
  111. });
  112. }
  113. public void InitWidget(CombatMagicWeaponEntity combatMagicWeaponEntity)
  114. {
  115. noshifang = null;
  116. chargedFinish = null;
  117. // feng.SetActive(false);
  118. this.combatMagicWeaponEntity = combatMagicWeaponEntity;
  119. icon.icon_name = combatMagicWeaponEntity.FaBaoInfo.SkillConfig.icon;
  120. icon.IsGray = true;
  121. icon_hui.icon_name = combatMagicWeaponEntity.FaBaoInfo.SkillConfig.icon;
  122. }
  123. private void Update()
  124. {
  125. if (combatMagicWeaponEntity == null)
  126. {
  127. return;
  128. }
  129. float d =
  130. (combatMagicWeaponEntity.cd + combatMagicWeaponEntity.RootMagicWeaponControl.globalMagicWeaponCd) /
  131. (combatMagicWeaponEntity.MaxCd);
  132. float max = 140;
  133. float spMax = 80;
  134. float a = (max - spMax) / 2 / max;
  135. float startA = 1 - a;
  136. float fa = 1 - ((startA - d) / (startA - a));
  137. float y = icon_hui.imageH;
  138. icon_hui.fillAmount = fa;
  139. bg_hui.fillAmount = d;
  140. // bg_.fillAmount = d;
  141. if (combatMagicWeaponEntity.cd < 1 && !isForewarn)
  142. {
  143. isForewarn = true;
  144. icon.IsGray = false;
  145. GObjectPool.Instance.FetchAsync<ParticleSystemPool>("fx_ui_fb_gw_Starshifang",
  146. delegate(ParticleSystemPool pool)
  147. {
  148. pool.transform.SetParent(transform);
  149. pool.transform.localPosition = new Vector3(0, 0, 0);
  150. pool.transform.SetAsLastSibling();
  151. });
  152. }
  153. if (!isChargedFinish && combatMagicWeaponEntity.cd <= 0)
  154. {
  155. isChargedFinish = true;
  156. GObjectPool.Instance.FetchAsync<ParticleSystemPool>("fx_ui_fb_shifang",
  157. delegate(ParticleSystemPool pool)
  158. {
  159. pool.transform.SetParent(transform);
  160. pool.transform.localPosition = new Vector3(0, 0, 0);
  161. pool.transform.SetSiblingIndex(3);
  162. chargedFinish = pool;
  163. });
  164. }
  165. }
  166. }
  167. }