Energy efficiency in unity3d - halting app waiting for user interaction

巧了我就是萌 提交于 2019-12-07 07:16:28

Unity internal architecture is that of a game. There as an infinite loop consisted of Update() and Render() and it's runs as fast as it can. Probably, you can change this behaviour with custom plugin, so there is option №1.

Option №1. Unity is (still) single-threaded. But it is in multi-threaded managed environment. You may call Sleep in your script and application will sleep for a time with no Update() neither Render() invoked. The problem is that Unity run its input in the same thread. But in theory you can create custom plugin and implement input running in another thread. Therefore you will be able to put Unity to conditional sleep using something like WaitFor(customInput). Of course you will need separate implementation of plugin for each platform.

It is not an easy answer, huh? Yet there is another option.

Option №2. You can reduce power consumption if you ease the work (its obviously, I know). First, you don't need 60 frames per second in your app. Look for Application.targetFrameRate and vsync in quality setting (note that vsync overrides targetFrameRate). And second, cache your results. You can pre-render complex scene into render target and then present in on screen instead of source scene until considerably changes will be made.

You can use:

Thread.sleep(noofmillisecs)

Even using as little as 2millisecs Thread.sleep(2) saves energy, since its called every frame. If you have 30fps (ios) it will sleep the app 40% of the time. If you get userinput you can lower or stop sleeping for a while, and resume when there is none.

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