JiNanCementPlantForUnity/Assets/Scripts/VideoCtl.cs

66 lines
1.7 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;
public enum VideoName
{
,
,
,
,
}
public class VideoCtl : MonoBehaviour
{
public VideoPlayer player;
public CameraState CameraState;
private double timer;
private double videolength;
bool ison;
private void OnEnable()
{
GetComponent<VideoPlayer>().url = Application.streamingAssetsPath + "/video/" + gameObject.name + ".mp4";
WebPoint.instance.enabled = false;
Debug.Log("WebPoint" + WebPoint.instance.isActiveAndEnabled);
CameraState.enabled = false;
timer = 0;
// 等待视频准备完成
player.Prepare();
ison = false;
// 在视频准备完成后获取总时间
player.prepareCompleted += VideoPrepareCompleted;
}
private void VideoPrepareCompleted(VideoPlayer source)
{
// 获取视频总时间
videolength = source.length;
ison = true;
}
private void OnDisable()
{
WebPoint.instance.enabled = true;
CameraState.enabled = true;
BrideWebView.Instance.webViewPrefab.WebView.PostMessage(gameObject.name);
Debug.Log("(C#Log)JSON Post:" + gameObject.name);
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (ison)
{
timer += Time.deltaTime;
if (timer > videolength)
{
gameObject.SetActive(false);
}
}
}
}