TimeController.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. using System;
  2. using UnityEngine;
  3. public class TimeController : BaseBehaviour, IPlatformPhysics
  4. {
  5. private void Awake()
  6. {
  7. this.animControl = base.GetComponent<SpineAnimationController>();
  8. this.rigid = base.GetComponent<Rigidbody2D>();
  9. this.eAttr = base.GetComponent<EnemyAttribute>();
  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. public Vector2 GetCurrentSpeed()
  30. {
  31. Vector2? vector = this.currentSpeed;
  32. return (vector == null) ? this.rigid.velocity : vector.Value;
  33. }
  34. private void FixedUpdate()
  35. {
  36. if (this.isPause)
  37. {
  38. return;
  39. }
  40. Vector2? vector = this.currentSpeed;
  41. if (vector != null)
  42. {
  43. this.rigid.velocity = this.currentSpeed.Value;
  44. this.currentSpeed = null;
  45. }
  46. float? num = this.currentGravity;
  47. if (num != null)
  48. {
  49. this.rigid.gravityScale = this.currentGravity.Value;
  50. this.currentGravity = null;
  51. }
  52. }
  53. public void SetSpeed(Vector2 speed)
  54. {
  55. if (this.isPause)
  56. {
  57. this.currentSpeed = new Vector2?(speed);
  58. }
  59. else
  60. {
  61. this.rigid.velocity = speed;
  62. }
  63. }
  64. public void SetGravity(float scale)
  65. {
  66. if (this.isPause)
  67. {
  68. this.currentGravity = new float?(scale);
  69. }
  70. else
  71. {
  72. this.rigid.gravityScale = scale;
  73. }
  74. }
  75. private void ClipFrozen(object obj, WorldTime.FrozenArgs e)
  76. {
  77. if (e.Type == WorldTime.FrozenArgs.FrozenType.Player)
  78. {
  79. return;
  80. }
  81. if (e.Type == WorldTime.FrozenArgs.FrozenType.Target && base.gameObject != e.Target)
  82. {
  83. return;
  84. }
  85. if (this.isPause)
  86. {
  87. return;
  88. }
  89. this.isPause = true;
  90. this.currentSpeed = new Vector2?(this.rigid.velocity);
  91. this.currentGravity = new float?(this.rigid.gravityScale);
  92. this.rigid.gravityScale = 0f;
  93. this.rigid.velocity = Vector2.zero;
  94. this.animControl.Pause();
  95. }
  96. private void ClipResume(object obj, WorldTime.FrozenArgs e)
  97. {
  98. if (!this.isPause)
  99. {
  100. return;
  101. }
  102. this.animControl.Resume();
  103. this.isPause = false;
  104. }
  105. public Vector2 velocity
  106. {
  107. get
  108. {
  109. return this.GetCurrentSpeed();
  110. }
  111. set
  112. {
  113. this.SetSpeed(value);
  114. }
  115. }
  116. public Vector2 position
  117. {
  118. get
  119. {
  120. return this.rigid.position;
  121. }
  122. set
  123. {
  124. this.rigid.position = value;
  125. }
  126. }
  127. public bool isOnGround
  128. {
  129. get
  130. {
  131. return this.eAttr.isOnGround;
  132. }
  133. }
  134. public float? currentGravity;
  135. public Vector2? currentSpeed;
  136. [SerializeField]
  137. public bool isPause;
  138. private EnemyAttribute eAttr;
  139. private Rigidbody2D rigid;
  140. private SpineAnimationController animControl;
  141. private Vector2? nextSpeed;
  142. }