using UnityEngine;
using UnityEngine.UI;public class VideoResize : MonoBehaviour
{private RawImage rawImage;private VideoPlayer videoPlayer;private void Start(){rawImage = GetComponent<RawImage();videoPlayer = GetComponent<VideoPlayer>();videoPlayer.Play();ResizeVideo();}private void ResizeVideo(){int videoWidth = 1920;//视频的宽int videoHeight = 1080;//视频的高int targetWidth = Screen.width;//屏幕宽int targetHeight = Screen.height;//屏幕高float scaleWidth = (float)targetWidth / videoWidth;float scaleHeight = (float)targetHeight / videoHeight;float scaleFactor = Mathf.Min(scaleWidth, scaleHeight);int newWidth = Mathf.RoundToInt(videoWidth * scaleFactor);int newHeight = Mathf.RoundToInt(videoHeight * scaleFactor);rawImage.rectTransform.sizeDelta = new Vector2(newWidth , newHeight );}
}