Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System;
- public class ExampleRenderTexturePlayback : MonoBehaviour
- {
- #if UNITY_SWITCH
- private string MoviePath;
- public GameObject lumaObject;
- public GameObject chromaObject;
- UnityEngine.Switch.SwitchVideoPlayer video;
- UnityEngine.Switch.SwitchFMVTexture lumaTex;
- UnityEngine.Switch.SwitchFMVTexture chromaTex;
- void OnMovieEvent(int FMVevent)
- {
- Debug.Log("script has received FMV event :" + (UnityEngine.Switch.SwitchVideoPlayer.Event)FMVevent);
- }
- void Start()
- {
- MoviePath = Application.streamingAssetsPath + "/H264_AAC_1280x720_30sec_01.mp4";
- video = new UnityEngine.Switch.SwitchVideoPlayer(OnMovieEvent);
- int width = 1980;
- int height = 1080;
- { // if the resolution has already known, this should be removed so that the redundant file access could be suppressed.
- video.GetTrackInfo(MoviePath, out width, out height);
- }
- {
- // when you didn't call this, system would guesse a container type with the file extension.
- video.SetContainerType(UnityEngine.Switch.SwitchVideoPlayer.ContainerType.Mpeg4);
- }
- lumaTex = new UnityEngine.Switch.SwitchFMVTexture();
- lumaTex.Create(width, height, UnityEngine.Switch.SwitchFMVTexture.Type.R8);
- chromaTex = new UnityEngine.Switch.SwitchFMVTexture();
- chromaTex.Create(width/2, height/2, UnityEngine.Switch.SwitchFMVTexture.Type.R8G8);
- video.Init(lumaTex, chromaTex);
- var quad = GameObject.Find("Quad");
- quad.GetComponent<Renderer>().material.mainTexture = lumaTex.GetTexture();
- quad.GetComponent<Renderer>().material.SetTexture("_ChromaTex", chromaTex.GetTexture());
- if (lumaObject != null) {
- lumaObject.GetComponent<Renderer>().material.mainTexture = lumaTex.GetTexture();
- }
- if (chromaObject != null) {
- chromaObject.GetComponent<Renderer>().material.mainTexture = chromaTex.GetTexture();
- }
- }
- void Update()
- {
- UnityEngine.Profiling.Profiler.BeginSample("fmv_update");
- if (Input.anyKeyDown) // anykey
- {
- bool result = video.Play(MoviePath);
- Debug.Log("result of starting to play : " + result);
- }
- if (Input.GetKeyDown(KeyCode.A)) // A
- {
- video.Stop();
- }
- UnityEngine.Profiling.Profiler.EndSample();
- }
- void OnPreRender()
- {
- video.Update();
- //float normalized_progress = video.GetCurrentTime()/video.GetVideoLength();
- }
- #endif // #if UNITY_SWITCH
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement