使用示例:
代码示例:
using UnityEngine;
using UnityEngine.Video;
// ExecuteInEditMode 不用运行程序也能跑脚本
// 属性链接:https://blog.csdn.net/qq_39097425/article/details/109194397
// [ExecuteInEditMode]
[RequireComponent(typeof(VideoPlayer))]
public class VideoPlayerPlayFromStreamingAssets : MonoBehaviour
{
public bool LoadFromStreamingAssets = true;
public string URL;
private void Start()
{
VideoPlayer vp = gameObject.GetComponent<VideoPlayer>();
if (vp != null)
{
vp.source = VideoSource.Url;
vp.playOnAwake = true;
vp.url = Application.streamingAssetsPath + "/" + URL.Replace(@"\", "/");
vp.Play();
}
}
}