C#-Unity协程在后台停止

C#-Unity协程在后台停止,第1张

概述我的问题如下:目前,我在Android/iOS的游戏中运行了多个协程,但是当我将游戏发送到后台以尝试使用手机进行其他 *** 作时,协程会停止并且仅在我回到游戏后才能恢复;有什么方法可以让协程在后台运行时继续运行?解决方法:Androidwillsuspendyourapplicationbydesign.Co-routinesru

我的问题如下:目前,我在Android / iOS的游戏中运行了多个协程,但是当我将游戏发送到后台以尝试使用手机进行其他 *** 作时,协程会停止并且仅在我回到游戏后才能恢复;有什么方法可以让协程在后台运行时继续运行?

解决方法:

Android will suspend your application by design. Co-routines run in the same thread as your Updates,因此不太可能在前台运行方面区分两者.话虽如此,但是有解决方法.您可以构建一个与AndroID平台对话的plugin或使用OnApplicationPause并计算在应用程序中传递的时间,然后在这两个时间段内做您想做的任何事情.第一个要求您按照building a plugin的方式进行 *** 作
第二个使用以下

public voID OnApplicationPause(bool paused) {    if(paused) {       // Game is paused, remember the time    } else {       // Game is unpaused, calculate the time passed since the game was paused and use this time to calculate build times of your buildings or how much money the player has gained in the meantime.     }}

有关更多信息,请参见
this或this.

还要注意的是building a plugin requires a Pro Licence

其他常规程序资源

>
Co-Routine Execution Order
> Co-Routine Scheduler
> Deep Explaination of Co-Routines

总结

以上是内存溢出为你收集整理的C#-Unity协程在后台停止全部内容,希望文章能够帮你解决C#-Unity协程在后台停止所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1087953.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存