问题
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