提高太多UI图像上的帧速率-Unity UI [英] Improve Frame rate on too many UI Images - Unity UI
问题描述
在我的单个页面中,有很多纹理需要渲染,然后我才刚刚遇到屏幕打开问题,但这可以解决这个建议:
In my single page, there were so many textures those I require to render before I was just facing problem in just screen opening but this I was able to resolve this suggestion:
这是我用于此目的的实际代码:
Here is the actual code that I used for this purpose:
public void OnValueChangeRefreshCards (Vector2 valueChange)
{
elapsedYDist += valueChange.y;
if (elapsedYDist > 3f) {
elapsedYDist = 0f;
for (int i = 0; i < GameConstants.TOTAL_ROSE_COUNT; i++) {
Card card = roseList [i].GetComponent<Card> ();
if (RendererExtensions.IsVisibleFrom (card.MyRectTransform, Camera.main))
card.roseImage.enabled = true;
else
card.roseImage.enabled = false;
}
}
}
但是现在我开始过多的丢帧率相关问题,因此即使滚动页面也对我来说真的很困难. 请查看随附的视频,以进一步了解我所面临的问题. NameThatRose-低帧速率
But now I started too much framerate lose related issue so even scrolling of page become really difficult for me. Please check the attached video for more clearance about the issue, I was facing. NameThatRose - Low Frame Rate
请给我一些进一步改进的建议.
Please give me some suggestions for next improvements.
编辑:这是我的探查器输出.
Here are my profiler output.
- 详细的深度剖析器
- 概述Deep Profiler
- Detailed Deep Profiler
- Overview Deep Profiler
推荐答案
您可以尝试一些尝试来找出导致fps低的原因.
You can try few things to find out whats causing the low fps.
- 使用 profiler 进行深入剖析,以找出哪个UI调用花费更多时间.就像我做的一样这里.
由于Image继承自
UIMaskableGraphics
,因此它将为列表中的每个图像调用MaskableGraphics.OnEnable()
每帧.这会占用一些时间,您可以在此处查看:
- Use profiler to deep profile to find out which UI call is taking more time. Like what I did here.
As Image inherits from
UIMaskableGraphics
, it callsMaskableGraphics.OnEnable()
every frame for every image in your list. This takes up time which you can see here:
-
我相信您的
OnValueChanged
方法在每一帧都被调用,这只会使启用/禁用迭代及其处理时间倍增.您可以限制通话时间,例如每秒处理4次.
I believe your
OnValueChanged
method is called every frame this would only multiply the enable/disable iterations and its processing time. You can limit the call by some time, processing 4 times a second for example.
float timeSinceLastUpdate = 0;
void Update()
{
timeSinceLastUpdate += Time.deltaTime;
}
public void OnValueChangeRefreshCards (Vector2 valueChange)
{
if(timeSinceLastUpdate < 0.25f)
{
return;
}
timeSinceLastUpdate = 0;
// do your stuff here...
}
您需要处理250张以上的图像,每一帧都需要处理,这对于较旧的Android设备而言非常重要,因为MaskableGraphics.OnEnable()
调用可能是罪魁祸首.您可以根据需要避免更改状态:
You have 250+ images to process every frame which is a big deal for older Android devices, again as MaskableGraphics.OnEnable()
call can be the culprit. You can avoid changing the state if it is required:
if (RendererExtensions.IsVisibleFrom (card.MyRectTransform, Camera.main))
{
if(!card.roseImage.enalbed)
card.roseImage.enabled = true;
}
else
{
if(card.roseImage.enalbed)
card.roseImage.enabled = false;
}
此外,以下是一些在Unity中优化UI的有用链接:
Furthermore, following are some helpful links to optimize UI in Unity:
以下博客提供了有关UI渲染的更多信息:
The following blog provides more information about UI rendering:
希望这会有所帮助:)
这篇关于提高太多UI图像上的帧速率-Unity UI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!