PlayList.cs 2.4 KB

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