VideoManager.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using GameFramework.Event;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using UnityEngine.Video;
  7. public class VideoManager : MonoBehaviour
  8. {
  9. public VideoManager _Instance { get; private set; }
  10. private VideoPlayer videoPlayer;
  11. private void Awake()
  12. {
  13. _Instance = this;
  14. videoPlayer = this.GetComponent<VideoPlayer>();
  15. }
  16. private void Start()
  17. {
  18. GameMain.Event.Subscribe(PlayerVideoEvent.EventId, OnDealPlayEvent);
  19. }
  20. private void OnDealPlayEvent(object sender, GameEventArgs e)
  21. {
  22. PlayerVideoEvent args = (PlayerVideoEvent)e;
  23. bool play = args.play;
  24. if (play)
  25. {
  26. var tempForm = (BaseStudyForm)sender;
  27. tempForm.SetTVFrame(videoPlayer.targetTexture);
  28. BeginPlay();
  29. }
  30. else
  31. {
  32. StopPlay();
  33. }
  34. }
  35. private void OnDestroy()
  36. {
  37. if (GameMain.Event.Check(PlayerVideoEvent.EventId, OnDealPlayEvent))
  38. {
  39. GameMain.Event.Unsubscribe(PlayerVideoEvent.EventId, OnDealPlayEvent);
  40. }
  41. }
  42. public void BeginPlay() {
  43. videoPlayer.Play();
  44. }
  45. public void StopPlay() {
  46. videoPlayer.Stop();
  47. }
  48. }