VideoControl.cs 1.3 KB

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