/****************************************************************************
* Copyright 2019 Nreal Techonology Limited. All rights reserved.
*
* This file is part of NRSDK.
*
* https://www.nreal.ai/
*
*****************************************************************************/
namespace NRKernal.Record
{
using NRKernal;
using UnityEngine;
using System.Collections;
/// An editor frame provider.
public class NullDataFrameProvider : AbstractFrameProvider
{
protected UniversalTextureFrame m_DefaultFrame;
private bool m_IsPlay = false;
private int FPS;
/// Default constructor.
public NullDataFrameProvider(int fps)
{
FPS = fps;
m_DefaultFrame = new UniversalTextureFrame();
NRKernalUpdater.Instance.StartCoroutine(UpdateFrame());
}
/// Updates the frame.
/// An IEnumerator.
public IEnumerator UpdateFrame()
{
float timeInteval = 1f * 0.9f / FPS;
float timeLast = 0f;
while (true)
{
if (m_IsPlay)
{
if (timeLast >= timeInteval)
{
m_DefaultFrame.timeStamp = NRSessionManager.Instance.TrackingSubSystem.GetHMDTimeNanos();
OnUpdate?.Invoke(m_DefaultFrame);
m_IsFrameReady = true;
timeLast = 0;
}
}
yield return new WaitForEndOfFrame();
timeLast += Time.unscaledDeltaTime;
}
}
/// Plays this object.
public override void Play()
{
m_IsPlay = true;
}
/// Stops this object.
public override void Stop()
{
m_IsPlay = false;
}
/// Releases this object.
public override void Release()
{
m_IsPlay = false;
NRKernalUpdater.Instance?.StopCoroutine(UpdateFrame());
}
}
}