/****************************************************************************
* Copyright 2019 Nreal Techonology Limited. All rights reserved.
*
* This file is part of NRSDK.
*
* https://www.nreal.ai/
*
*****************************************************************************/
using UnityEngine;
using UnityEngine.UI;
namespace NRKernal.NRExamples
{
/// A controller for handling camera captures.
[HelpURL("https://developer.nreal.ai/develop/unity/rgb-camera")]
public class CameraCaptureController : MonoBehaviour
{
/// The capture image.
public RawImage CaptureImage;
/// Number of frames.
// public Text FrameCount;
/// Gets or sets the RGB camera texture.
/// The RGB camera texture.
private NRRGBCamTexture RGBCamTexture { get; set; }
void Start()
{
RGBCamTexture = new NRRGBCamTexture();
CaptureImage.texture = RGBCamTexture.GetTexture();
RGBCamTexture.Play();
}
/// Updates this object.
void Update()
{
if (RGBCamTexture == null)
{
return;
}
// FrameCount.text = RGBCamTexture.FrameCount.ToString();
}
/// Plays this object.
public void Play()
{
if (RGBCamTexture == null)
{
RGBCamTexture = new NRRGBCamTexture();
CaptureImage.texture = RGBCamTexture.GetTexture();
}
RGBCamTexture.Play();
// The origin texture will be destroyed after call "Stop",
// Rebind the texture.
CaptureImage.texture = RGBCamTexture.GetTexture();
}
/// Pauses this object.
public void Pause()
{
RGBCamTexture?.Pause();
}
/// Stops this object.
public void Stop()
{
RGBCamTexture?.Stop();
RGBCamTexture = null;
}
/// Executes the 'destroy' action.
void OnDestroy()
{
RGBCamTexture?.Stop();
RGBCamTexture = null;
}
}
}