Rotator.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using System;
  2. using CIS;
  3. using UnityEngine;
  4. public class Rotator : MonoBehaviour, ILevelItem
  5. {
  6. private void Awake()
  7. {
  8. this.myTrans = base.transform;
  9. this.initQuat = this.myTrans.rotation;
  10. this.triggered = true;
  11. if (this.needDoorTrigger || this.needAreaTrigger)
  12. {
  13. this.triggered = false;
  14. }
  15. this.originalDirection = this.direction;
  16. }
  17. public void OnReset()
  18. {
  19. if (!this.needReset)
  20. {
  21. return;
  22. }
  23. this.direction = this.originalDirection;
  24. this.myTrans.rotation = this.initQuat;
  25. this.triggered = true;
  26. if (this.needDoorTrigger || this.needAreaTrigger)
  27. {
  28. this.triggered = false;
  29. }
  30. }
  31. public void OnPause(bool isPause)
  32. {
  33. }
  34. private void Update()
  35. {
  36. if (SingletonMonoBehaviourClass<GameLogicMgr>.instance != null && SingletonMonoBehaviourClass<GameLogicMgr>.instance.IsPause())
  37. {
  38. return;
  39. }
  40. if (!this.triggered)
  41. {
  42. return;
  43. }
  44. float z = this.myTrans.rotation.eulerAngles.z;
  45. this.myTrans.rotation = Quaternion.Euler(0f, 0f, z + (float)this.direction * this.speed * SingletonMonoBehaviourClass<TimeMgr>.instance.deltaTime);
  46. }
  47. public void OnAreaTriggerEnter(Collider2D coll)
  48. {
  49. if (coll.CompareTag("Player"))
  50. {
  51. this.triggered = true;
  52. }
  53. }
  54. public void OnAreaTriggerExit(Collider2D coll)
  55. {
  56. }
  57. public void OnActive(int index)
  58. {
  59. this.triggered = true;
  60. }
  61. public void OnEntertBlock(ILevelBlock block)
  62. {
  63. }
  64. public void OnLeaveBlock(ILevelBlock block)
  65. {
  66. }
  67. public void OnPickingTime(float time)
  68. {
  69. }
  70. public float speed;
  71. public int direction = 1;
  72. public bool needReset;
  73. public bool needAreaTrigger;
  74. public bool needDoorTrigger;
  75. private Transform myTrans;
  76. private Quaternion initQuat;
  77. private int originalDirection;
  78. private bool triggered = true;
  79. }