Global Game Jam 2022
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.

168 lines
4.0 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using TMPro;
  6. using NaughtyAttributes;
  7. public class IntroController : MonoBehaviour, IResettable
  8. {
  9. [SerializeField]
  10. private TMP_Text m_levelText;
  11. [SerializeField]
  12. private TextMeshProUGUI m_detailsText;
  13. [SerializeField]
  14. private TextMeshProUGUI m_timerText;
  15. [SerializeField]
  16. private TextMeshProUGUI m_goText;
  17. [SerializeField]
  18. private Variables.Reference<bool> m_freezePlayer;
  19. [SerializeField]
  20. private LevelManager m_manager;
  21. [SerializeField]
  22. private Image m_backGround;
  23. [SerializeField, BoxGroup("Settings")]
  24. private float LevelFadeTime = 2;
  25. [SerializeField, BoxGroup("Settings")]
  26. private float Details1 = 1;
  27. [SerializeField, BoxGroup("Settings")]
  28. private float Details2 = 0.1f;
  29. [SerializeField, BoxGroup("Settings")]
  30. private float Details3 = 0.8f;
  31. [SerializeField, BoxGroup("Settings")]
  32. private float Fadetime = 1;
  33. [SerializeField, BoxGroup("Settings")]
  34. private float gotime = 0.5f;
  35. private IEnumerator Start()
  36. {
  37. m_backGround.gameObject.SetActive(true);
  38. m_timerText.gameObject.SetActive(false);
  39. m_levelText.text = m_manager.levelName;
  40. m_freezePlayer.Value = true;
  41. yield return StartCoroutine(LevelName(LevelFadeTime));
  42. yield return StartCoroutine(DetailText(Details1, Details2, Details3));
  43. yield return StartCoroutine(Fade(Fadetime));
  44. yield return StartCoroutine(Go(gotime));
  45. }
  46. private IEnumerator LevelName(float time)
  47. {
  48. m_levelText.gameObject.SetActive(true);
  49. float start = 0;
  50. float end = 1;
  51. float elaspedTime = 0;
  52. Color color = m_levelText.color;
  53. while (elaspedTime < time)
  54. {
  55. float alpha = Mathf.Sin(Mathf.PI * (elaspedTime / time));
  56. color.a = alpha;
  57. m_levelText.color = color;
  58. yield return new WaitForEndOfFrame();
  59. elaspedTime += Time.deltaTime;
  60. }
  61. color.a = 0;
  62. m_levelText.color = color;
  63. m_levelText.gameObject.SetActive(false);
  64. }
  65. private IEnumerator DetailText(float time,float time2, float time3)
  66. {
  67. m_timerText.gameObject.SetActive(true);
  68. yield return new WaitForSeconds(time);
  69. m_detailsText.gameObject.SetActive(true);
  70. m_detailsText.text = "\nSeconds\n\n";
  71. yield return new WaitForSeconds(time);
  72. foreach(char c in m_manager.levelPrompt)
  73. {
  74. m_detailsText.text += c;
  75. yield return new WaitForSeconds(time2);
  76. }
  77. yield return new WaitForSeconds(time3);
  78. }
  79. private IEnumerator Fade(float time)
  80. {
  81. float elaspedTime = 0;
  82. Color textColor = m_detailsText.color;
  83. Color backgroundColor = m_backGround.color;
  84. while (elaspedTime < time)
  85. {
  86. textColor.a = 1-(elaspedTime/time);
  87. backgroundColor.a = 1-(elaspedTime/time);
  88. m_backGround.color = backgroundColor;
  89. m_detailsText.color = textColor;
  90. yield return new WaitForEndOfFrame();
  91. elaspedTime+= Time.deltaTime;
  92. }
  93. textColor.a = 0;
  94. backgroundColor.a = 0;
  95. m_backGround.color = backgroundColor;
  96. m_detailsText.color = textColor;
  97. m_detailsText.gameObject.SetActive(false);
  98. m_backGround.gameObject.SetActive(false);
  99. }
  100. private IEnumerator Go(float time)
  101. {
  102. m_goText.gameObject.SetActive(true);
  103. yield return new WaitForSeconds(time);
  104. m_freezePlayer.Value = false;
  105. m_goText.gameObject.SetActive(false);
  106. }
  107. public void OnLevelLoad()
  108. {
  109. }
  110. public IEnumerator OnResetStart(float time)
  111. {
  112. yield return new WaitForSeconds(time - gotime);
  113. m_goText.gameObject.SetActive(true);
  114. yield return new WaitForSeconds(gotime);
  115. m_goText.gameObject.SetActive(false);
  116. }
  117. public void OnResetEnd()
  118. {
  119. }
  120. }