Files
PrinceOfGlory/Assets/Video360Controller.cs
2026-03-03 18:24:17 +08:00

70 lines
1.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;
/// <summary>
/// 360视频播放控制组件用来读取外部视频文件
/// </summary>
public class Video360Controller : MonoBehaviour
{
private VideoPlayer mVideoPlayer;
public string VideoNameStr = "";
public double Time = 0;
private void Awake()
{
mVideoPlayer = gameObject.GetComponent<VideoPlayer>();
mVideoPlayer.started += MVideoPlayer_started;
mVideoPlayer.prepareCompleted += MVideoPlayer_prepareCompleted;
PrepareVide(VideoNameStr);
}
public bool isPlaying
{
get { return mVideoPlayer.isPlaying; }
}
private void MVideoPlayer_started(VideoPlayer source)
{
if (Time != 0)
{
MVideoPlayer_started(Time);
}
}
private void MVideoPlayer_prepareCompleted(VideoPlayer source)
{
mVideoPlayer.Play();
}
public void MVideoPlayer_started(double mtime)
{
if (Time >= mVideoPlayer.length)
{
mVideoPlayer.time = mVideoPlayer.length;
return;
}
mVideoPlayer.time = mtime;
}
public void PrepareVide(string name)
{
try
{
string videoPath = FileLoad.GetMoviesFolder() + name;
Debug.Log($"目录检测{videoPath}");
mVideoPlayer.url = videoPath;
mVideoPlayer.Prepare();
}
catch (System.Exception e)
{
Debug.LogError(e.Message);
}
}
private void OnDisable()
{
Time = 0;
}
}