class in UnityEngine.AdaptivePerformance
Extension methods for IAdaptivePerformance related to energy-usage tracking.
Call AdaptivePerformanceEnergyUsageExtensions.EnergyUsageControl on an Adaptive Performance instance, such as
Holder.Instance, to reach the IEnergyUsageControl interface that starts, resets,
and stops energy-usage tracking.
The extension returns null when the active Adaptive Performance implementation doesn't provide energy-usage
tracking at all, so check the result before you use it. A non-null result doesn't guarantee that the device
itself can report energy: check IEnergyUsageControl.EnergyUsageTrackingSupported as well.
Additional resources: IAdaptivePerformance, IEnergyUsageControl, EnergyUsage
The following example acquires the energy-usage control, verifies that the device supports tracking, and
tracks energy usage while a component is enabled.
using UnityEngine; using UnityEngine.AdaptivePerformance;
public class EnergyUsageControlExample : MonoBehaviour { IEnergyUsageControl energyUsageControl;
void OnEnable() { IAdaptivePerformance adaptivePerformance = Holder.Instance; if (adaptivePerformance == null || !adaptivePerformance.Initialized) return;
// The result is null when this Adaptive Performance implementation has no energy-usage tracking. energyUsageControl = adaptivePerformance.EnergyUsageControl(); if (energyUsageControl == null) { Debug.Log("This Adaptive Performance implementation doesn't provide energy-usage tracking."); return; }
// A non-null control doesn't guarantee that this device has usable power monitors. if (!energyUsageControl.EnergyUsageTrackingSupported) { Debug.Log("This device doesn't support energy-usage tracking."); return; }
energyUsageControl.StartEnergyUsageTracking(); }
void OnDisable() { energyUsageControl?.StopEnergyUsageTracking(); } }
| Method | Description |
|---|---|
| EnergyUsageControl | Returns the energy-usage control for the given Adaptive Performance instance, or null if the active implementation does not support energy-usage tracking. |