BladeGunAction.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. using System;
  2. using System.Collections.Generic;
  3. using ExtensionMethods;
  4. using UnityEngine;
  5. public class BladeGunAction : EnemyBaseAction
  6. {
  7. static Dictionary<string, int> _003C_003Ef__switch_0024mapC;
  8. protected override void Start()
  9. {
  10. this.stateMachine.AddStates(typeof(BladeGunAction.StateEnum));
  11. this.stateMachine.OnEnter += this.OnMyStateEnter;
  12. this.stateMachine.OnTransfer += this.OnStateTransfer;
  13. base.AnimChangeState(BladeGunAction.StateEnum.Idle, 1f);
  14. }
  15. private void FixedUpdate()
  16. {
  17. if (this.stateMachine.currentState != "FlyToFall")
  18. {
  19. return;
  20. }
  21. Vector2 currentSpeed = this.eAttr.timeController.GetCurrentSpeed();
  22. float f = currentSpeed.x;
  23. f = Mathf.Clamp(Mathf.Abs(f) - this.airFric * Time.fixedDeltaTime, 0f, float.MaxValue) * Mathf.Sign(f);
  24. currentSpeed.x = Mathf.Clamp(Mathf.Abs(f) - this.airFric * Time.fixedDeltaTime, 0f, float.PositiveInfinity) * Mathf.Sign(f);
  25. this.eAttr.timeController.SetSpeed(currentSpeed);
  26. }
  27. private void OnStateTransfer(object sender, StateMachine.TransferEventArgs args)
  28. {
  29. this.gun.mode = SkeletonUtilityBone.Mode.Follow;
  30. if (args.nextState == "FlyToFall")
  31. {
  32. Vector2 currentSpeed = this.eAttr.timeController.GetCurrentSpeed();
  33. currentSpeed.y = 0f;
  34. this.eAttr.timeController.SetSpeed(currentSpeed);
  35. this.eAttr.timeController.SetGravity(0f);
  36. }
  37. if (args.lastState == "FlyToFall" && !this.eAttr.willBeExecute)
  38. {
  39. this.eAttr.timeController.SetGravity(1f);
  40. }
  41. if (args.nextState == "Atk1")
  42. {
  43. this.eAttr.paBody = true;
  44. }
  45. if (args.lastState == "Atk1")
  46. {
  47. this.eAttr.paBody = false;
  48. }
  49. }
  50. private void OnMyStateEnter(object sender, StateMachine.StateEventArgs args)
  51. {
  52. string state = args.state;
  53. if (state != null)
  54. {
  55. if (BladeGunAction._003C_003Ef__switch_0024mapC == null)
  56. {
  57. BladeGunAction._003C_003Ef__switch_0024mapC = new Dictionary<string, int>(14)
  58. {
  59. {
  60. "Atk1End",
  61. 0
  62. },
  63. {
  64. "Atk1Ready",
  65. 0
  66. },
  67. {
  68. "Atk2",
  69. 0
  70. },
  71. {
  72. "Die",
  73. 0
  74. },
  75. {
  76. "FallHitGround",
  77. 0
  78. },
  79. {
  80. "FlyToFall",
  81. 0
  82. },
  83. {
  84. "Hit1",
  85. 0
  86. },
  87. {
  88. "HitToFly1",
  89. 0
  90. },
  91. {
  92. "Warning",
  93. 0
  94. },
  95. {
  96. "Fall",
  97. 1
  98. },
  99. {
  100. "HitFall",
  101. 1
  102. },
  103. {
  104. "HitToFly2",
  105. 1
  106. },
  107. {
  108. "Atk1",
  109. 1
  110. },
  111. {
  112. "Idle",
  113. 1
  114. }
  115. };
  116. }
  117. int num;
  118. if (BladeGunAction._003C_003Ef__switch_0024mapC.TryGetValue(state, out num))
  119. {
  120. if (num != 0)
  121. {
  122. if (num == 1)
  123. {
  124. this.spineAnim.Play(args.state, true, false, 1f);
  125. }
  126. }
  127. else
  128. {
  129. this.spineAnim.Play(args.state, false, true, 1f);
  130. }
  131. }
  132. }
  133. }
  134. public override void AnimMove()
  135. {
  136. if (this.stateMachine.currentState != "Atk1Ready" && this.stateMachine.currentState != "Atk1")
  137. {
  138. base.AnimChangeState(BladeGunAction.StateEnum.Atk1Ready, 1f);
  139. }
  140. else if (this.stateMachine.currentState == "Atk1")
  141. {
  142. base.AnimChangeState(BladeGunAction.StateEnum.Atk1, 1f);
  143. }
  144. }
  145. public override void Attack2(int dir)
  146. {
  147. if (this.eAttr.isDead)
  148. {
  149. return;
  150. }
  151. if (!this.IsInNormalState())
  152. {
  153. return;
  154. }
  155. base.ChangeFace(dir);
  156. base.AnimChangeState(BladeGunAction.StateEnum.Atk2, 1f);
  157. }
  158. public override void AnimReady()
  159. {
  160. base.AnimChangeState(BladeGunAction.StateEnum.Atk1End, 1f);
  161. }
  162. public override bool IsInNormalState()
  163. {
  164. return this.stateMachine.currentState.IsInArray(BladeGunAction.NormalSta) && base.IsInNormalState();
  165. }
  166. public override bool IsInAttackState()
  167. {
  168. return this.stateMachine.currentState == "Atk2";
  169. }
  170. public override bool IsInDeadState(string state)
  171. {
  172. return state == "Die";
  173. }
  174. public override bool IsInWeakSta()
  175. {
  176. return this.eAttr.inWeakState;
  177. }
  178. public override bool IsInIdle()
  179. {
  180. return this.stateMachine.currentState == "Idle";
  181. }
  182. protected override bool EnterAtkSta(string lastState, string nextState)
  183. {
  184. return nextState == "Atk2" && lastState != "Atk2";
  185. }
  186. protected override bool ExitAtkSta(string lastState, string nextState)
  187. {
  188. return nextState != "Atk2" && lastState == "Atk2";
  189. }
  190. public float airFric = 8f;
  191. [SerializeField]
  192. private SkeletonUtilityBone gun;
  193. private static readonly string[] NormalSta = new string[]
  194. {
  195. "Idle",
  196. "Atk1Ready",
  197. "Atk1",
  198. "Atk1End",
  199. "Warning"
  200. };
  201. public enum StateEnum
  202. {
  203. Idle,
  204. Atk1Ready,
  205. Atk1,
  206. Atk1End,
  207. Atk2,
  208. Die,
  209. Fall,
  210. FallHitGround,
  211. FlyToFall,
  212. Hit1,
  213. HitToFly1,
  214. HitToFly2,
  215. Warning,
  216. HitFall
  217. }
  218. public enum HurtSta
  219. {
  220. Fall,
  221. FallHitGround,
  222. FlyToFall,
  223. Hit1,
  224. HitToFly1,
  225. HitToFly2,
  226. HitFall
  227. }
  228. }