Version: Unity 6.3 LTS (6000.3)
Language : English
Modifying asset quality with scalers
Use scaler profiles

Create custom scalers

Create custom scalers to automatically adjust quality settings based on device performance.

For more information about scalers, refer to Modifying asset quality with scalers.

To create a custom scaler:

  1. Create a new C# script in your project.
  2. Create a class that inherits from AdaptivePerformanceScaler.
  3. Make sure the class name matches the AdaptivePerformanceScalerSettingsBase name.
  4. Define the scaler’s behavior.

The following example shows a scaler for controlling texture quality:

using UnityEngine;
using UnityEngine.AdaptivePerformance;

public class TextureQualityScaler : AdaptivePerformanceScaler
{
    // Define the default settings for the Adaptive Texture Quality Scaler.
    AdaptivePerformanceScalerSettingsBase m_AdaptiveTextureQualityScaler = new AdaptivePerformanceScalerSettingsBase
    {
        // Make sure this name matches the class name.
        name = "Texture Quality Scaler",
        enabled = false,
        scale = 1.0f,
        visualImpact = ScalerVisualImpact.High,
        target = ScalerTarget.GPU,
        minBound = 0,
        maxBound = 4,
        maxLevel = 4
    };

    int m_DefaultTextureLimit;

    public AdaptivePerformanceScalerSettingsBase AdaptiveTextureQualitySetting
    {
        get { return m_AdaptiveTextureQualityScaler; }
        set { m_AdaptiveTextureQualityScaler = value; }
    }

    protected override void Awake()
    {
        base.Awake();
        ApplyDefaultSetting(AdaptiveTextureQualitySetting);
    }

    protected override void OnDisabled()
    {
        QualitySettings.globalTextureMipmapLimit = m_DefaultTextureLimit;
    }

    protected override void OnEnabled()
    {
        m_DefaultTextureLimit = QualitySettings.globalTextureMipmapLimit;
    }
    // Define the scaler's behavior.
    protected override void OnLevel()
    {
        // Calling ScaleChanged() from the base class will perform the following calculation.
        // float scaleIncrement = (MaxBound - MinBound) / MaxLevel;
        // Scale = scaleIncrement * (MaxLevel - CurrentLevel) + MinBound;

        if (ScaleChanged())
        {
            Debug.Log(Scale);
            QualitySettings.globalTextureMipmapLimit = (int)MaxBound - ((int)(MaxBound * Scale));
        }
    }
}

Additional resources

Modifying asset quality with scalers
Use scaler profiles
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961