Unity 6.3
0 онлайн 53 гостей 3 в системе
Вход

VideoClip.pixelAspectRatioNumerator

Declaration

public uint pixelAspectRatioNumerator;

Описание

Возвращает числитель соотношения сторон пикселей (числитель:знаменатель). (Только для чтения).

Соотношение сторон пикселей (например, 10:11) определяет форму каждого пикселя. Первое число (10) является числителем и представляет собой ширину пикселя. Второе число (11) является знаменателем и представляет собой высоту пикселя. Вы можете использовать соотношение сторон пикселей для изменения размера видео, чтобы оно выглядело менее растянутым.

Дополнительные ресурсы: VideoClip.pixelAspectRatioDenominator.

// This script creates a plane, adds a VideoPlayer component and plays a video on it. 
// It uses the pixel aspect ratio denominator and numerator to resize the plane to prevent the video appearing stretched. 

using UnityEngine; using UnityEngine.Video;

public class PixelAspectRatioExample : MonoBehaviour { public VideoClip videoClip; public Camera mainCamera; void Start() { if (videoClip != null) { float numerator = (float)videoClip.pixelAspectRatioNumerator; float denominator = (float)videoClip.pixelAspectRatioDenominator;

// Create a plane to project the video clip onto. GameObject videoPlane = GameObject.CreatePrimitive(PrimitiveType.Plane); // Create the VideoPlayer and assign a VideoClip. VideoPlayer videoPlayer = videoPlane.AddComponent<VideoPlayer>(); videoPlayer.clip = videoClip;

// Set the plane to the same position as your GameObject. videoPlane.transform.position = transform.position;

// Rotate the plane to face the camera and adjust. videoPlane.transform.LookAt(mainCamera.transform); videoPlane.transform.Rotate(90, 0, 0);

// Scale the plane to match the video's aspect ratio. float planeWidth = videoPlane.transform.localScale.x * numerator / denominator; videoPlane.transform.localScale = new Vector3(planeWidth, 1, 1);

} else { Debug.LogError("No VideoClip assigned in the Inspector."); } } }