屏幕录像不是加强现实的功能,只是EasyAR SDK自带的一个功能。该功能限制颇多,只能在移动设备上使用,并且没有办法直接录制UI界面。屏幕录像功能本质上录的是RenderTexture。html
主要是在基础结构上添加了一个【VideoRecorder】游戏对象。另外,须要动态的往【Main Camera】主摄像机游戏对象上添加【CameraRecorder】脚本。bash
取消Other Settings标签下Multithreaded Rendering选项多线程
添加2个按钮用于开始和中止录像,添加一个文本框显示提示。ide
编写脚本。ui
using UnityEngine;
using UnityEngine.UI;
using easyar;
using VideoRecording;
public class RecorderController : MonoBehaviour
{
public Text uiText;
public VideoRecorder videoRecorder;
private CameraRecorder cameraRecorder;
private void Awake()
{
videoRecorder.StatusUpdate += (status, msg) =>
{
if (status == RecordStatus.OnStarted)
{
uiText.text = "Recording start";
}
if (status == RecordStatus.FailedToStart ||
status == RecordStatus.FileFailed || status == RecordStatus.LogError)
{
uiText.text = "Recording Error: " + status + ", details: " + msg;
}
Debug.Log("RecordStatus: " + status + ", details: " + msg);
};
}
public void StartRecorder()
{
videoRecorder.StartRecording();
cameraRecorder =
Camera.main.gameObject.AddComponent<CameraRecorder>();
cameraRecorder.Setup(videoRecorder, null);
}
public void StopRecorder()
{
if (videoRecorder.StopRecording())
{
uiText.text = "Recording stop " + videoRecorder.FilePath;
}
else
{
uiText.text = "Recording failed";
}
if (cameraRecorder)
{
cameraRecorder.Destroy();
}
}
}
复制代码
运行之后,点击按钮就能够开始录像,文本框会显示开始录制的提示“Recording start”。点击中止按钮,就会中止录像。spa
录像的结果会保存在持久数据目录下,具体目录位置请查看Unity官方文档 docs.unity3d.com/2018.4/Docu…线程
视频版地址:www.bilibili.com/video/bv1eK…3d