ShadeAttackChase.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. using LitJson;
  3. using UnityEngine;
  4. public class ShadeAttackChase : BaseBehaviour
  5. {
  6. private float height
  7. {
  8. get
  9. {
  10. return Physics2D.Raycast(base.transform.position, Vector2.up * -1f, 100f, LayerManager.GroundMask | LayerManager.OneWayGroundMask).distance;
  11. }
  12. }
  13. private void Awake()
  14. {
  15. this.skeletonAnim = base.GetComponent<SkeletonAnimation>();
  16. this.jsonData = JsonMapper.ToObject(this.data.text);
  17. base.GetComponentInChildren<PlayerAtk>().SetData(this.jsonData["AirAtk7"], Incrementor.GetNextId());
  18. }
  19. private void OnEnable()
  20. {
  21. this.skeletonAnim.state.SetAnimation(0, this.GetAnim(), false);
  22. if (this.height >= 0.5f)
  23. {
  24. Vector3 euler = new Vector3(0f, 0f, UnityEngine.Random.Range(-30f, 30f));
  25. base.transform.localRotation = Quaternion.Euler(euler);
  26. }
  27. R.Audio.PlayEffect(200, new Vector3?(base.transform.position));
  28. }
  29. private void OnDisable()
  30. {
  31. this.skeletonAnim.Reset();
  32. }
  33. private string GetAnim()
  34. {
  35. if (this.height >= 0.5f)
  36. {
  37. return this.airAnim[UnityEngine.Random.Range(0, this.airAnim.Length)];
  38. }
  39. return this.groundAnim[UnityEngine.Random.Range(0, this.groundAnim.Length)];
  40. }
  41. private SkeletonAnimation skeletonAnim;
  42. [SerializeField]
  43. private TextAsset data;
  44. private JsonData jsonData;
  45. private string[] airAnim = new string[]
  46. {
  47. "ToLeft",
  48. "ToLeftAir"
  49. };
  50. private string[] groundAnim = new string[]
  51. {
  52. "Down",
  53. "Down2",
  54. "ToLeftGround",
  55. "ToLeftGround2"
  56. };
  57. }