PlayList.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.InputSystem;
  5. using UnityEngine.UI;
  6. using System;
  7. public class PlayList : MonoBehaviour
  8. {
  9. public GameObject[] playListObjects1;
  10. public GameObject[] playListObjects;
  11. /// <summary>
  12. /// 等待时间
  13. /// </summary>
  14. private float waitTime;
  15. /// <summary>
  16. /// 答案数据
  17. /// </summary>
  18. [Header("答案数据")]
  19. public List<bool> saveData;
  20. private void Awake()
  21. {
  22. DateTime now = DateTime.Now;
  23. DateTime startTime = new DateTime(2024, 1, 30);
  24. Debug.Log(startTime.Subtract(now).Days);
  25. }
  26. private void Start()
  27. {
  28. //StartPlayState2();
  29. }
  30. /// <summary>
  31. /// 跳过
  32. /// </summary>
  33. public void Skip()
  34. {
  35. waitTime = 0.5f;
  36. }
  37. /// <summary>
  38. /// 停止并退出当前课程
  39. /// </summary>
  40. public void StopAll()
  41. {
  42. StopAllCoroutines();
  43. for (int i = 0; i < playListObjects1.Length; i++)
  44. {
  45. playListObjects1[i].gameObject.SetActive(false);
  46. }
  47. for (int i = 0; i < playListObjects.Length; i++)
  48. {
  49. playListObjects[i].gameObject.SetActive(false);
  50. }
  51. gameObject.SetActive(false);
  52. }
  53. /// <summary>
  54. /// 播放课堂行为管理
  55. /// </summary>
  56. public void StartPlayState1()
  57. {
  58. gameObject.SetActive(true);
  59. saveData = new List<bool>();
  60. StartCoroutine(StartPlayState2Coroutine(playListObjects1));
  61. }
  62. /// <summary>
  63. /// 播放高级认知提问
  64. /// </summary>
  65. public void StartPlayState2()
  66. {
  67. gameObject.SetActive(true);
  68. saveData = new List<bool>();
  69. StartCoroutine(StartPlayState2Coroutine(playListObjects));
  70. }
  71. private IEnumerator StartPlayState2Coroutine(GameObject[] objects)
  72. {
  73. for (int i = 0; i < objects.Length; i++)
  74. {
  75. yield return StartCoroutine(WaitTime(objects[i]));
  76. }
  77. }
  78. private IEnumerator WaitTime(GameObject obj)
  79. {
  80. obj.SetActive(true);
  81. SelectPrefab selectPrefab = obj.GetComponent<SelectPrefab>();
  82. if (selectPrefab == null)
  83. {
  84. waitTime = obj.GetComponent<AudioSource>().clip.length + 1;
  85. }
  86. else
  87. {
  88. waitTime = 9999999;
  89. selectPrefab.SelectPrefabCreateInit((bool value) =>
  90. {
  91. saveData.Add(value);
  92. waitTime = 0;
  93. });
  94. }
  95. while (waitTime > 0)
  96. {
  97. waitTime -= Time.deltaTime;
  98. yield return null;
  99. }
  100. obj.SetActive(false);
  101. }
  102. }
粤ICP备19079148号