Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
1,120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. using UnityEngine;
  2. using System;
  3.  
  4.  
  5. public class ExampleRenderTexturePlayback : MonoBehaviour
  6. {
  7. #if UNITY_SWITCH
  8. private string MoviePath;
  9. public GameObject lumaObject;
  10. public GameObject chromaObject;
  11.  
  12. UnityEngine.Switch.SwitchVideoPlayer video;
  13. UnityEngine.Switch.SwitchFMVTexture lumaTex;
  14. UnityEngine.Switch.SwitchFMVTexture chromaTex;
  15.  
  16. void OnMovieEvent(int FMVevent)
  17. {
  18. Debug.Log("script has received FMV event :" + (UnityEngine.Switch.SwitchVideoPlayer.Event)FMVevent);
  19. }
  20.  
  21. void Start()
  22. {
  23. MoviePath = Application.streamingAssetsPath + "/H264_AAC_1280x720_30sec_01.mp4";
  24. video = new UnityEngine.Switch.SwitchVideoPlayer(OnMovieEvent);
  25.  
  26. int width = 1980;
  27. int height = 1080;
  28. { // if the resolution has already known, this should be removed so that the redundant file access could be suppressed.
  29. video.GetTrackInfo(MoviePath, out width, out height);
  30. }
  31. {
  32. // when you didn't call this, system would guesse a container type with the file extension.
  33. video.SetContainerType(UnityEngine.Switch.SwitchVideoPlayer.ContainerType.Mpeg4);
  34. }
  35.  
  36. lumaTex = new UnityEngine.Switch.SwitchFMVTexture();
  37. lumaTex.Create(width, height, UnityEngine.Switch.SwitchFMVTexture.Type.R8);
  38. chromaTex = new UnityEngine.Switch.SwitchFMVTexture();
  39. chromaTex.Create(width/2, height/2, UnityEngine.Switch.SwitchFMVTexture.Type.R8G8);
  40. video.Init(lumaTex, chromaTex);
  41.  
  42. var quad = GameObject.Find("Quad");
  43. quad.GetComponent<Renderer>().material.mainTexture = lumaTex.GetTexture();
  44. quad.GetComponent<Renderer>().material.SetTexture("_ChromaTex", chromaTex.GetTexture());
  45.  
  46. if (lumaObject != null) {
  47. lumaObject.GetComponent<Renderer>().material.mainTexture = lumaTex.GetTexture();
  48. }
  49. if (chromaObject != null) {
  50. chromaObject.GetComponent<Renderer>().material.mainTexture = chromaTex.GetTexture();
  51. }
  52. }
  53.  
  54. void Update()
  55. {
  56. UnityEngine.Profiling.Profiler.BeginSample("fmv_update");
  57.  
  58. if (Input.anyKeyDown) // anykey
  59. {
  60. bool result = video.Play(MoviePath);
  61. Debug.Log("result of starting to play : " + result);
  62. }
  63.  
  64. if (Input.GetKeyDown(KeyCode.A)) // A
  65. {
  66. video.Stop();
  67. }
  68.  
  69.  
  70. UnityEngine.Profiling.Profiler.EndSample();
  71. }
  72.  
  73. void OnPreRender()
  74. {
  75. video.Update();
  76. //float normalized_progress = video.GetCurrentTime()/video.GetVideoLength();
  77. }
  78.  
  79. #endif // #if UNITY_SWITCH
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement