使用JIMO ActionOne HongHu 及其他MR VR眼镜,将真实场景和游戏内场景混合渲染
1. 在VR相机Head内创建一个 Camera 和两个RawImage(Camera 的参数和VRCamera的参数一致, 两个RawImage尺寸一致, 要把VRCamera的相机遮挡住 )
2.Camera负责渲染游戏内的画面,将画面通过RenderTexture 渲染到第二个RawImage上
3.设置需要渲染物体的Layer为ShowObj ,没有就自己ADD
4.设置Camera 的CullingMask 为只渲染ShowObj层
5.将VRCamera相机的CullingMask设置为UI(就是只能看见两个RawImage,其它不渲染就行,自行修改RawImage的Layer,和 3 4 步骤一个意思)
6.新建OperCamera,代码如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class OpenCamera : MonoBehaviour
{
// UI 相关参数
public RawImage rawImage;
// 摄像机图片参数
private WebCamTexture webCamTexture;
// Start is called before the first frame update
void Start()
{
StartCoroutine("OpenCameraTest");
}
IEnumerator OpenCameraTest()
{
// 申请相机权限
yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
// 判断是否有相机权限
if (Application.HasUserAuthorization(UserAuthorization.WebCam))
{
// 获取相机设备
WebCamDevice[] webCamDevices = WebCamTexture.devices;
// 判断是否有相机设别
if (webCamDevices != null && webCamDevices.Length > 0)
{
// 把 0 号设备(移动端后置摄像头)名称赋值
string webCamName = webCamDevices[0].name;
// 设置相机渲染宽高,并运行相机
webCamTexture = new WebCamTexture(webCamName, Screen.width, Screen.height);
// webCamTexture.requestedFPS = 30;
webCamTexture.Play();
// 把获取的图像渲染到画布上
rawImage.texture = webCamTexture;
}
}
}
}
将第一个RawImage放入 ,直接运行就行了。