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("射线进入物体");

    }
}

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐