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().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); } } } }