Unity UI 优化最佳实践6 其他优化技术和小技巧

有时候,没有简单的方法来优化用户界面。 本节包含一些可能有助于提高UI性能的建议,但有些建议在结构上“不整洁”,可能难以维护,或者可能有难看的副作用。 其他人可能是UI中行为的解决方案,旨在简化初始开发,但也会使创建性能问题变得相对简单。

RectTransform-based Layouts

Layout 组件相对昂贵,因为它们必须在每次标记脏时重新计算其子元素的大小和位置。 (有关详细信息,请参阅基础章节的Graphic重建部分。)如果给定布局中的元素数量相对较少且数量固定,并且布局结构相对简单,则可以用基于RectTransform的布局来代替Layout。

通过分配RectTransform的锚点,RectTransform的位置和大小可以基于其父级进行缩放。例如,使用两个RectTransforms可以实现简单的两列布局:

  • 左栏的锚点X:(0,0.5)和Y:(0,1)
  • 右列的锚点X:(0.5,1)和Y:(0,1)

RectTransform的大小和位置的计算将由Transform系统本身在本地代码(native code)中驱动。这通常比依靠布局系统更高效。编写基于RectTransform的布局的MonoBehaviours也是可行的。但是,这是一项相对复杂的任务,超出了本指南的范围。

Disabling Canvases

在显示或隐藏UI中分离的各部分时,通常在UI的根部启用或禁用GameObject。这可以确保禁用的用户界面中没有组件接收输入或Unity回调。

但是,这也会导致Canvas放弃其VBO数据。重新启用画布将需要画布(以及任何子画布)运行重建和重新分批过程。如果这种情况频繁发生,CPU使用率的增加可能会导致应用程序的帧速率变差。

一种可能但很冒险的解决方法是将UI显示/隐藏放到其自己的Canvas或Sub-canvas中,然后仅启用/禁用此对象上的Canvas组件。

这将导致UI的网格不被绘制,但它们将保持驻留在内存中,并且它们的原始批处理将被保留。此外,在UI的层次结构中不会调用OnEnable或OnDisable回调。

但请注意,这不会禁用隐藏UI中的任何MonoBehaviours,因此这些MonoBehaviours仍将接收Unity生命周期回调,例如Update。

为了避免这个问题,将以这种方式禁用的UI上的MonoBehaviours不应该直接实现Unity的生命周期回调,而应该从UI的根GameObject上的“Callback Manager” MonoBehaviour接收它们的回调。只要显示/隐藏UI,就可以通知此“Callback Manager”,并且可以确保生命周期事件根据需要传播或不传播。这个“Callback Manager”模式的进一步解释超出了本指南的范围。

Assigning Event Cameras

如果使用Unity的内置输入管理器以及设置为在World Space 或 Screen Space–Camera模式下渲染的Canvases,则始终分别设置事件相机或渲染相机属性非常重要。 从脚本开始,它始终作为worldCamera属性暴露出来。

如果此属性未设置,Unity UI将通过使用Main Camera tag查找附加到GameObjects的Camera组件来搜索Main Camera。 对于每个World Space或Camera Space的Canvas,此查找至少会发生一次。 由于GameObject.FindWithTag的速度很慢,因此强烈建议所有的World Space和Camera Space的Canvases都在设计时或初始化时分配其Camera属性。

Overlay Canvases不会出现此问题。

UI源代码自定义

UI系统被设计为支持大量的用例。 这种灵活性非常好,但这也意味着在不破坏其他功能的情况下不能轻松完成一些优化。 如果您最终遇到可以通过更改C#UI源代码节省一些CPU周期的情况,可以重新编译UI DLL并覆盖Unity自带的那个。 编译方法记录在Bitbucket仓库的的readme文件中。 确保获得与您的Unity版本相对应的源代码。

但这只能作为最后的手段,因为有一些重要的缺点。 首先,你必须找到一种方法将这个新的DLL分发给开发人员和构建机器。 然后,每次升级Unity时,都必须将您的更改与新的UI源代码合并。 确保你不能扩展现有的类或者编写你自己版本的组件再继续朝这个方向前进

翻译自:https://unity3d.com/cn/learn/tutorials/topics/best-practices/other-ui-optimization-techniques-and-tips?playlist=30089

Pingbacks are open.

Trackbacks
  1. excel dashboards for changing data on 08/03/2019 10:34 p.m. #

    ACLegend's Weblog - Unity UI 优化最佳实践6 其他优化技术和小技巧

  2. excel tips on 08/07/2019 2:59 p.m. #

    ACLegend's Weblog - Unity UI 优化最佳实践6 其他优化技术和小技巧

  3. free download excel dashboard templates on 08/08/2019 3:29 p.m. #

    ACLegend's Weblog - Unity UI 优化最佳实践6 其他优化技术和小技巧

Trackback URL

Comments

23 Comments

  • jonathandf11
    29 May 2019, 07:06 | Reply
    Nude Sex Pics, Sexy Naked Women, Hot Girls Porn http://lesbianpornpics.allproblog.com/?araceli abnormal size penis porn younger girl porn videos anal queens of porn super hot sexy pov porn naked vanessa hudgens porn hub
  • BennieMig
    01 Jun 2019, 09:08 | Reply
    301 Moved Permanently https://www.918online.today/category/pussy888/ - Click here>>>
  • BBWBabehoula
    01 Jun 2019, 19:19 | Reply
    Wow, marvelous weblog structure! How lengthy have you ever been blogging for <a href=https://bbwporn.me>bbw anal porn</a>? you made running a blog glance easy. The whole look of your website is magnificent, let alone the content!
  • dedikser
    24 Jun 2019, 23:43 | Reply
    <a href=https://dedicatet.com/categories/obsuzhdenie-igr-chitov.77/>Обсуждение игр, читов</a>
  • Valyaviefs
    26 Jun 2019, 07:52 | Reply
    beb9 average is price the best site is tablets
  • 시카고가라오케
    30 Jun 2019, 16:32 | Reply
    Hi! I could have sworn I've been to this blog before but after reading through some of the post I realized it's new to me. Anyhow, I'm definitely delighted I found it and I'll be book-marking and checking back often!
  • BrunetteBabehoula
    02 Jul 2019, 15:31 | Reply
    I've learn some just right stuff here. Certainly worth bookmarking for revisiting <a href=https://www.brunette.pro>black brunette porn</a>. I wonder how a lot effort you set to create the sort of great informative web site.
  • rosannayg60
    08 Jul 2019, 00:58 | Reply
    Hot new pictures each day http://meatmarketporn.kanakox.com/?lyndsey old fashioned titty tease porn tube free homemade porn vidieo sexy azz big booty porn hermaphadite teen porn jhonny test hentai porns
  • imeldasx3
    08 Jul 2019, 12:37 | Reply
    Browse over 500 000 of the best porn galleries, daily updated collections http://nonkpornmovies.amandahot.com/?yazmin princess donna porn pj sparxx nurse streaming porn free porn sample videos mature lesbien porn fantastix porn
  • lenoreci1
    11 Jul 2019, 23:17 | Reply
    Hot new pictures each day http://hindiadultmovie.bloglag.com/?elisa british heather porn dexters lab streaming porn mobile black bbw porn woman gets pregnant from 3d porn home made retro porn
  • johnnyaz4
    14 Jul 2019, 08:02 | Reply
    Daily updated super sexy photo galleries http://amyjporn.spankwierporn.kanakox.com/?maia afro porn from 1990 s category porn videos miss cleo porn chanal lace porn star porn traailers
  • katharineos2
    18 Jul 2019, 04:08 | Reply
    Free Porn Pictures and Best HD Sex Photos http://sextoyshardcore.xblognetwork.com/?nya black porn blow jobs classic porn movies trailer torrents porn hub poolside orgy young jocks gay porn celebrity porn 2007 jelsoft enterprises ltd
  • excel dashboards for changing data
    03 Aug 2019, 22:34 | Reply
    ACLegend's Weblog - Unity UI 优化最佳实践6 其他优化技术和小技巧
  • aclegend.org
    04 Aug 2019, 15:28 | Reply
    That is commendable mazuma swop classification incomparably in damaged of victory. aclegend.org http://bit.ly/2NNGp8q
  • Williamwougs
    05 Aug 2019, 13:12 | Reply
    Good day! I am reaching out to you based on a request from a private investor who is looking for a potential investment opportunity in your country. Details of investment proposal will be sent out to you on reading back from you as we deem it necessary to seek for your consent prior to any formal exchange of material information relating to the Investment. I look forward to your earliest response via my private email address. Regards, Gilbert Mboweni Email: g.mboweni@alliedconsults.com D/ Tel:+44 7459 225716
  • Cocktails & Saveurs
    06 Aug 2019, 01:17 | Reply
    Hello There. I found your blog using msn. This is a very well written article. I will be sure to bookmark it and return to read more of your useful info. Thanks for the post. I'll definitely return.
  • Cocktails & Saveurs
    06 Aug 2019, 01:17 | Reply
    Hello There. I found your blog using msn. This is a very well written article. I will be sure to bookmark it and return to read more of your useful info. Thanks for the post. I'll definitely return.
  • excel tips
    07 Aug 2019, 14:59 | Reply
    ACLegend's Weblog - Unity UI 优化最佳实践6 其他优化技术和小技巧
  • Harrissheam
    08 Aug 2019, 04:33 | Reply
    My name is Mr. Steven Albert, I'm a foreign investment management consultant , am representing the interest of Mr. A. S AlSayed and partners www.alsayedgroup.com who is ready to invest in any profitable business with good ROI . I will be glad to hear from you on any potential opportunity for further discussion. Call me on +1 (701) 4842612 or email me on : info@alliedinvestmentservices.org Yours Sincerely, Mr. Steven Albert. Investment Manager.
  • free download excel dashboard templates
    08 Aug 2019, 15:29 | Reply
    ACLegend's Weblog - Unity UI 优化最佳实践6 其他优化技术和小技巧
  • http://rewahadbuy.tk/jxs5
    13 Aug 2019, 18:57 | Reply
    That is an appealing contribution as a implementation to winning. http://teratheme.tk/1pge
  • Herbertslics
    14 Aug 2019, 02:03 | Reply
    As a business you may be using some or other email system - time to upgrade to Google's Business Email System - G Suite. G Suite contains apps like business emails, drive, docs and video/audio conferencing and much more. Review more here: https://protostarcs.com/g-suite Or reach us at Email: need@proerp.cloud or Skype: need@proerp.cloud or WhatsApp: +91 9359453615 see more details about G Suite: https://gsuite.google.co.in/
  • WilliamClild
    18 Aug 2019, 19:10 | Reply
    Please note a seemlysacrifice recompense you. http://unreasenmo.tk/7kft
Post your comment

cancel reply