Version: Unity 6.7 Beta (6000.7)
LanguageEnglish
  • C#

AdaptivePerformanceEnergyUsageExtensions

class in UnityEngine.AdaptivePerformance

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

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(); } }

Static Methods

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.