WindyAction.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System;
  2. using UnityEngine;
  3. public class WindyAction : BaseBehaviour
  4. {
  5. private void Awake()
  6. {
  7. this._anim = base.GetComponent<SpineAnimationController>();
  8. this._windyLocalPosition = base.transform.localPosition;
  9. this._windyLocalScale = base.transform.localScale;
  10. }
  11. private void Start()
  12. {
  13. this._anim.Play("Idle", true, false, 1f);
  14. }
  15. private void Update()
  16. {
  17. if (this._currentState == "Move" && this._currentV.magnitude < 0.3f)
  18. {
  19. this._anim.Play("Idle", true, false, 1f);
  20. }
  21. else if (this._currentState == "Idle" && this._currentV.magnitude >= 0.3f)
  22. {
  23. this._anim.Play("Move", true, false, 1f);
  24. }
  25. this.FollowPlayer();
  26. }
  27. private void FollowPlayer()
  28. {
  29. Vector3 localPosition = R.Player.Transform.localPosition;
  30. Vector3 a = localPosition + this.playerAnchorOffset;
  31. Vector3 vector = a - this._windyLocalPosition;
  32. if (Mathf.Abs(vector.x) > 0.5f || Mathf.Abs(vector.y) > 0.5f)
  33. {
  34. Vector3 target = a - new Vector3((float)this._faceDir * 0.5f * 1.2f, 0f, 0f);
  35. this._windyLocalPosition = Vector3.SmoothDamp(this._windyLocalPosition, target, ref this._currentV, 0.4f);
  36. base.transform.position = this._windyLocalPosition;
  37. }
  38. this.TurnRound(InputSetting.JudgeDir(this._windyLocalPosition, localPosition));
  39. }
  40. private void TurnRound(int dir)
  41. {
  42. if (this._faceDir != dir)
  43. {
  44. this._faceDir = dir;
  45. this._windyLocalScale.x = (float)(-(float)dir) * Mathf.Abs(this._windyLocalScale.x);
  46. base.transform.localScale = this._windyLocalScale;
  47. }
  48. }
  49. private const float SmoothTime = 0.4f;
  50. private const float FollowJudgeDistance = 0.5f;
  51. private readonly string _currentState = "Idle";
  52. private SpineAnimationController _anim;
  53. private Vector3 _currentV;
  54. private int _faceDir = -1;
  55. private Vector3 _windyLocalPosition;
  56. private Vector3 _windyLocalScale;
  57. [SerializeField]
  58. private Vector3 playerAnchorOffset;
  59. private static class State
  60. {
  61. public const string Move = "Move";
  62. public const string Idle = "Idle";
  63. public static readonly string[] StateArray = new string[]
  64. {
  65. "Move",
  66. "Idle"
  67. };
  68. }
  69. }