PlayerTimeController.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. using System;
  2. using UnityEngine;
  3. public class PlayerTimeController : BaseBehaviour, IPlatformPhysics
  4. {
  5. private void Start()
  6. {
  7. this.animControl = base.GetComponent<MultiSpineAnimationController>();
  8. this.platform = base.GetComponent<PlatformMovement>();
  9. this.pAttr = R.Player.Attribute;
  10. }
  11. private void OnEnable()
  12. {
  13. if (SingletonMono<WorldTime>.ApplicationIsQuitting)
  14. {
  15. return;
  16. }
  17. SingletonMono<WorldTime>.Instance.FrozenEvent += this.ClipFrozen;
  18. SingletonMono<WorldTime>.Instance.ResumeEvent += this.ClipResume;
  19. }
  20. private void OnDisable()
  21. {
  22. if (SingletonMono<WorldTime>.ApplicationIsQuitting)
  23. {
  24. return;
  25. }
  26. SingletonMono<WorldTime>.Instance.FrozenEvent -= this.ClipFrozen;
  27. SingletonMono<WorldTime>.Instance.ResumeEvent -= this.ClipResume;
  28. }
  29. private void OnDestroy()
  30. {
  31. }
  32. public Vector2 GetCurrentSpeed()
  33. {
  34. Vector2? vector = this.currentSpeed;
  35. return (vector == null) ? this.platform.velocity : vector.Value;
  36. }
  37. private void FixedUpdate()
  38. {
  39. if (this.isPause)
  40. {
  41. return;
  42. }
  43. Vector2? vector = this.currentSpeed;
  44. if (vector != null)
  45. {
  46. this.platform.velocity = this.currentSpeed.Value;
  47. this.currentSpeed = null;
  48. }
  49. }
  50. public void SetSpeed(Vector2 speed)
  51. {
  52. if (this.isPause)
  53. {
  54. this.currentSpeed = new Vector2?(speed);
  55. }
  56. else
  57. {
  58. this.platform.velocity = speed;
  59. }
  60. }
  61. public void NextPosition(Vector3 nextPos)
  62. {
  63. this.platform.position = nextPos;
  64. }
  65. private void ClipFrozen(object obj, WorldTime.FrozenArgs e)
  66. {
  67. if (e.Type == WorldTime.FrozenArgs.FrozenType.Enemy)
  68. {
  69. return;
  70. }
  71. if (e.Type == WorldTime.FrozenArgs.FrozenType.Target && base.gameObject != e.Target)
  72. {
  73. return;
  74. }
  75. if (this.isPause)
  76. {
  77. return;
  78. }
  79. this.isPause = true;
  80. this.currentSpeed = new Vector2?(this.platform.velocity);
  81. this.platform.velocity = Vector2.zero;
  82. this.platform.isKinematic = true;
  83. this.animControl.Pause();
  84. }
  85. private void ClipResume(object obj, WorldTime.FrozenArgs e)
  86. {
  87. if (e.Type == WorldTime.FrozenArgs.FrozenType.Enemy)
  88. {
  89. return;
  90. }
  91. if (e.Type == WorldTime.FrozenArgs.FrozenType.Target && base.gameObject != e.Target)
  92. {
  93. return;
  94. }
  95. if (!this.isPause)
  96. {
  97. return;
  98. }
  99. this.platform.isKinematic = false;
  100. this.animControl.Resume();
  101. this.isPause = false;
  102. }
  103. public Vector2 velocity
  104. {
  105. get
  106. {
  107. return this.GetCurrentSpeed();
  108. }
  109. set
  110. {
  111. this.SetSpeed(value);
  112. }
  113. }
  114. public Vector2 position
  115. {
  116. get
  117. {
  118. return this.platform.position;
  119. }
  120. set
  121. {
  122. this.platform.position = value;
  123. }
  124. }
  125. public bool isOnGround
  126. {
  127. get
  128. {
  129. return this.pAttr.isOnGround;
  130. }
  131. }
  132. private MultiSpineAnimationController animControl;
  133. private Vector2? currentSpeed;
  134. [SerializeField]
  135. public bool isPause;
  136. private PlatformMovement platform;
  137. private PlayerAttribute pAttr;
  138. private Vector2? nextSpeed;
  139. }