MonsterTrapBullet.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using Adon.Game.BO;
  2. using Adon.Game.Helper;
  3. using AdonGameKit;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. /// <summary>
  8. /// 怪物陷阱
  9. /// </summary>
  10. public class MonsterTrapBullet : MonoBehaviour
  11. {
  12. public float m_AttackAngle = 360;//攻击角度
  13. public float m_AttackSight = 0.8f;//攻击范围
  14. public string m_SkillID;
  15. private BaseMonsterAdon m_BaseMonsterAdon;
  16. bool isFire;
  17. float fireIntervalsTimer;
  18. float m_FireIntervalsTime = 1;
  19. float fireLifeTimer;
  20. float fireLife = 4;
  21. // Start is called before the first frame update
  22. void Start()
  23. {
  24. fireIntervalsTimer = m_FireIntervalsTime;
  25. }
  26. // Update is called once per frame
  27. void Update()
  28. {
  29. //先检测玩家是否进入范围
  30. ///检测范围内的英雄
  31. if (PlayerHelperAdon.GetNearEnemyHero(m_AttackSight, m_AttackAngle, gameObject) != null)
  32. {
  33. isFire = true;
  34. }
  35. else
  36. {
  37. isFire = false;
  38. }
  39. //if (m_BaseMonsterAdon.time == null)
  40. //{
  41. // return;
  42. //}
  43. fireLifeTimer += m_BaseMonsterAdon.time.deltaTime;
  44. if (fireLifeTimer >= fireLife) isFire = false;
  45. if (isFire)
  46. {
  47. //计时,周期发送伤害
  48. if (fireIntervalsTimer >= m_FireIntervalsTime)
  49. {
  50. fireIntervalsTimer = 0;
  51. ///检测范围内的英雄
  52. List<GameObject> heros = PlayerHelperAdon.GetNearEnemyHero(m_AttackSight, m_AttackAngle, gameObject);
  53. for (int i = 0; i < heros.Count; i++)
  54. {
  55. BaseHero component = heros[i].GetComponent<BaseHero>();
  56. //发送战斗信息,等待后台处理逻辑返回数据
  57. //X2Battle.X2BattleManager.Instance.mBulletModel.OnCastSkill(
  58. // m_BaseMonsterAdon.mData.UID, m_SkillID,
  59. // false, X2Battle.EBulletCastPoint.ECAST_POINT_DEFLUAT, component.mData.UID, false);
  60. BulletMessage.catSkillFun(m_BaseMonsterAdon.mData.UID, m_SkillID,
  61. false, (int)X2Battle.EBulletCastPoint.ECAST_POINT_DEFLUAT, component.mData.UID, false);
  62. //实例化克隆爆炸光效
  63. //Transform effobj = Instantiate(m_BombEff);
  64. //effobj.position = monster.m_HitObj.position;//设置爆炸位置
  65. //effobj.gameObject.SetActive(true);
  66. }
  67. }
  68. fireIntervalsTimer += m_BaseMonsterAdon.time.deltaTime;
  69. }
  70. }
  71. public void SetMonster(BaseMonsterAdon monster)
  72. {
  73. m_BaseMonsterAdon = monster;
  74. }
  75. #if UNITY_EDITOR
  76. /// <summary>
  77. /// 绘制打击配置
  78. /// </summary>
  79. private void OnDrawGizmosSelected()
  80. {
  81. Vector3 forward = transform.forward;
  82. UnityEditor.Handles.color = new Color(1.0f, 0.0f, 0.0f, 0.1f);
  83. Vector3 rotatedForward = Quaternion.Euler(0, -m_AttackAngle * 0.5f, 0) * transform.forward;
  84. UnityEditor.Handles.DrawSolidArc(transform.position, Vector3.up, rotatedForward, m_AttackAngle, m_AttackSight);
  85. }
  86. #endif
  87. }