EnemyBullet.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System;
  2. using GameWorld;
  3. using LitJson;
  4. using UnityEngine;
  5. public class EnemyBullet : BaseBehaviour
  6. {
  7. private bool _hitGround
  8. {
  9. get
  10. {
  11. return Physics2D.OverlapBox(base.transform.position, Vector2.one, 0f, LayerManager.WallMask | LayerManager.GroundMask | LayerManager.OneWayGroundMask | LayerManager.CeilingMask | LayerManager.ObstacleMask);
  12. }
  13. }
  14. private void OnEnable()
  15. {
  16. this.player = null;
  17. this.beAtked = false;
  18. }
  19. private void Update()
  20. {
  21. if (this._hitGround && !this.enableOnGround)
  22. {
  23. if (this.explosionEffect > 0)
  24. {
  25. R.Effect.Generate(this.explosionEffect, null, base.transform.position, default(Vector3), default(Vector3), true);
  26. }
  27. R.Audio.PlayEffect(UnityEngine.Random.Range(136, 139), new Vector3?(base.transform.position));
  28. EffectController.TerminateEffect(base.gameObject);
  29. }
  30. }
  31. private void OnTriggerEnter2D(Collider2D other)
  32. {
  33. if (other.name == "PlayerHurtBox")
  34. {
  35. PlayerHurtAtkEventArgs args = new PlayerHurtAtkEventArgs(other.transform.parent.gameObject, base.gameObject, this.origin, this.damage, Incrementor.GetNextId(), this.atkData, false);
  36. EventManager.PostEvent<Transform, PlayerHurtAtkEventArgs>("PlayerHurtAtk", base.transform, args);
  37. if (this.hitAudio > 0)
  38. {
  39. R.Audio.PlayEffect(this.hitAudio, new Vector3?(base.transform.position));
  40. }
  41. if (!this.beAtked && this.type == EnemyBullet.BUlletType.Once)
  42. {
  43. this.player = other.transform.parent;
  44. this.HitBullet();
  45. }
  46. if (this.type == EnemyBullet.BUlletType.Stay)
  47. {
  48. UnityEngine.Object.Destroy(base.GetComponent<Collider2D>());
  49. }
  50. }
  51. }
  52. public void HitBullet()
  53. {
  54. if (this.beAtked)
  55. {
  56. if (this.explosionEffect > 0)
  57. {
  58. R.Effect.Generate(this.explosionEffect, null, base.transform.position, default(Vector3), default(Vector3), true);
  59. }
  60. R.Effect.Generate(49, null, base.transform.position, default(Vector3), default(Vector3), true);
  61. R.Audio.PlayEffect(UnityEngine.Random.Range(136, 139), new Vector3?(base.transform.position));
  62. }
  63. if (this.player)
  64. {
  65. if (this.explosionEffect > 0)
  66. {
  67. R.Effect.Generate(this.explosionEffect, null, new Vector3((base.transform.position.x + this.player.position.x) / 2f, base.transform.position.y, base.transform.position.z), default(Vector3), default(Vector3), true);
  68. }
  69. R.Audio.PlayEffect(UnityEngine.Random.Range(136, 139), new Vector3?(base.transform.position));
  70. }
  71. EffectController.TerminateEffect(base.gameObject);
  72. }
  73. private void OnDisable()
  74. {
  75. if (this.missAudio > 0)
  76. {
  77. R.Audio.PlayEffect(this.missAudio, new Vector3?(base.transform.position));
  78. }
  79. }
  80. public void SetAtkData(JsonData jsonData)
  81. {
  82. this.atkData = jsonData;
  83. }
  84. private Transform player;
  85. public bool beAtked;
  86. public int damage;
  87. public JsonData atkData;
  88. [HideInInspector]
  89. public GameObject origin;
  90. [SerializeField]
  91. public int explosionEffect = 90;
  92. [SerializeField]
  93. private bool enableOnGround;
  94. public EnemyBullet.BUlletType type;
  95. public EnemyType EnemyTypeOfShooter;
  96. public int hitAudio;
  97. public int missAudio;
  98. public enum BUlletType
  99. {
  100. Once,
  101. Stay,
  102. Continue
  103. }
  104. }