VR游乐园学习—添加游乐项目视频
Posted dream-seeker-201907
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VR游乐园学习—添加游乐项目视频相关的知识,希望对你有一定的参考价值。
(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游乐园学习—添加游乐项目视频的主要内容,如果未能解决你的问题,请参考以下文章
无法在 Swift 游乐场中向 SKScene 添加滑动识别器?
如何将共享到 GraphQL Bin 选项添加到我的 Apollo 服务器游乐场?
向 info.plist 添加了自定义键,当我从 Swift 的游乐场访问时,它是 nil