基于AVpro视频播放器的展馆视频播放
using System.Collections;using System.Collections.Generic;using UnityEngine;using RenderHeads.Media.AVProVideo;脚本不需要赋值,挂在物体上即可public class VideoShowOne : MonoBehaviour{public static VideoShowOne showO
文章共1,310字 · 阅读需要大约5分钟
一键AI生成摘要,助你高效阅读
问答
·
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using RenderHeads.Media.AVProVideo;
脚本不需要赋值,挂在物体上即可
public class VideoShowOne : MonoBehaviour
{
public static VideoShowOne showOne;bool IsPlay = false;
private void Awake()
{
showOne = this;
}
public MediaPlayer mediaPlayer;
public void ShowOne(MediaPlayer media, string path) {
if (mediaPlayer!=null)
{
mediaPlayer.Control.CloseVideo();
}
mediaPlayer = media;
media.OpenVideoFromFile(MediaPlayer.FileLocation.RelativeToStreamingAssetsFolder, path, true);
media.Play();
}
public void Tog(MediaPlayer media, string path) {
if (media.Control.IsPlaying())
{
media.Pause();
media.Control.CloseVideo();
}
else
{
ShowOne(media, path);
}
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
//存储信息脚本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using RenderHeads.Media.AVProVideo;
public class Cun : MonoBehaviour
{
public MediaPlayer MediaPlayer;public string path;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
//重写控制器基类
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEditor;
using UnityEngine;
using VRTK;
using RenderHeads.Media.AVProVideo;
/// <summary>
/// 重写的脚本基类
/// </summary>
public class VideoPress : MonoBehaviour
{
public VRTK_Pointer RighPO;
private void Awake()
{
RighPO = GetComponent<VRTK_Pointer>();
RighPO.DestinationMarkerEnter += Pointer_DestinationMarkerEnter;
RighPO.DestinationMarkerExit += Pointer_DestinationMarkerExit;
RighPO.DestinationMarkerSet += M_Pointer_DestinationMarkerSet;
}
private void M_Pointer_DestinationMarkerSet(object sender, DestinationMarkerEventArgs e)
{
print("选择物体" + e.target.name);
Cun video = e.target.GetComponent<Cun>();//获取物体身上的
if (video)
{
VideoShowOne.showOne.Tog(video.MediaPlayer, video.path);
}
}
public void OnDestroy()
{
RighPO.DestinationMarkerEnter -= Pointer_DestinationMarkerEnter;
RighPO.DestinationMarkerExit -= Pointer_DestinationMarkerExit;
}
private void Pointer_DestinationMarkerExit(object sender, DestinationMarkerEventArgs e)
{
print("射线退出物体");
}
private void Pointer_DestinationMarkerEnter(object sender, DestinationMarkerEventArgs e)
{
print("射线进入物体");
}
}
更多推荐
已为社区贡献1条内容
所有评论(0)