具有大量动态内容的Unity TextMeshPro(或替代性)的性能

发布于 2025-02-11 14:03:46 字数 588 浏览 2 评论 0原文

我正在从事一个传统的Roguelike项目。我有一个播放器日志,显示发生的事情,播放,移动到这里,机器人攻击的播放器,播放器能力等。这是相当有用的信息,并且每当玩家采取至少一行时,它都会经常更新他们周围的任何敌人也将产生线条。

我正在使用包裹在滚动rect内部的视口内部的TMP来显示日志的最后10行,并且滚动rect使我们能够滚动滚动以查看以前的行。

最初,我会天真地向TMP.TEXT添加线条,这会增长,但是,我很快注意到性能问题,每当附加文本时,TMP.generateTextMesh/generateText呼叫都会迅速增长到大小,从一百行左右后,游戏下降了。

因此,要部分解决该问题,我现在将日志文本存储在旋转的圆形缓冲区中,并且在TMP.TEXT中仅保留20条左右的线条,从而使性能良好。但是,当添加新行或用户滚动以查看旧线时,该.TEXT值仍然需要更改。即使有相对较少的文本,20行左右,TMP.GenerateText的呼叫也约为10ms(启用深层探测器),这对于相对简单的UI来说是疯狂的成本。费用是每次更新,因此一旦使文本便宜呈现,但是如果您经常更改文本字段,则成本会高昂。

是否有更好的解决方案来显示具有经常更改内容的动态文本字段?我想聊天客户端都面临类似问题,因此必须有解决方案。

I'm working on a traditional roguelike project. I have a player log that displays what happens, played moved here, robot attacked player, player casts ability etc. This is fairly useful information and it updates frequently, every time the player takes an action at least one line will be generated and if there are any enemies around they too will generate lines.

I'm using a TMP wrapped inside a Viewport that is inside a scroll rect to display the last 10 or so lines of the log, and the scroll rect gives us the ability to scroll back up to look at previous lines.

Originally, I would naively add lines to the TMP.text and this would just grow, but, I quickly noticed performance issues, whenever text was appended the TMP.GenerateTextMesh/GenerateText calls would quickly grow in magnitude to the point where it was visibly slowing the game down after one hundred lines or so.

So to partially fix the problem I now store the log's text in a rotating circular buffer and keep only 20 or so lines in the TMP.text that makes the performance fine-ish. But that .text value still needs to change when new lines are added or the user scrolls to look at old lines. Even with a relatively small amount of text, 20 or so lines, the calls for TMP.GenerateText are taking around ~10ms (with deep profiler on) which is an insane cost for a relatively simple piece of UI. The cost is per update, so once made the text is cheap to render, but if you have a text field changing frequently the cost is exorbitant.

Is there a better solution to display a dynamic text field with frequently changing content? I'd imagine anything with a chat client is facing similar issues so there must be a solution.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

自此以后,行同陌路 2025-02-18 14:03:46

根据Derhugo的想法,当用户经常按密钥并生成大量文本更改时,每X MS划分传入的文本会产生巨大的性能差异。

现在,当新文本进来时,如果批处理时间尚未启动,则启动批处理计时器,收集接下来的250ms的所有文本,然后使用新数据更新TMP。

As per derHugo's idea, batching the incoming text every X ms made a huge performance difference when the user is pressing keys frequently and generating large text changes.

Now when new text comes in, if the batch time has not started, it starts the batch timer, collects all the text for the next 250ms and then updates the TMP with the new data.

初心未许 2025-02-18 14:03:46
  1. 将每条线拆分以单独的textmeshpro-component,
  2. 如果可以的话,请禁用其他功能,尤其是自动尺寸
  3. 使用较小的字体ATLAS分辨率
  4. 使用较少的字符字体
  5. 不使用contentsizefitter,请您自己调整RectTransfort,您自己by yousp by by yousp by by by by by yousp y
  6. recttransform
  7. 。 (您可以通过反射进行)
  8. 禁用rectMask.softness(可以通过反射进行)
  9. 或gameObject.Alpha或gameObject.setActive.setActive.setActive.Stmpro.Abled.Abled.abable或
  10. canvasgroup.alpha = 0,而不是tmpro.alpha 如果不需要
  11. 调整RectTransForm大小,则可以(单线控制台)
  12. 不使用LayoutGroup,请自己定位TMPROS
  1. Split each line to separate TextMeshPro-Component
  2. Disable additional features if you can, especially Auto-Sizing
  3. Use smaller font atlas resolution
  4. use less characters font
  5. Not use ContentSizeFitter, Resize RectTransform by yourself
  6. disable RectTransform.anchors from stretch-mode-values
  7. disable RectMask.Culling (You can make this by reflection)
  8. disable RectMask.Softness (You can make this by reflection)
  9. hide labels by CanvasGroup.alpha = 0, not by TMPro.alpha or GameObject.SetActive or TMPro.enabled or TMPro.text = Empty
  10. Disable ScrollRect if it's not need
  11. not resize RectTransform, if you can (single-line console)
  12. not use LayoutGroup, position TMPros by yourself
把梦留给海 2025-02-18 14:03:46

确保您没有创建那么多的字体资产,而是复制具有相同字体地图集的原始材料,并用您想要的盛开或灯光自定义它。
当您不需要桌面版本时,请使用移动模式。

Make sure you didn't create so many font assets, duplicate the original material of one which has the same font atlas instead and customize it with what you want to like bloom or light.
Use mobile mode when you don't need the desktop version.

御守 2025-02-18 14:03:46

确保包含您的TMP组件的画布没有启用像素完美。该设置将在每个滚动事件上触发GenerateText调用,并以大量方式触发坦克性能。

如果您需要Pixel Perfect,则可以将文本组件放入带Pifts Perfect的儿童画布中,并将其他元素保留在父帆布中。

Make sure the Canvas that contains your TMP components doesn't have pixel perfect enabled. That setting will trigger GenerateText calls on every scroll event and potentially tank performance in a massive way.

If you need the pixel perfect, you can put the text components in a child canvas with pixel perfect off and keep the other elements in a parent canvas.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文