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:
AdaptivePerformanceScaler
.AdaptivePerformanceScalerSettingsBase
name.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));
}
}
}