FightingTipManager.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace YLBattle
  5. {
  6. public class FightingTipManager : MonoBehaviour
  7. {
  8. /// <summary>
  9. /// 画布
  10. /// </summary>
  11. private Canvas m_Canvas = null;
  12. /// <summary>
  13. ///坐标
  14. /// </summary>
  15. private RectTransform rectTransform;
  16. /// <summary>
  17. /// 实例
  18. /// </summary>
  19. static FightingTipManager mInstance;
  20. /// <summary>
  21. /// 获取单键
  22. /// </summary>
  23. /// <returns>单键实例</returns>
  24. public static FightingTipManager Instance
  25. {
  26. get
  27. {
  28. if (mInstance == null)
  29. {
  30. GameObject obj = GameObject.Find("FightingTipManager");
  31. if (obj != null)
  32. {
  33. mInstance = obj.AddComponent<FightingTipManager>();
  34. }
  35. }
  36. return mInstance;
  37. }
  38. }
  39. void Start()
  40. {
  41. m_Canvas = GetComponent<Canvas>();
  42. rectTransform = m_Canvas.transform as RectTransform;
  43. }
  44. /// <summary>
  45. /// 在目标位置(UI层)上创建特效
  46. /// </summary>
  47. /// <param name="Id">目标Id</param>
  48. /// <param name="resName">资源名称</param>
  49. /// <param name="posType">位置类型 0=transform脚底 1=shoot/hit 2=指定位置</param>
  50. public void createPosEffect(string Id, string resName, Vector3 pos, int posType = 0, float time = 1.0f)
  51. {
  52. Fighter target = FightingManager.Instance.GetFighter(Id);
  53. #region 加载准备阶段光效
  54. ResourceHelper.Instance.LoadAssetBundle(resName, ab =>
  55. {
  56. if (ab != null)
  57. {
  58. GameObject comUIEff = (GameObject)Instantiate(ab.LoadAsset(resName));
  59. Vector3 targetPos = Vector3.zero;
  60. if (posType == 2)
  61. {
  62. targetPos = WorldToGUI(pos);
  63. }
  64. else if (target != null)
  65. {
  66. if (posType == 1)
  67. {
  68. if (target.mTeam == EBattleTeam.REDTEAM)
  69. {
  70. targetPos = WorldToGUI(target.mBodyCenterPos);
  71. }
  72. else
  73. {
  74. targetPos = target.mBodyCenterPos;
  75. }
  76. }
  77. else
  78. {
  79. if (target.mTeam == EBattleTeam.REDTEAM)
  80. {
  81. targetPos = WorldToGUI(target.mBodyRootPos);
  82. }
  83. else
  84. {
  85. targetPos = target.mBodyRootPos;
  86. }
  87. }
  88. }
  89. this.TranformHandle(comUIEff.transform, targetPos);
  90. ExplodeBase exloreScript = comUIEff.GetComponent<ExplodeBase>();
  91. if (exloreScript != null)
  92. {
  93. exloreScript.enabled = false;
  94. }
  95. ///(用于非战斗的定点位置爆炸跟踪使用)
  96. ExplodeTraceBase explode = comUIEff.GetComponent<ExplodeTraceBase>();
  97. if (explode == null)
  98. {
  99. explode = comUIEff.AddComponent<ExplodeTraceBase>();
  100. }
  101. explode.lifeTime = time;
  102. explode.TargetId = Id;
  103. explode.posType = posType;
  104. }
  105. else
  106. {
  107. LogHelper.LogWarning("特效模版数据有误!!! " + resName);
  108. }
  109. });
  110. #endregion
  111. }
  112. /// <summary>
  113. ///
  114. /// </summary>
  115. /// <returns></returns>
  116. public Vector3 WorldToGUI(Vector3 orgPos)
  117. {
  118. Vector2 pos;
  119. Vector3 screenPos = CameraManager.Instance.SenceCamara.WorldToScreenPoint(orgPos);
  120. RectTransformUtility.ScreenPointToLocalPointInRectangle(this.rectTransform,
  121. screenPos, CameraManager.Instance.SenceTIPCamera, out pos);
  122. return pos;
  123. }
  124. /// <summary>
  125. /// Tranform的处理,3D->UI
  126. /// </summary>
  127. /// <param name="model"></param>
  128. /// <param name="trgPos"></param>
  129. public void TranformHandle(Transform model, Vector3 trgPos)
  130. {
  131. Transform[] all = model.GetComponentsInChildren<Transform>();
  132. ///默认UI相机照射所有特效
  133. ///如果是bomb在敌人身上(3D)身上,则使用3D摄像机;
  134. foreach (Transform rc in all)
  135. {
  136. rc.gameObject.layer = LayerMask.NameToLayer("Tip"); //指定Layer
  137. }
  138. model.transform.SetParent(transform);
  139. model.transform.position = trgPos;
  140. model.transform.rotation = Quaternion.identity;
  141. model.transform.localScale = new Vector3(1, 1, 1);
  142. }
  143. }
  144. }