FBBullet.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. using System;
  2. using GameWorld;
  3. using LitJson;
  4. using UnityEngine;
  5. public class FBBullet : BaseBehaviour
  6. {
  7. private bool isOnGround
  8. {
  9. get
  10. {
  11. RaycastHit2D hit = Physics2D.Raycast(base.transform.position, -Vector2.up, 0.36f, LayerManager.GroundMask);
  12. return hit;
  13. }
  14. }
  15. private void OnEnable()
  16. {
  17. if (this.normalBullet != null)
  18. {
  19. this.normalData = JsonMapper.ToObject(this.normalBullet);
  20. }
  21. this.atkId = Incrementor.GetNextId();
  22. }
  23. private void OnTriggerEnter2D(Collider2D other)
  24. {
  25. if (other.CompareTag("EnemyHurtBox") && this.canCollide(other))
  26. {
  27. this.EventTrigger(other.transform);
  28. if (!this.canThrough)
  29. {
  30. EffectController.TerminateEffect(base.gameObject);
  31. }
  32. if (this.enemyEffect != -1)
  33. {
  34. R.Effect.Generate(this.enemyEffect, null, other.bounds.center, default(Vector3), default(Vector3), true);
  35. }
  36. }
  37. if (other.CompareTag("EnemyBullet"))
  38. {
  39. EnemyBullet component = other.GetComponent<EnemyBullet>();
  40. EnemyBulletLaucher component2 = other.GetComponent<EnemyBulletLaucher>();
  41. if (component != null)
  42. {
  43. component.beAtked = true;
  44. R.Camera.Controller.CameraShake(0.166666672f, 0.2f, CameraController.ShakeTypeEnum.Rect, false);
  45. component.HitBullet();
  46. }
  47. else if (component2 != null)
  48. {
  49. component2.beAtked = true;
  50. R.Camera.Controller.CameraShake(0.166666672f, 0.2f, CameraController.ShakeTypeEnum.Rect, false);
  51. component2.HitBullet();
  52. }
  53. }
  54. }
  55. public void SetBulletData(JsonData data)
  56. {
  57. this.normalData = data;
  58. }
  59. private void Update()
  60. {
  61. if (this.isOnGround && this.groundEffect != -1 && this.firstHitGround)
  62. {
  63. this.firstHitGround = false;
  64. R.Effect.Generate(this.groundEffect, null, base.transform.position + new Vector3(0f, -0.4f, 0f), default(Vector3), default(Vector3), true);
  65. this.ExpandFunction();
  66. if (this.groundImmediatelyDisable)
  67. {
  68. this.Disable();
  69. }
  70. else
  71. {
  72. base.Invoke("Disable", this.groundDisableDelayTime);
  73. }
  74. }
  75. }
  76. public virtual void ExpandFunction()
  77. {
  78. }
  79. private void EventTrigger(Transform enemyBody)
  80. {
  81. HurtCheck component = enemyBody.GetComponent<HurtCheck>();
  82. HurtCheck.BodyType body = (!(component != null)) ? HurtCheck.BodyType.Body : component.bodyType;
  83. EnemyHurtAtkEventArgs args = new EnemyHurtAtkEventArgs(enemyBody.parent.gameObject, base.gameObject, this.atkId, enemyBody.GetComponent<Collider2D>().bounds.center, body, new EnemyHurtAtkEventArgs.PlayerNormalAtkData(this.normalData, true), false);
  84. EventManager.PostEvent<GameObject, EnemyHurtAtkEventArgs>("EnemyHurtAtk", base.gameObject, args);
  85. }
  86. private void Disable()
  87. {
  88. EffectController.TerminateEffect(base.gameObject);
  89. }
  90. private bool canCollide(Collider2D other)
  91. {
  92. return Vector3.Distance(other.transform.position, base.transform.position) < this.collsionDistance || Mathf.Abs(other.transform.position.x - base.transform.position.x) < this.collsionDistance;
  93. }
  94. public float collsionDistance = 3f;
  95. [SerializeField]
  96. private string normalBullet;
  97. [SerializeField]
  98. private bool canThrough;
  99. [SerializeField]
  100. private Transform pulse;
  101. [SerializeField]
  102. private int enemyEffect = -1;
  103. [SerializeField]
  104. private int groundEffect = -1;
  105. private JsonData normalData;
  106. private int atkId;
  107. [Header("在地面上立即消失")]
  108. public bool groundImmediatelyDisable = true;
  109. [Header("地面延时消失时间")]
  110. public float groundDisableDelayTime;
  111. public bool firstHitGround = true;
  112. }