public string videopath = "Video";
private VideoPlayer videoplayer => GetComponent<VideoPlayer>();
private int currentClipIndex = 0;
List<string> videoClips;
void Start()
{
var path = Application.streamingAssetsPath + "/" + videopath;
if (Directory.Exists(path))
{
DirectoryInfo direction = new DirectoryInfo(path);
FileInfo[] files = direction.GetFiles("*", SearchOption.AllDirectories);
videoClips = new List<string>();
for (int i = 0; i < files.Length; i++)
{
if (files[i].Name.EndsWith(".meta")) continue;
videoClips.Add(files[i].Name);
}
}
videoplayer.url = "file://" + Application.streamingAssetsPath + "/" + videopath + "/" + videoClips[currentClipIndex];
videoplayer.Play();
}
void FixedUpdate()
{
if (videoplayer.isPlaying)
{
if ((ulong)videoplayer.frame>=videoplayer.frameCount-1)
{
currentClipIndex++;
if (currentClipIndex >= videoClips.Count)
{
currentClipIndex = 0;
}
videoplayer.url = "file://" + Application.streamingAssetsPath + "/" + videopath + "/" + videoClips[currentClipIndex];
videoplayer.Play();
}
}
}
unity 循环播放视频
最新推荐文章于 2024-07-10 16:30:57 发布