ZhangZhouSpecialEquipment/Assets/Scripts/门式起重机/VideoCtrl.cs

66 lines
1.5 KiB
C#

using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using UnityEngine;
using UnityEngine.Video;
/// <summary>
/// ¶à¸öÊÓÆµÂÖ²¥
/// </summary>
public class VideoCtrl : MonoBehaviour
{
public string[] AllVideoNames;
private string[] _allVideoPath;
private int _nowVideoNum = 0;
private VideoPlayer _player;
// Start is called before the first frame update
void Start()
{
_player = GetComponent<VideoPlayer>();
_allVideoPath=new string[AllVideoNames.Length];
for (int i = 0; i < AllVideoNames.Length; i++)
{
_allVideoPath[i]= Path.Combine(Application.streamingAssetsPath, AllVideoNames[i] + ".mp4");
}
StartCoroutine(WaitTimeToLoadNextVideo());
}
// Update is called once per frame
void Update()
{
}
IEnumerator WaitTimeToLoadNextVideo()
{
_player.url = _allVideoPath[0];
_player.Play();
while (true)
{
yield return new WaitForSeconds(1);
if (_player.time > (_player.length - 1))
{
if (_nowVideoNum < AllVideoNames.Length - 1)
{
_nowVideoNum++;
}
else
{
_nowVideoNum = 0; ;
}
_player.url = _allVideoPath[_nowVideoNum];
_player.Play();
}
}
}
}