BladeGunAnimEvent.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. using System;
  2. using System.Collections;
  3. using LitJson;
  4. using UnityEngine;
  5. public class BladeGunAnimEvent : BaseBehaviour
  6. {
  7. private Transform player
  8. {
  9. get
  10. {
  11. return R.Player.Transform;
  12. }
  13. }
  14. private void Awake()
  15. {
  16. this._action = base.GetComponent<BladeGunAction>();
  17. this._eAttr = base.GetComponent<EnemyAttribute>();
  18. this._enemyAtk = base.GetComponentInChildren<EnemyAtk>();
  19. }
  20. private void Start()
  21. {
  22. this._jsonData = SingletonMono<EnemyDataPreload>.Instance.attack[EnemyType.霰弹利刃];
  23. }
  24. private void Update()
  25. {
  26. if (this._eAttr.isDead)
  27. {
  28. return;
  29. }
  30. if (this._eAttr.isFlyingUp)
  31. {
  32. bool flag = this.maxFlyHeight > 0f && this._eAttr.height >= this.maxFlyHeight;
  33. if (flag)
  34. {
  35. Vector2 currentSpeed = this._eAttr.timeController.GetCurrentSpeed();
  36. currentSpeed.y = 0f;
  37. this._eAttr.timeController.SetSpeed(currentSpeed);
  38. }
  39. if (this._eAttr.timeController.GetCurrentSpeed().y <= 0f)
  40. {
  41. this._eAttr.isFlyingUp = false;
  42. this._action.AnimChangeState(BladeGunAction.StateEnum.FlyToFall, 1f);
  43. }
  44. }
  45. if (this._eAttr.checkHitGround && this._eAttr.isOnGround)
  46. {
  47. this._eAttr.checkHitGround = false;
  48. R.Effect.Generate(6, base.transform, default(Vector3), default(Vector3), default(Vector3), true);
  49. if (this._action.stateMachine.currentState == "HitFall")
  50. {
  51. this.maxFlyHeight = 4f;
  52. this._eAttr.timeController.SetSpeed(Vector2.up * 25f);
  53. this._action.AnimChangeState(BladeGunAction.StateEnum.HitToFly1, 1f);
  54. }
  55. else
  56. {
  57. this._action.AnimChangeState(BladeGunAction.StateEnum.FallHitGround, 1f);
  58. }
  59. }
  60. }
  61. public void ChangeState(BladeGunAction.StateEnum sta)
  62. {
  63. this._action.AnimChangeState(sta.ToString(), 1f);
  64. }
  65. public void HitGround()
  66. {
  67. this._eAttr.checkHitGround = true;
  68. }
  69. public void FlyUp()
  70. {
  71. this._eAttr.isFlyingUp = true;
  72. }
  73. public void SetAtkData()
  74. {
  75. this._enemyAtk.atkData = this._jsonData[this._action.stateMachine.currentState];
  76. this.SetAtkId();
  77. }
  78. public void SetAtkId()
  79. {
  80. this._enemyAtk.atkId = Incrementor.GetNextId();
  81. }
  82. public void DestroySelf()
  83. {
  84. base.Invoke("RealDestroy", 2f);
  85. base.gameObject.SetActive(false);
  86. }
  87. private void RealDestroy()
  88. {
  89. UnityEngine.Object.Destroy(base.gameObject);
  90. }
  91. public void Shoot()
  92. {
  93. Transform transform = R.Effect.Generate(207, null, default(Vector3), default(Vector3), default(Vector3), true);
  94. EnemyBullet component = transform.GetComponent<EnemyBullet>();
  95. component.damage = this._eAttr.atk;
  96. component.origin = base.gameObject;
  97. transform.position = this.gunPos.position;
  98. component.SetAtkData(this._jsonData[this._action.stateMachine.currentState]);
  99. Vector2 from = this.gunPos.position - this.gunAssistant.position;
  100. float z = Mathf.Clamp(Vector2.Angle(from, new Vector2((float)this._eAttr.faceDir, 0f)), 0f, 90f);
  101. transform.localRotation = Quaternion.Euler(new Vector3(0f, (float)((this._eAttr.faceDir != 1) ? 180 : 0), z));
  102. }
  103. public IEnumerator TargetingPlayer()
  104. {
  105. float angle = Vector2.Angle(this.player.position - base.transform.position, Vector2.up);
  106. if (angle >= 30f)
  107. {
  108. this.gun.GetComponent<SkeletonUtilityBone>().mode = SkeletonUtilityBone.Mode.Override;
  109. Vector3 startEuler = this.gun.localEulerAngles;
  110. float targetAngle = Mathf.Clamp(angle + 90f, 120f, 180f);
  111. for (int i = 0; i < 30; i++)
  112. {
  113. this.gun.localEulerAngles = Vector3.Lerp(startEuler, new Vector3(0f, 0f, targetAngle), (float)i / 29f);
  114. yield return null;
  115. }
  116. }
  117. yield break;
  118. }
  119. public IEnumerator TargetRecover()
  120. {
  121. this.gun.GetComponent<SkeletonUtilityBone>().mode = SkeletonUtilityBone.Mode.Override;
  122. Vector3 startEuler = this.gun.localEulerAngles;
  123. for (int i = 0; i < 30; i++)
  124. {
  125. this.gun.localEulerAngles = Vector3.Lerp(startEuler, new Vector3(0f, 0f, 180f), (float)i / 29f);
  126. yield return null;
  127. }
  128. yield break;
  129. }
  130. public void PlaySound(int id)
  131. {
  132. R.Audio.PlayEffect(id, new Vector3?(base.transform.position));
  133. }
  134. public float maxFlyHeight;
  135. private BladeGunAction _action;
  136. private EnemyAttribute _eAttr;
  137. private JsonData _jsonData;
  138. [SerializeField]
  139. private Transform bullet;
  140. [SerializeField]
  141. private Transform gunPos;
  142. [SerializeField]
  143. private Transform gunAssistant;
  144. [SerializeField]
  145. private Transform gun;
  146. private EnemyAtk _enemyAtk;
  147. }