このページでは、ランタイム UI のパフォーマンスを向上させる方法について説明します。
usageHints
を使って、ランタイムに要素がどのように使われるかを設定することができます。そうすれば、それに応じてデータストレージを最適化することができます。以下はその例です。
visualElement.usageHints = UsageHints.DynamicTransform;
以下の表は、どの要素にどのプロパティを使うかを、例を挙げて説明したものです。
Elements with the following | Use this | Example |
---|---|---|
Frequent changes to their position or transform | UsageHint.DynamicTransform |
If you change style.left , style.top , or style.position for an element, set the UsageHint.DynamicTransform on that element. |
Many DynamicTransform child elements that often change positions or transforms |
UsageHint.GroupTransform |
In ShaderGraph, each node uses DynamicTransform , set UsageHint.GroupTransform on the view container. |
A built-in style color being animated | UsageHint.DynamicColor |
If you change style.backgroundColor , style.unityBackgroundImageTintColor , or any border colors for an element, such as style.borderLeftColor , set the UsageHint.DynamicColor on that element. |
一部の Android デバイスと WebGL は、インデックスバッファに部分的にパッチを適用できません。ユーザーがそのようなデバイスを使用している場合、または WebGL をターゲットにする場合、UI Toolkit のレンダリングは機能しますが、パフォーマンスが低下する可能性があります。パフォーマンスの低下を避けるには、同時にあまり多くの要素をアニメーション化せず、デバイスのプロファイリング を行います。
ビジュアル要素のメッシュテッセレーションを作成するには、計算コストがかかります。要素のサイズ (幅/高さ) が変わるたびに、そのジオメトリは再作成されます。これは、アニメーションや頻繁なサイズ変更において問題となります。
一般的に言って、トランスフォーム とテクスチャは、柔軟性と再利用という点で良い選択ではありません。しかし、アニメーションを行う場合は、より良いパフォーマンスを得るために、以下を行ってください。
テクスチャの変更によって壊れるバッチの数を減らし、良好なパフォーマンスを達成するには、アトラスを使用して、同時に使用されるテクスチャをグループ化します。これは以下のいずれかの方法で実現できます。
動的アトラスを使用してテクスチャをグループ化する場合、ドローコール の回数を制限するために、テクスチャが動的アトラスに入ることを確認します。確認するには、フレームデバッガー を使います。フレームデバッガーは、テクスチャの変化を観察し、バッチが壊れるのを推測するのに役立ちます。
以下の例では、動的アトラスにランタイム 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.