AnimatorFrozen.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using UnityEngine;
  3. public class AnimatorFrozen : BaseBehaviour
  4. {
  5. private void Start()
  6. {
  7. }
  8. private void OnEnable()
  9. {
  10. if (SingletonMono<WorldTime>.Instance != null)
  11. {
  12. SingletonMono<WorldTime>.Instance.FrozenEvent += new EventHandler<WorldTime.FrozenArgs>(this.ClipFrozen);
  13. SingletonMono<WorldTime>.Instance.ResumeEvent += new EventHandler<WorldTime.FrozenArgs>(this.ClipResume);
  14. }
  15. }
  16. private void Update()
  17. {
  18. }
  19. private void OnDisable()
  20. {
  21. if (SingletonMono<WorldTime>.Instance != null)
  22. {
  23. SingletonMono<WorldTime>.Instance.FrozenEvent -= new EventHandler<WorldTime.FrozenArgs>(this.ClipFrozen);
  24. SingletonMono<WorldTime>.Instance.ResumeEvent -= new EventHandler<WorldTime.FrozenArgs>(this.ClipResume);
  25. }
  26. }
  27. private void ClipFrozen(object obj, EventArgs e)
  28. {
  29. if (this.isPause)
  30. {
  31. return;
  32. }
  33. this.anim.speed = 0f;
  34. this.isPause = true;
  35. }
  36. private void ClipResume(object obj = null, EventArgs e = null)
  37. {
  38. if (!this.isPause)
  39. {
  40. return;
  41. }
  42. this.anim.speed = 1f;
  43. this.isPause = false;
  44. }
  45. [SerializeField]
  46. private Animator anim;
  47. [SerializeField]
  48. public bool isPause;
  49. }