RageEffect3D.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. using UnityEngine;
  2. using System.Collections;
  3. public class RageEffect3D
  4. {
  5. public const string HUD_RAGE_PREFAB = "Battle/RageImage";
  6. private GameObject mHud;
  7. private Fighter mFighter = null;
  8. Vector3 m_ragePos;
  9. public void Born(Fighter owner)
  10. {
  11. mFighter = owner;
  12. mHud = null;
  13. //EventMgr.AddEventListener<bool>(ECoreEventType.EID_BOSS_IN_RAGE, OnShowRage);
  14. }
  15. public void Dispose()
  16. {
  17. if (mHud != null)
  18. {
  19. ResourceMgr.Instance.RecycleGO(Constants.UI3DPath, HUD_RAGE_PREFAB, mHud);
  20. }
  21. mHud = null;
  22. }
  23. public void Destroy()
  24. {
  25. //EventMgr.RemoveEventListener<bool>(ECoreEventType.EID_BOSS_IN_RAGE, OnShowRage);
  26. Dispose();
  27. }
  28. public void Prepare()
  29. {
  30. InitHudUI();
  31. }
  32. public void Fight()
  33. {
  34. #if UNITY_EDITOR
  35. if (mHud)
  36. {
  37. mHud.name = mFighter.Ctrl.name + "_RageHud";
  38. }
  39. #endif
  40. ResetHudUI();
  41. }
  42. public void Deactive()
  43. {
  44. SetVisible(false);
  45. }
  46. public void OnActorDead()
  47. {
  48. if (mFighter == null) return;
  49. SetVisible(false);
  50. }
  51. public void OnActorRevive()
  52. {
  53. if (mFighter == null) return;
  54. SetVisible(false);
  55. }
  56. public void SetVisible(bool vis)
  57. {
  58. if (mHud == null) return;
  59. mHud.SetActive(vis);
  60. }
  61. public void LateUpdate()
  62. {
  63. if (mHud == null) return;
  64. if (mFighter == null)
  65. {
  66. ResourceMgr.Instance.RecycleGO(Constants.UI3DPath, HUD_RAGE_PREFAB, mHud);
  67. mHud = null;
  68. return;
  69. }
  70. // 这几种情况不需要更新下面的东西,太费了
  71. if (!mFighter.IsVisible)
  72. {
  73. return;
  74. }
  75. Vector3 curUIPointPos = mFighter.Ctrl.GetUIPointPos();
  76. // Update Hud
  77. if (mHud.activeSelf)
  78. {
  79. Vector3 hudPosition = curUIPointPos + mFighter.Actor.AvatarData.crazyPos;
  80. Vector3 curBloodPos = Camera.main.WorldToScreenPoint(hudPosition);
  81. bool isNeedUpdateUIHud = (m_ragePos != curBloodPos);
  82. m_ragePos = curBloodPos;
  83. if (isNeedUpdateUIHud)
  84. {
  85. UpdateUIHud(ref curBloodPos);
  86. }
  87. }
  88. }
  89. ///-------------------------------------------------
  90. /// 初始化Hud UI
  91. ///-------------------------------------------------
  92. private void InitHudUI()
  93. {
  94. if (mFighter == null)
  95. return;
  96. if (mHud == null)
  97. {
  98. mHud = ResourceMgr.Instance.GetGoFromPool(Constants.UI3DPath, HUD_RAGE_PREFAB);
  99. DebugHelper.Assert(mHud != null, "wtf?");
  100. if (mHud == null)
  101. {
  102. return;
  103. }
  104. Transform hudPanel = GetHudPanel();
  105. if (hudPanel != null)
  106. {
  107. mHud.transform.SetParent(hudPanel, true);
  108. mHud.transform.localScale = Vector3.one;
  109. mHud.transform.localRotation = Quaternion.identity;
  110. }
  111. }
  112. SetVisible(false);
  113. }
  114. private void ResetHudUI()
  115. {
  116. if (mHud == null || mFighter == null)
  117. {
  118. return;
  119. }
  120. //添加到对应的Panel
  121. Transform hudPanel = GetHudPanel();
  122. if (hudPanel != null)
  123. {
  124. mHud.transform.SetParent(hudPanel, true);
  125. mHud.transform.localScale = Vector3.one;
  126. mHud.transform.localRotation = Quaternion.identity;
  127. }
  128. //Camera_UI3D.GetInstance().GetCurrentCanvas().RefreshLayout();
  129. SetVisible(false);
  130. }
  131. ///-------------------------------------------------
  132. /// 更新UI Hud
  133. ///-------------------------------------------------
  134. private void UpdateUIHud(ref Vector3 bloodPosition)
  135. {
  136. if (mHud != null)
  137. {
  138. bloodPosition.Set(bloodPosition.x, bloodPosition.y, bloodPosition.z);
  139. var UI3D_Came = Camera_UI3D.GetInstance().GetCurrentCamera();
  140. if (UI3D_Came == null)
  141. {
  142. return;
  143. }
  144. mHud.transform.position = UI3D_Came.ScreenToWorldPoint(bloodPosition);
  145. }
  146. }
  147. private Transform GetHudPanel()
  148. {
  149. if (null == BattleCamera.Instance.RealCamera)
  150. {
  151. return null;
  152. }
  153. var UI3D_Came = Camera_UI3D.GetInstance().GetCurrentCamera();
  154. if (UI3D_Came == null)
  155. {
  156. return null; //有可能该局已经结束了,此时还在loading协程
  157. }
  158. Transform root = UI3D_Came.transform.Find("Hud");
  159. Transform child = root.Find("SkillNames");
  160. if (child == null)
  161. {
  162. DebugHelper.LogError("WTF????");
  163. }
  164. return child;
  165. }
  166. private void OnShowRage(CoreEvent<bool> ce)
  167. {
  168. bool rage = ce.Data;
  169. SetVisible(rage);
  170. }
  171. }