enumeration
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
CloseFor some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
CloseType of destination for the images read by a VideoPlayer.
Set this enumeration to determine where and how the VideoPlayer renders the images of a video clip.
// This script switches between the render modes when you press the Spacebar. // To set up your project for this script: // 1. Attach this script to a GameObject in your scene. // 2. Add a VideoPlayer component to your GameObject. // 3. Assign a Camera to the script component in the Inspector. // 4. Add a plane to your scene. // 5. Create a Material (right click in Asset folder, Create > Material). // 6. Create a new RenderTexture (right click in Asset folder, Create > Material). // 7. Assign the RenderTexture to the Inspector of your material (Base Map). // 8. Assign the material to your plane.
using UnityEngine; using UnityEngine.Video;
public class VideoRenderModeExample : MonoBehaviour { VideoPlayer videoPlayer; public RenderTexture renderTexture; Camera mainCamera;
// Tracks the current render mode. private int renderModeIndex = 0;
void Start() { mainCamera = Camera.main; videoPlayer = GetComponent<VideoPlayer>(); videoPlayer.isLooping = true; UpdateRenderMode(); }
private void Update() { // If you press the Spacebar, cycle through the render modes. if (Input.GetKeyDown(KeyCode.Space)) { renderModeIndex = (renderModeIndex + 1) % 5; UpdateRenderMode(); } }
void UpdateRenderMode() { ClearPreviousRenderMode(); // Switch render mode when you press the Spacebar. switch (renderModeIndex) { case 0: SwitchToRenderTexture(); break; case 1: SwitchToCameraNearPlane(); break; case 2: SwitchToCameraFarPlane(); break; case 3: SwitchToAPIOnly(); break; case 4: SwitchToMaterialOverride(); break; } }
// Show video on the surface of an object. void SwitchToRenderTexture() { videoPlayer.renderMode = VideoRenderMode.RenderTexture; videoPlayer.targetTexture = renderTexture; Debug.Log("Switched to RenderTexture mode"); }
// Show the video on your screen in front of your Scene. void SwitchToCameraNearPlane() { videoPlayer.renderMode = VideoRenderMode.CameraNearPlane; videoPlayer.targetCamera = mainCamera; Debug.Log("Switched to CameraNearPlane mode"); }
// Show video in the background of your Scene, behind your objects. void SwitchToCameraFarPlane() { videoPlayer.renderMode = VideoRenderMode.CameraFarPlane; videoPlayer.targetCamera = mainCamera; Debug.Log("Switched to CameraFarPlane mode"); }
// Don't show the video anywhere. void SwitchToAPIOnly() { videoPlayer.renderMode = VideoRenderMode.APIOnly; Debug.Log("Switched to APIOnly mode"); }
// Show the video wherever a certain material is applied. void SwitchToMaterialOverride() { videoPlayer.renderMode = VideoRenderMode.MaterialOverride; Debug.Log("Switched to Material Override mode"); }
// Clear the previous render target from the VideoPlayer. void ClearPreviousRenderMode() { // Temporarily disable rendering. videoPlayer.renderMode = VideoRenderMode.APIOnly; videoPlayer.targetTexture = null; videoPlayer.targetCamera = null;
// Clear the RenderTexture. if (renderTexture != null) { RenderTexture.active = renderTexture; GL.Clear(true, true, Color.clear); RenderTexture.active = null; } } }
Property | Description |
---|---|
CameraFarPlane | Draw video content behind a camera's scene. |
CameraNearPlane | Draw video content in front of a camera's scene. |
RenderTexture | Draw video content into a RenderTexture. |
MaterialOverride | Draw the video content into a user-specified property of the current GameObject's material. |
APIOnly | Don't draw the video content anywhere, but still make it available via the VideoPlayer's texture property in the API. |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.