このページでは、ランタイム UI のパフォーマンスを向上させる方法について説明します。
You can use usage hints to set how an element is used at runtime. Usage hints can reduce draw calls and avoid geometry regeneration.
You can set the usage hints in UI Builder, UXML, or C#. The following examples set the usage hints to DynamicTransform
:
UXML:
<ui:VisualElement usage-hints="DynamicTransform" />
C#:
visualElement.usageHints = UsageHints.DynamicTransform;
The supported usage hints are:
For more information, see usageHints
and VisualElement.usageHints
.
Some Android devices and the Web platform can’t partially patch index buffers. If your audience uses such devices or if you target the Web platform, UI Toolkit rendering is still functional but performance may be degraded. To avoid performance degradation, don’t animate too many elements at the same time and profile on device.
ビジュアル要素のメッシュテッセレーションを作成するには、計算コストがかかります。要素のサイズ (幅/高さ) が変わるたびに、そのジオメトリは再作成されます。これは、アニメーションや頻繁なサイズ変更において問題となります。
一般的に言って、トランスフォーム とテクスチャは、柔軟性と再利用という点で良い選択ではありません。しかし、アニメーションを行う場合は、より良いパフォーマンスを得るために、以下を行ってください。
テクスチャの変更によって壊れるバッチの数を減らし、良好なパフォーマンスを達成するには、アトラスを使用して、同時に使用されるテクスチャをグループ化します。これは以下のいずれかの方法で実現できます。
動的アトラスを使用してテクスチャをグループ化する場合、ドローコール の回数を制限するために、テクスチャが動的アトラスに入ることを確認します。確認するには、フレームデバッガー を使います。フレームデバッガーは、テクスチャの変化を観察し、バッチが壊れるのを推測するのに役立ちます。
以下の例では、動的アトラスにランタイム UI のすべてのテクスチャが含まれていることを確認します。
動的アトラステクスチャは、指定された最小サイズから開始し、必要に応じて水平または垂直方向に倍増し、指定された最大サイズまで拡大します。アトラスの最小サイズと最大サイズ は、Panel Settings アセットで定義できます。動的アトラスのフィルターを使って、サブテクスチャをアトラスに追加するかどうかを決めることもできます。
フィルターを有効または無効にするには、Panel Settings アセットの Inspector ウィンドウで、Dynamic Atlas Settings > Active Filters ドロップダウンリストからオプションを選択します。
カスタムフィルターをPanelSettings.dynamicAtlasSettings.customFilter
に割り当て、グローバル、またはカスタムテクスチャ単位で、制限を加えたり緩めたりできます。
以下のカスタムフィルターの例は、大きなテクスチャに対しSize フィルターの適用を避け、一方、他のテクスチャに対して、Size フィルターをアクティブにしたままにします。
using UnityEngine;
using UnityEngine.UIElements;
class MyCustomFilter : MonoBehaviour
{
public PanelSettings panelSettings;
public Texture2D largeTexture;
void OnEnable() { panelSettings.dynamicAtlasSettings.customFilter = Filter; }
void OnDisable() { panelSettings.dynamicAtlasSettings.customFilter = null; }
bool Filter(Texture2D texture, ref DynamicAtlasFilters filtersToApply)
{
if (texture == largeTexture)
{
// Disable the Size check for this one.
filtersToApply &= ~DynamicAtlasFilters.Size;
}
return true;
}
}
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.