using System;
using Convai.Runtime.Vision.Sources;
using UnityEngine;
public class CustomXRVisionFrameSource : MonoBehaviour, IVisionFrameSource
{
[SerializeField] private float _targetFrameRate = 15f;
[SerializeField] private string _sourceId = "custom-xr";
private RenderTexture _renderTexture;
public bool IsCapturing { get; private set; }
public long FrameCount { get; private set; }
public (int Width, int Height) FrameDimensions => (_renderTexture ? _renderTexture.width : 0,
_renderTexture ? _renderTexture.height : 0);
public float TargetFrameRate => _targetFrameRate;
public string SourceId => _sourceId;
public RenderTexture CurrentRenderTexture => _renderTexture;
public bool IsFrameReady { get; private set; }
public event Action FrameReady;
public void StartCapture()
{
// 在此初始化你的 XR SDK 摄像头和 RenderTexture。
// 每当有新帧可用时,将其 blit 到 _renderTexture 中(自上而下 / Y 翻转),
// 然后递增 FrameCount,将 IsFrameReady 设为 true,并触发 FrameReady?.Invoke()。
IsCapturing = true;
}
public void StopCapture()
{
IsCapturing = false;
IsFrameReady = false;
}
}