VideoControl.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Video;
  5. using System;
  6. public class VideoControl : MonoBehaviour {
  7. public GameObject Icon;
  8. public Material material;
  9. bool? isStart = true;
  10. public VideoPlayer videoPlayer;
  11. [Serializable]
  12. public class VideoInfo {
  13. public VideoClip video;
  14. public int index;
  15. }
  16. public List<VideoInfo> videoList;
  17. public void VideoStartSwitch() {
  18. isStart = videoPlayer.isPlaying;
  19. isStart = !isStart;
  20. Icon.SetActive(!isStart.Value);
  21. if(isStart.Value) {
  22. videoPlayer?.Play();
  23. } else {
  24. videoPlayer?.Pause();
  25. }
  26. }
  27. public void PlayVideo(int index) {
  28. if(videoPlayer == null)
  29. return;
  30. foreach(var item in videoList) {
  31. if(item.index == index) {
  32. videoPlayer.clip = item.video;
  33. videoPlayer?.Play();
  34. Icon.SetActive(false);
  35. break;
  36. }
  37. }
  38. }
  39. }