Adding simple ForceRenderRate example
This commit is contained in:
Родитель
6ddc6912a3
Коммит
99de62b983
|
@ -0,0 +1,32 @@
|
|||
using System.Collections;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
|
||||
public class ForceRenderRate : MonoBehaviour
|
||||
{
|
||||
public float Rate = 50.0f;
|
||||
float currentFrameTime;
|
||||
|
||||
void Start()
|
||||
{
|
||||
QualitySettings.vSyncCount = 0;
|
||||
Application.targetFrameRate = 9999;
|
||||
currentFrameTime = Time.realtimeSinceStartup;
|
||||
StartCoroutine("WaitForNextFrame");
|
||||
}
|
||||
|
||||
IEnumerator WaitForNextFrame()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
yield return new WaitForEndOfFrame();
|
||||
currentFrameTime += 1.0f / Rate;
|
||||
var t = Time.realtimeSinceStartup;
|
||||
var sleepTime = currentFrameTime - t - 0.01f;
|
||||
if (sleepTime > 0)
|
||||
Thread.Sleep((int)(sleepTime * 1000));
|
||||
while (t < currentFrameTime)
|
||||
t = Time.realtimeSinceStartup;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2e246fafd6d9746bb9f3f9c95effb55e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7d80985686f3a4ce5bfd78a905569c3e
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -117,7 +117,7 @@ public class GenLockedRecorder : MonoBehaviour
|
|||
// This is the actual sleep/busy loop simulating waiting for the genlock signal.
|
||||
var sleepTime = nextGenLockTime - t - 0.01f; // conservative sleep
|
||||
if (sleepTime>0)
|
||||
Thread.Sleep((int)sleepTime / 1000);
|
||||
Thread.Sleep((int)(sleepTime * 1000));
|
||||
do // busy-loop the remaining time for accuracy
|
||||
{
|
||||
t = Time.realtimeSinceStartup;
|
||||
|
|
|
@ -5,10 +5,10 @@ EditorBuildSettings:
|
|||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 2
|
||||
m_Scenes:
|
||||
- enabled: 0
|
||||
path: Assets/Scenes/SampleScene.unity
|
||||
guid: 99c9720ab356a0642a771bea13969a05
|
||||
- enabled: 1
|
||||
path: Assets/Test.unity
|
||||
path: Assets/GenLockedRecorder.unity
|
||||
guid: b4881cb83d3ff4e1c927ba2c6fd1de5b
|
||||
- enabled: 0
|
||||
path: Assets/ForceRenderRate.unity
|
||||
guid: 7d80985686f3a4ce5bfd78a905569c3e
|
||||
m_configObjects: {}
|
||||
|
|
Загрузка…
Ссылка в новой задаче