Unity:如何暂停执行,直到函数终止,以便跳过任何帧 [英] Unity: How to pause execution until function terminates, so as to skip no frames

查看:1243
本文介绍了Unity:如何暂停执行,直到函数终止,以便跳过任何帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个游戏/程序,每隔几秒钟必须向硬盘写入大量数据 - 这需要几秒钟的时间才能完成,并且自然会导致游戏在此期间挂起。



然而,当游戏在写完后恢复游戏时,游戏会跳过几帧。



我需要Unity 跳过绝对无框是如此。如何强制Unity引擎在写入完成前停止执行,以便在恢复时不会跳过任何帧?






为了提供一些上下文,我将捕获每帧的截图,并将它们作为Texture2D存储在队列中。当队列中有超过100帧的Texture2D时,我将它作为PNG写入磁盘,然后清除队列。



我想暂停渲染/执行,同时写入发生,以便输出(单独)无缝。

解决方案

您可以将timeScale设置为0,以便不调用Animation和FixedUpdate。

添加一些检查:

  void Update()
{
if(Manager.cleaningTexture == true ){return; }
//其余的代码
}


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.

解决方案

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
}

这篇关于Unity:如何暂停执行,直到函数终止,以便跳过任何帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆