码迷,mamicode.com
首页 > 其他好文 > 详细

VR游乐园学习(1)—添加游乐项目视频

时间:2019-08-30 14:15:05      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:one   exist   object   gas   mat   src   collect   err   return   

(1)首先需要添加组件“VideoPlayer”

技术图片

技术图片

source为视频来源,URL为视频路径。

(2)通过脚本控制视频播放,在Quad上挂载

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;
using VRTK;
using System.IO;

public class GameItem : MonoBehaviour {

    public int Index;
    private VideoPlayer m_VideoPlayer;

    private void Awake()
    {
        m_VideoPlayer = GetComponent<VideoPlayer>();
        GameObject.Find("ControllerRight").GetComponent<VRTK_ControllerEvents>().TouchpadReleased += GameItem_TouchpadReleased;
        GameObject.Find("ControllerLeft").GetComponent<VRTK_ControllerEvents>().TouchpadReleased += GameItem_TouchpadReleased;
    }
    private void Update()
    {
        if (Index == GameItemSelect._Instance.Index)
        {
            GetComponent<MeshCollider>().enabled = true;
            GetComponent<MeshRenderer>().material.color = Color.white;
        }else
        {
            GetComponent<MeshCollider>().enabled = false;
            GetComponent<MeshRenderer>().material.color = Color.gray;
        }
    }
    /// <summary>
    /// 圆盘按钮抬起
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void GameItem_TouchpadReleased(object sender, ControllerInteractionEventArgs e)
    {
        m_VideoPlayer.Pause();
    }
    /// <summary>
    /// 设置视频名称
    /// </summary>
    /// <param name="videoName"></param>
    public void SetVideoName(string videoName)
    {
        m_VideoPlayer.url = GetVideoPath(videoName);

    }
    /// <summary>
    /// 获取视频路径
    /// </summary>
    /// <param name="videoName"></param>
    /// <returns></returns>
    private string GetVideoPath(string videoName)
    {
        return Application.dataPath + "/StreamingAssets/" + videoName + ".mp4";

    }
    private void OnTriggerEnter(Collider other)
    {
        if (File.Exists(m_VideoPlayer.url) == false) return;
        m_VideoPlayer.Play();
    }

    private void OnTriggerExit(Collider other)
    {
        m_VideoPlayer.Pause();
    }
}

 

VR游乐园学习(1)—添加游乐项目视频

标签:one   exist   object   gas   mat   src   collect   err   return   

原文地址:https://www.cnblogs.com/dream-seeker-201907/p/11434329.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!