本地优化
This commit is contained in:
47
Assets/Script/Recorder/WebcamToRenderTexture.cs
Normal file
47
Assets/Script/Recorder/WebcamToRenderTexture.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using Unity.WebRTC;
|
||||
using UnityEngine;
|
||||
|
||||
public class WebcamToRenderTexture : MonoBehaviour
|
||||
{
|
||||
public RenderTexture renderTexture;
|
||||
|
||||
private WebCamTexture webcamTexture;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (renderTexture == null)
|
||||
{
|
||||
RenderTextureFormat supportedFormat = WebRTC.GetSupportedRenderTextureFormat(SystemInfo.graphicsDeviceType);
|
||||
|
||||
// 创建新的RenderTexture
|
||||
renderTexture = new RenderTexture(1920, 1200, 0, supportedFormat);
|
||||
renderTexture.enableRandomWrite = true;
|
||||
renderTexture.Create();
|
||||
//_textureImage.texture = localRenderTexture;
|
||||
}
|
||||
|
||||
webcamTexture = new WebCamTexture();
|
||||
webcamTexture.Play();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (webcamTexture != null && webcamTexture.didUpdateThisFrame)
|
||||
{
|
||||
Graphics.Blit(webcamTexture, renderTexture);
|
||||
}
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
if (webcamTexture != null)
|
||||
{
|
||||
webcamTexture.Stop();
|
||||
}
|
||||
|
||||
if (renderTexture != null)
|
||||
{
|
||||
renderTexture.Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user