Unity: How to pause execution until function terminates, so as to skip no frames

五迷三道 提交于 2019-12-11 23:34:01

问题


I am writing a game/program which every few seconds has to write a lot of data to the hard disk - this takes a few seconds to complete, and naturally causes the game to hang for that duration.

However, when the game resumes after the writes have completed, the game skips a few frames.

I need it that Unity will skip absolutely no frames what so ever. How can I force the Unity Engine to stop executing until the writing has fully completed, so that when it resumes, no frames have been skipped?


To provide some context, I am capturing a screenshot every frame, storing them as Texture2Ds in a queue. When the queue has more than 100 frames worth of Texture2Ds in it, I am writing the to the disk as PNGs, and clearing the queue.

I want to pause rendering/execution whilst the writing takes place so that the output (alone) is seamless.


回答1:


You could set the timeScale to 0 so that Animation and FixedUpdate are not called.

As for the Update you would have to add some checks:

void Update()
{
    if(Manager.cleaningTexture == true){ return; }
    // Rest of the code
}


来源:https://stackoverflow.com/questions/35633412/unity-how-to-pause-execution-until-function-terminates-so-as-to-skip-no-frames

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!