AdaptivePerformanceEnergyUsageExtensions
Extension methods for IAdaptivePerformance related to energy-usage tracking.
Read time 1 minuteLast updated 12 days ago
Definition
- Type: Class
- Namespace: UnityEngine.AdaptivePerformance
- Assembly: UnityEngine.AdaptivePerformanceModule
public static class AdaptivePerformanceEnergyUsageExtensions
Remarks
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.
The following example acquires the energy-usage control, verifies that the device supports tracking, and tracks energy usage while a component is enabled.
Examples
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(); }}
Static Methods
Method | Description |
|---|---|
| EnergyUsageControl | Returns the energy-usage control for the given Adaptive Performance instance, or |