DaoPaoAnimEvent.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. using System;
  2. using System.Collections;
  3. using DatabaseModel;
  4. using LitJson;
  5. using OnionSkin;
  6. using UnityEngine;
  7. public class DaoPaoAnimEvent : BaseBehaviour
  8. {
  9. private Transform player
  10. {
  11. get
  12. {
  13. return R.Player.Transform;
  14. }
  15. }
  16. private void Start()
  17. {
  18. this._rollLoopTimes = 2;
  19. this._eAction = base.GetComponent<DaoPaoAction>();
  20. this._eAttr = base.GetComponent<EnemyAttribute>();
  21. this._atkData = SingletonMono<EnemyDataPreload>.Instance.attack[EnemyType.刀炮混合];
  22. this._onion = base.GetComponent<OnionCreator>();
  23. this._rigidbody2D = base.GetComponent<Rigidbody2D>();
  24. }
  25. private void Update()
  26. {
  27. if (this._eAttr.isDead)
  28. {
  29. return;
  30. }
  31. if (this._rollAttackFly && this._eAttr.isOnGround && this._rigidbody2D.velocity.y <= 0f)
  32. {
  33. this._rollAttackFly = false;
  34. this._eAction.AnimChangeState(DaoPaoAction.StateEnum.HitGround, 1f);
  35. }
  36. if (this._eAttr.isFlyingUp)
  37. {
  38. bool flag = this.maxFlyHeight > 0f && this._eAttr.height >= this.maxFlyHeight;
  39. if (flag)
  40. {
  41. Vector2 currentSpeed = this._eAttr.timeController.GetCurrentSpeed();
  42. currentSpeed.y = 0f;
  43. this._eAttr.timeController.SetSpeed(currentSpeed);
  44. }
  45. if (this._rigidbody2D.velocity.y <= 0f)
  46. {
  47. this._eAttr.isFlyingUp = false;
  48. this._eAction.AnimChangeState(DaoPaoAction.StateEnum.HitToFly3, 1f);
  49. }
  50. }
  51. if (this._eAttr.checkHitGround && this._eAttr.isOnGround)
  52. {
  53. this._eAttr.checkHitGround = false;
  54. R.Effect.Generate(6, base.transform, default(Vector3), default(Vector3), default(Vector3), true);
  55. if (this._eAction.stateMachine.currentState == "HitFall")
  56. {
  57. this.maxFlyHeight = 4f;
  58. this._eAttr.timeController.SetSpeed(Vector2.up * 25f);
  59. this._eAction.AnimChangeState(DaoPaoAction.StateEnum.HitToFly1, 1f);
  60. }
  61. else
  62. {
  63. this._eAction.AnimChangeState(DaoPaoAction.StateEnum.FallHitGround, 1f);
  64. }
  65. }
  66. }
  67. public void ChangeState(DaoPaoAction.StateEnum sta)
  68. {
  69. this._eAction.AnimChangeState(sta.ToString(), 1f);
  70. }
  71. public void PlaySound(int index)
  72. {
  73. R.Audio.PlayEffect(index, new Vector3?(base.transform.position));
  74. }
  75. public void PlayMoveSound()
  76. {
  77. R.Audio.PlayEffect(this.moveSound[UnityEngine.Random.Range(0, this.moveSound.Length)], new Vector3?(base.transform.position));
  78. }
  79. public void PlayHitGroundSound()
  80. {
  81. R.Audio.PlayEffect(this.hitGroundSound[UnityEngine.Random.Range(0, this.hitGroundSound.Length)], new Vector3?(base.transform.position));
  82. }
  83. public void RollStart()
  84. {
  85. if (this._rollOver)
  86. {
  87. this._rollOver = false;
  88. this._rollLoopTimes = 2;
  89. }
  90. }
  91. public void Atk2Start()
  92. {
  93. this._rollOver = true;
  94. this._eAttr.paBody = true;
  95. }
  96. public void RollOver()
  97. {
  98. this._rollLoopTimes--;
  99. if (this._rollLoopTimes <= 0)
  100. {
  101. if (this._eAction.stateMachine.currentState == "DaoAtk6_2" && UnityEngine.Random.Range(0, 100) < 50)
  102. {
  103. this._eAction.FaceToPlayer();
  104. this.atk.atkId = Incrementor.GetNextId();
  105. this._eAction.AnimChangeState(DaoPaoAction.StateEnum.DaoAtk4, 1f);
  106. }
  107. else
  108. {
  109. this._eAction.AnimChangeState(DaoPaoAction.StateEnum.Idle, 1f);
  110. }
  111. this._rollOver = true;
  112. }
  113. }
  114. public void Atk6_1Over()
  115. {
  116. if (UnityEngine.Random.Range(0, 100) < 50)
  117. {
  118. this._eAction.FaceToPlayer();
  119. this.atk.atkId = Incrementor.GetNextId();
  120. this._eAction.AnimChangeState(DaoPaoAction.StateEnum.DaoAtk6_2Ready, 1f);
  121. }
  122. else
  123. {
  124. this._eAction.AnimChangeState(DaoPaoAction.StateEnum.Idle, 1f);
  125. }
  126. }
  127. public void HitGround()
  128. {
  129. this._rollAttackFly = false;
  130. this._eAttr.checkHitGround = true;
  131. }
  132. public void FlyUp()
  133. {
  134. this._rollAttackFly = false;
  135. this._eAttr.isFlyingUp = true;
  136. }
  137. public void SetAtkData()
  138. {
  139. this.atk.atkData = this._atkData[this._eAction.stateMachine.currentState];
  140. }
  141. public void SwordFightStart()
  142. {
  143. this._rollAttackFly = true;
  144. }
  145. public void RunAwayEnd()
  146. {
  147. this.BackToIdle();
  148. if (!this._eAction.IsInNormalState())
  149. {
  150. return;
  151. }
  152. if (UnityEngine.Random.Range(0, 2) == 0)
  153. {
  154. int dir = InputSetting.JudgeDir(base.transform.position, this.player.position);
  155. this._eAction.Attack3(dir);
  156. }
  157. }
  158. public void GetUp()
  159. {
  160. if (this._eAttr.isDead)
  161. {
  162. this.DieBlock();
  163. this.DestroySelf();
  164. }
  165. else
  166. {
  167. this._eAction.AnimChangeState(DaoPaoAction.StateEnum.GetUp, 1f);
  168. }
  169. }
  170. public void BackToIdle()
  171. {
  172. if (this._eAction.IsInWeakSta())
  173. {
  174. this._eAttr.enterWeakMod = false;
  175. }
  176. this._eAction.AnimChangeState(DaoAction.StateEnum.Idle, 1f);
  177. }
  178. public void WeakOver()
  179. {
  180. if (!this._eAction.IsInWeakSta())
  181. {
  182. this._eAction.AnimChangeState(DaoPaoAction.StateEnum.Idle, 1f);
  183. }
  184. }
  185. public void DestroySelf()
  186. {
  187. this.RealDestroy();
  188. }
  189. private void RealDestroy()
  190. {
  191. UnityEngine.Object.Destroy(base.gameObject);
  192. }
  193. public void Shoot()
  194. {
  195. Transform transform = UnityEngine.Object.Instantiate<Transform>(this.bullet);
  196. EnemyBullet component = transform.GetComponent<EnemyBullet>();
  197. component.damage = this._eAttr.atk;
  198. component.origin = base.gameObject;
  199. transform.position = this.gunPos.position;
  200. Vector2 from = this.gunPos.position - this.gunAssistant.position;
  201. if (Vector2.Angle(from, Vector2.right) < 3f)
  202. {
  203. from = Vector2.right;
  204. }
  205. if (Vector2.Angle(from, -Vector2.right) < 3f)
  206. {
  207. from = -Vector2.right;
  208. }
  209. transform.GetComponent<Rigidbody2D>().velocity = from.normalized * 12f;
  210. component.SetAtkData(this._atkData["Bullet"]);
  211. }
  212. public IEnumerator TargetingPlayer()
  213. {
  214. float angle = Vector2.Angle(this.player.position + Vector3.up - base.transform.position, Vector2.up);
  215. if (angle >= 45f)
  216. {
  217. this.gun.GetComponent<SkeletonUtilityBone>().mode = SkeletonUtilityBone.Mode.Override;
  218. Vector3 startEuler = this.gun.localEulerAngles;
  219. float targetAngle = Mathf.Clamp(angle - 8f, 37f, 128f);
  220. for (int i = 0; i < 40; i++)
  221. {
  222. this.gun.localEulerAngles = Vector3.Lerp(startEuler, new Vector3(0f, 0f, targetAngle), (float)i / 39f);
  223. yield return null;
  224. }
  225. }
  226. yield break;
  227. }
  228. public IEnumerator TargetingRecover()
  229. {
  230. if (this.gun.GetComponent<SkeletonUtilityBone>().mode == SkeletonUtilityBone.Mode.Override)
  231. {
  232. Vector3 startEuler = this.gun.localEulerAngles;
  233. int clips = (int)(startEuler.z / 2f);
  234. if (clips > 1)
  235. {
  236. for (int i = 0; i < clips; i++)
  237. {
  238. this.gun.localEulerAngles = Vector3.Lerp(startEuler, new Vector3(0f, 0f, 80f), (float)i * 1f / (float)(clips - 1));
  239. yield return null;
  240. }
  241. }
  242. }
  243. this.gun.GetComponent<SkeletonUtilityBone>().mode = SkeletonUtilityBone.Mode.Follow;
  244. yield break;
  245. }
  246. public void PlayHitGroundEffect()
  247. {
  248. R.Effect.Generate(40, base.transform, Vector3.zero, new Vector3(0f, (float)(90 * this._eAttr.faceDir), 0f), default(Vector3), true);
  249. }
  250. public void DieBlock()
  251. {
  252. R.Effect.Generate(163, null, new Vector3(base.transform.position.x, base.transform.position.y, base.transform.position.z - 0.1f), Vector3.zero, default(Vector3), true);
  253. }
  254. public void ChargingDieEffect()
  255. {
  256. if (!R.Camera.IsInView(base.gameObject))
  257. {
  258. return;
  259. }
  260. GameObject prefab = CameraEffectProxyPrefabData.GetPrefab(9);
  261. UnityEngine.Object.Instantiate<GameObject>(prefab, this._eAttr.bounds.center, Quaternion.identity);
  262. }
  263. public void OpenOnion()
  264. {
  265. this._onion.Open(true, 0.7f, this.onionObj);
  266. }
  267. [SerializeField]
  268. private EnemyAtk atk;
  269. private JsonData _atkData;
  270. [SerializeField]
  271. private Transform bullet;
  272. private DaoPaoAction _eAction;
  273. private EnemyAttribute _eAttr;
  274. [SerializeField]
  275. private Transform gun;
  276. [SerializeField]
  277. private Transform gunAssistant;
  278. [SerializeField]
  279. private Transform gunPos;
  280. [SerializeField]
  281. private int[] hitGroundSound;
  282. public float maxFlyHeight;
  283. [SerializeField]
  284. private int[] moveSound;
  285. private OnionCreator _onion;
  286. [SerializeField]
  287. private GameObject[] onionObj;
  288. private bool _rollAttackFly;
  289. private int _rollLoopTimes;
  290. private bool _rollOver;
  291. private Rigidbody2D _rigidbody2D;
  292. }