You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

90 lines
1.9 KiB

  1. using System;
  2. using System.Collections;
  3. using SUISS.Core;
  4. using UnityEngine;
  5. public class CinematicEffect : SingletonMonobehaviour<CinematicEffect>
  6. {
  7. protected override void Awake()
  8. {
  9. base.Awake();
  10. this.HideInstant();
  11. }
  12. public Coroutine ShowAnimated()
  13. {
  14. this.StopCurrentRoutine();
  15. return base.StartCoroutine(this._fadeRoutine = this.ShowRoutine());
  16. }
  17. public Coroutine HideAnimated()
  18. {
  19. this.StopCurrentRoutine();
  20. return base.StartCoroutine(this._fadeRoutine = this.HideRoutine());
  21. }
  22. public void ShowInstant()
  23. {
  24. this.StopCurrentRoutine();
  25. this._camera.enabled = true;
  26. this._canvasGroup.alpha = 1f;
  27. }
  28. public void HideInstant()
  29. {
  30. this.StopCurrentRoutine();
  31. this._camera.enabled = false;
  32. this._canvasGroup.alpha = 0f;
  33. }
  34. private IEnumerator ShowRoutine()
  35. {
  36. this._camera.enabled = true;
  37. this._canvasGroup.alpha = 0f;
  38. float time = 0f;
  39. while (time < this._fadeDurationInSeconds)
  40. {
  41. time += Time.deltaTime;
  42. this._canvasGroup.alpha = this._fadeCurve.Evaluate(time / this._fadeDurationInSeconds);
  43. yield return null;
  44. }
  45. yield break;
  46. }
  47. private IEnumerator HideRoutine()
  48. {
  49. this._canvasGroup.alpha = 1f;
  50. float time = this._fadeDurationInSeconds;
  51. while (time > 0f)
  52. {
  53. time -= Time.deltaTime;
  54. this._canvasGroup.alpha = this._fadeCurve.Evaluate(time / this._fadeDurationInSeconds);
  55. yield return null;
  56. }
  57. this._camera.enabled = false;
  58. yield break;
  59. }
  60. private void StopCurrentRoutine()
  61. {
  62. if (this._fadeRoutine != null)
  63. {
  64. base.StopCoroutine(this._fadeRoutine);
  65. }
  66. }
  67. [SerializeField]
  68. private Camera _camera;
  69. [SerializeField]
  70. private CanvasGroup _canvasGroup;
  71. [SerializeField]
  72. private AnimationCurve _fadeCurve = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f);
  73. [SerializeField]
  74. private float _fadeDurationInSeconds = 0.7f;
  75. private IEnumerator _fadeRoutine;
  76. }