VideoControl.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. public string VideoURL;
  12. [Serializable]
  13. public class VideoInfo {
  14. public VideoClip video;
  15. public int index;
  16. }
  17. public List<VideoInfo> videoList;
  18. public void VideoStartSwitch() {
  19. isStart = videoPlayer.isPlaying;
  20. isStart = !isStart;
  21. Icon.SetActive(!isStart.Value);
  22. if(videoPlayer.url !=VideoURL)
  23. videoPlayer.url = VideoURL;
  24. if (isStart.Value) {
  25. videoPlayer?.Play();
  26. } else {
  27. videoPlayer?.Pause();
  28. }
  29. }
  30. public void PlayVideo(int index) {
  31. if(videoPlayer == null)
  32. return;
  33. foreach (var item in videoList) {
  34. if(item.index == index) {
  35. videoPlayer.clip = item.video;
  36. videoPlayer?.Play();
  37. Icon.SetActive(false);
  38. break;
  39. }
  40. }
  41. }
  42. }