Create a custom operation mode
Learn to create a custom operation mode.
Read time 3 minutesLast updated a month ago
You can create a custom operation mode to define your own strategy for how Adaptive Performance adjusts application quality.
The built-in operation modes cover the most common goals. Normal mode targets the highest frame rate, while battery mode targets longer battery life. If you need a different strategy, such as a mode for a specific scene or a target thermal budget, you can implement your own operation mode and activate it at runtime.
A custom operation mode is a class that implements the interface. Unlike a custom provider supplies device data, an operation mode decides how Adaptive Performance reacts to that data.
IAdaptivePerformanceModeProviderImplement the mode provider
Create a class that implements . The interface has the following members:
IAdaptivePerformanceModeProviderMember | Description |
|---|---|
| The name of the operation mode. |
| The action to apply in response to the device's thermal state. |
| The action to apply in response to the device's performance state. |
| Called when the mode becomes active. Use it to prepare the Indexer and enable scalers. |
| Called when the mode is replaced. Use it to restore any state you changed. |
| Called every frame while the mode is active. Use it to set the thermal and performance actions and apply them to the scalers. |
To adjust quality from a custom mode, set each scaler's . A value forces the scaler to that level, and returns control of the scaler to the Indexer. takes effect regardless of the scaler state. Only override scalers that are enabled for the current profile and mode. Use to enumerate every registered scaler, including disabled ones, then filter on .
OverrideLevel-1OverrideLevelAdaptivePerformanceIndexer.GetAllRegisteredScalersAdaptivePerformanceScaler.EnabledTo implement a custom operation mode:
- Create a C# class that implements .
IAdaptivePerformanceModeProvider - In , set
ApplyModeActionsandThermalAction, and set thePerformanceActionof the scalers you want to control.OverrideLevel - In , reset the
OnOperationModeEndof those scalers toOverrideLevelto return control to the Indexer.-1
The following example implements a mode that forces all scalers to their maximum level to reduce quality and keep the device cool:
using System.Collections.Generic;using UnityEngine.AdaptivePerformance;public class CoolingOperationMode : IAdaptivePerformanceModeProvider{ public string ModeName => "Cooling"; public StateAction ThermalAction { get; private set; } public StateAction PerformanceAction { get; private set; } readonly List<AdaptivePerformanceScaler> m_Scalers = new List<AdaptivePerformanceScaler>(); public void OnOperationModeStart() { } public void OnOperationModeEnd() { // Return control of every scaler to the Indexer. var indexer = Holder.Instance?.Indexer; if (indexer == null) return; indexer.GetAllRegisteredScalers(ref m_Scalers); foreach (var scaler in m_Scalers) { if (!scaler.Enabled) continue; scaler.OverrideLevel = -1; } } public void ApplyModeActions() { var indexer = Holder.Instance?.Indexer; if (indexer == null) return; ThermalAction = StateAction.Decrease; PerformanceAction = StateAction.Decrease; // Force every enabled scaler to its maximum level to reduce quality. indexer.GetAllRegisteredScalers(ref m_Scalers); foreach (var scaler in m_Scalers) { if (!scaler.Enabled) continue; scaler.OverrideLevel = scaler.MaxLevel; } }}
Activate the custom operation mode
Assign an instance to to activate your custom operation mode. Adaptive Performance calls on the previous mode and on your active mode.
IOperationModeStatus.CurrentOperationalModeProviderOnOperationModeEndOnOperationModeStartFor example:
using UnityEngine;using UnityEngine.AdaptivePerformance;public class ActivateCoolingMode : MonoBehaviour{ void Start() { var ap = Holder.Instance; if (ap == null || !ap.Active) return; ap.OperationModeStatus.CurrentOperationalModeProvider = new CoolingOperationMode(); }}
After you assign the provider, Adaptive Performance calls on your active mode in every frame until you change to another mode.
ApplyModeActions