Version: 2023.2
言語: 日本語
ビデオの概要
MovieTexture から VideoPlayer への移行

 Video Player コンポーネント

Video Player コンポーネント を使って ビデオファイルゲームオブジェクト にアタッチし、ランタイムにビデオファイルをゲームオブジェクトの テクスチャ 上で再生できます。

下の図は、球状のゲームオブジェクトにアタッチされた Video Player コンポーネントを表示しています。

By default, the Material Property of a Video Player component is set to a GameObject’s main texture, which means that when the Video Player component is attached to a GameObject that has a Renderer, it automatically assigns itself to the Texture on that Renderer (because this is the main Texture for the GameObject). Here, the GameObject has a Mesh Renderer component, so the Video Player automatically assigns it to the Renderer field, which means the Video Clip plays on the Mesh Renderer’s Texture.

A Video Player component attached to a spherical GameObject, playing the Video Clip on the GameObject’s main Texture (in this case, the Texture of the Mesh Renderer)
A Video Player component attached to a spherical GameObject, playing the Video Clip on the GameObject’s main Texture (in this case, the Texture of the Mesh Renderer)

ビデオを再生する特定の対象 (以下を含む) を設定することもできます。

Video Player component reference

プロパティ 説明 
ソース Choose the source type of your video.
Video Clip Select the Video Clip to assign to the Video Player component. This isn’t supported on the Web platform.
URL Enter the URL (for example, http:// or file://) of the video you want to assign to the Video Player.
Update Mode Set the clock source that the Video Player component uses to update its timing.
DSP Time Use the same clock source that processes audio.
Game Time Use the same clock source as the game clock. This clock source is affected by the time scaling and capture frame rate settings.
Unscaled Game Time Use the same clock source as the game clock but without being affected by time scaling or capture frame rate.
Play On Awake Play the video when the Scene launches. Clear it if you want to trigger the video playback at another point during runtime. Trigger it via scripting with the Play() command.
Wait For First Frame Wait for the first frame of the source video to be ready for display before the game starts. Clear it to keep the video time in sync with the rest of the game, which might cause the first few frames to be discarded.
Loop Loop the source video when it reaches its end. Clear it to stop playing the video when it reaches the end.
Skip On Drop When you enable this option, and the Video Player component detects drift between the playback position and the game clock, the Video Player skips ahead. When you disable this option, the Video Player doesn’t correct for drift and systematically plays all frames.
Playback Speed Set a multiplier for the playback speed, as a value between 0 and 10. This is set to 1 (normal speed) by default. If the field is set to 2, the video plays at two times its normal speed.
Render Mode Choose how the video will render.
Camera Far Plane ビデオをカメラの ファークリップ面 にレンダリングします。
Camera Near Plane ビデオをカメラの ニアクリップ面 にレンダリングします。
Render Texture レンダーテクスチャ にビデオをレンダリングします。
Material Override ビデオを、レンダラーの マテリアル を通してゲームオブジェクトの選択されたテクスチャプロパティにレンダリングします。
API Only ビデオを VideoPlayer.texture スクリプト API プロパティにレンダリングします。テクスチャを意図する対象に割り当てるには、スクリプトを使用する必要があります。
Camera ビデオを取得する カメラ を選択します。
Alpha Set the global transparency level to add to the source video. This allows elements behind the plane to be visible through it. For more information about alpha channels, refer to video transparency support.
3D Layout Choose the layout of 3D content in the source video.
None Video doesn’t have any 3D content.
Side by Side Video has 3D content where the left eye occupies the left half and right eye occupies the right half of video frames.
Over Under Video has 3D content where the left eye occupies the upper half and right eye occupies the lower half of video frames.
Target Texture Video Player コンポーネントが画像をレンダリングするレンダーテクスチャを選択します。
Aspect Ratio Set the aspect ratio of the images that fill the Camera Near Plane, Camera Far Plane, or Render Texture when the corresponding Render Mode is used.
No Scaling スケーリングを使用しません。ビデオは対象の矩形の中央に配置されます。
Fit Vertically 対象の矩形の縦に一致するようにソースをスケールします。左右はクロップしたり、必要な場合は黒い部分として残します。ソースのアスペクト比は維持されます。
Fit Horizontally 対象の矩形の横に一致するようにソースをスケールします。上下はクロップしたり、必要な場合は黒い部分として残します。ソースのアスペクト比は維持されます。
Fit Inside クロップせずに対象の矩形に一致するようソースをスケールします。左右、または上下は、必要に応じて黒い部分として残します。ソースのアスペクト比は維持されます。
Fit Outside 黒い部分を残さずに対象の矩形に一致するようソースをスケールします。左右、または上下は、必要に応じてクロップします。ソースのアスペクト比は維持されます。
Stretch Scale both horizontally or vertically to fit the destination rectangle. The source aspect ratio isn’t preserved.
Renderer Select the Renderer where the Video Player component renders its images. When set to None, the Renderer on the same GameObject as the Video Player component is used.
Auto-Select Property When you enable this option, the Video Player component selects the Renderer’s main texture automatically. When you disable this option, you can set the Material Property option manually.
Material Property Video Player コンポーネントの画像を受け取る Material Texture プロパティ の名。
Audio Output Mode ソースのオーディオトラックを出力する方法を選択します。
None Audio isn’t played.
Audio Source オーディオサンプルが選択した オーディオソース に送信され、Unity のオーディオ処理が適用できるようになります。
Direct オーディオサンプルは Unity のオーディオ処理を経由せず、直接オーディオ出力ハードウェアに送信されます。
API Only (Experimental) オーディオサンプルは関連するAudioSampleProviderに送信されます。
Controlled Tracks The number of audio tracks in the video.

Only shown when Source is URL. When Source is Video Clip, the number of tracks is determined by examining the video file.
Track Number Enable the associated audio track to use for playback. This must be set prior to playback.

The text to the left of the checkbox provides information about the audio track, specifically the track number, language, and number of channels.

When the source is a URL, this information is only available during playback.

This property only appears if your source is a Video Clip that has an audio track (or tracks), or your source is a URL (allowing you to indicate how many tracks are expected from the URL during playback).
Audio Source The audio source through which the audio track is played. The targeted audio source can also play Audio Clips.

The audio source’s playback controls (Play On Awake and Play() in scripting API) don’t apply to the video source’s audio track.

This property only appears when the Audio Output Mode is set to Audio Source.
Mute Mute the associated audio track. In Audio Source mode, the audio source’s control is used.

This property only appears when the Audio Output Mode is set to Direct.
Volume Volume of the associated audio track. In Audio Source mode, the audio source’s volume is used.

This property only appears when the Audio Output Mode is set to Direct.

Video Playerスクリプトの例

The following script demonstrates a few of the Video Player component’s features.

// Examples of Video Player function

using UnityEngine;

public class Example : MonoBehaviour
{
    void Start()
    {
        // Will attach a Video Player to the main camera.
        GameObject camera = GameObject.Find("Main Camera");

        // VideoPlayer automatically targets the camera backplane when it is added
        // to a camera object, no need to change videoPlayer.targetCamera.
        var videoPlayer = camera.AddComponent<UnityEngine.Video.VideoPlayer>();

        // Play on awake defaults to true. Set it to false to avoid the url set
        // below to auto-start playback since we're in Start().
        videoPlayer.playOnAwake = false;

        // By default, Video Players added to a camera will use the far plane.
        // Let's target the near plane instead.
        videoPlayer.renderMode = UnityEngine.Video.VideoRenderMode.CameraNearPlane;

        // This will cause our Scene to be visible through the video being played.
        videoPlayer.targetCameraAlpha = 0.5F;

        // Set the video to play. URL supports local absolute or relative paths.
        // Here, using absolute.
        videoPlayer.url = "/Users/graham/movie.mov";

        // Skip the first 100 frames.
        videoPlayer.frame = 100;

        // Restart from beginning when done.
        videoPlayer.isLooping = true;

        // Each time we reach the end, we slow down the playback by a factor of 10.
        videoPlayer.loopPointReached += EndReached;

        // Start playback. This means the Video Player may have to prepare (reserve
        // resources, pre-load a few frames, etc.). To better control the delays
        // associated with this preparation one can use videoPlayer.Prepare() along with
        // its prepareCompleted event.
        videoPlayer.Play();
    }

    void EndReached(UnityEngine.Video.VideoPlayer vp)
    {
        vp.playbackSpeed = vp.playbackSpeed / 10.0F;
    }
}

VideoPlayer

ビデオの概要
MovieTexture から VideoPlayer への移行