using System.ComponentModel;
namespace UnityEngine.AdaptivePerformance
{
///
/// Constants used by Adaptive Performance.
///
public static class Constants
{
///
/// The minimum temperature level.
/// See .
///
/// 0.0
public const float MinTemperatureLevel = 0.0f;
///
/// The maximum temperature level.
/// See .
///
/// 1.0
public const float MaxTemperatureLevel = 1.0f;
///
/// The minimum CPU level.
/// Used by and .
///
/// 0
public const int MinCpuPerformanceLevel = 0;
///
/// The minimum GPU level.
/// Used by and .
///
/// 0
public const int MinGpuPerformanceLevel = 0;
///
/// UnknownPerformanceLevel is the value of , ,
/// , and if the current performance level is unknown.
/// This can happen when AdaptivePerformance is not supported or when the device is in throttling state (see ).
///
/// -1
public const int UnknownPerformanceLevel = -1;
///
/// The number of past frames that are considered to calculate average frame times.
///
/// 100
public const int DefaultAverageFrameCount = 100;
}
///
/// The main interface to access Adaptive Performance.
/// None of the properties in this interface change after startup.
/// This means the references returned by the properties may be cached by the user.
///
public interface IAdaptivePerformance
{
///
/// Returns true if Adaptive Performance was initialized successfully, false otherwise.
/// This means that Adaptive Performance is enabled in StartupSettings and the application runs on a device that supports Adaptive Performance.
///
/// True when Adaptive Performance is initialized, running and available, false otherwise.
bool Initialized { get; }
///
/// Returns true if Adaptive Performance was initialized and is actively running, false otherwise.
/// This means that Adaptive Performance is enabled in StartupSettings.
///
/// True when Adaptive Performance is initialized and available, false otherwise.
bool Active { get; }
///
/// Access thermal status information of the device.
///
/// Interface to access thermal status information of the device.
IThermalStatus ThermalStatus { get; }
///
/// Access performance status information of the device and your application.
///
/// Interface to access performance status information of the device and your application.
IPerformanceStatus PerformanceStatus { get; }
///
/// Control CPU and GPU performance of the device.
///
/// Interface to control CPU and GPU performance levels of the device.
IDevicePerformanceControl DevicePerformanceControl { get; }
///
/// Access performance mode status information of the device.
///
/// Interface to access performance mode status information of the device.
IPerformanceModeStatus PerformanceModeStatus { get; }
///
/// Access to development (logging) settings.
///
/// Interface to control CPU and GPU performance levels of the device.
IDevelopmentSettings DevelopmentSettings { get; }
///
/// Access to the Indexer system. See
///
/// Interface to scalers that are active and their associated settings.
AdaptivePerformanceIndexer Indexer { get; }
///
/// Access to the Settings. See .
///
/// Interface to settings that are loaded from the provider settings object during startup.
IAdaptivePerformanceSettings Settings { get; }
///
/// Access to the active Subsystem. See .
///
/// Reference to active Subsystem.
Provider.AdaptivePerformanceSubsystem Subsystem { get; }
///
/// List of supported Features by the loaded provider. See .
///
/// The feature in question. See .
/// True if the requested feature is supported, false otherwise.
bool SupportedFeature(Provider.Feature feature);
///
/// Initiates the initialization process for Adaptive Performance by attempting to initialize the loaders. When
/// this completes successfully, will be true. Adaptive Performance can now be
/// started by calling the method.
///
void InitializeAdaptivePerformance();
///
/// Attempts to start Adaptive Performance by requesting the active loader and all subsystems to start. When
/// this completes successfully, will be true.
///
void StartAdaptivePerformance();
///
/// Attempts to stop Adaptive Performance by requesting the active loader and all subsystems to stop. When
/// this completes successfully, will be false.
///
void StopAdaptivePerformance();
///
/// Stops Adaptive Performance (if still running) and initiates the tear down process. When this completes
/// successfully, will be false.
///
void DeinitializeAdaptivePerformance();
}
///
/// Global access to the default Adaptive Performance interface and lifecycle management controls.
///
public static class Holder
{
static IAdaptivePerformance m_Instance;
///
/// Global access to the default Adaptive Performance interface to access the main manager object.
///
public static IAdaptivePerformance Instance
{
get { return m_Instance; }
internal set
{
if(value == null)
LifecycleEventHandler?.Invoke(m_Instance, LifecycleChangeType.Destroyed);
else
LifecycleEventHandler?.Invoke(value, LifecycleChangeType.Created);
m_Instance = value;
}
}
///
/// Create and attach the Adaptive Performance to the scene and initiate the startup process for the provider.
/// After initialization is complete, is made available.
///
/// Should only be used when "Initialize on Startup" is disabled.
///
///
public static void Initialize()
{
if (Instance != null)
return;
AdaptivePerformanceInitializer.Initialize();
if (Instance != null)
Instance.InitializeAdaptivePerformance();
}
///
/// Stops Adaptive Performance (if still running) and initiates the tear down process. Once complete,
/// is no longer available. All Adaptive Performance objects are removed from the
/// scene.
///
public static void Deinitialize()
{
if (Instance != null)
Instance.DeinitializeAdaptivePerformance();
AdaptivePerformanceInitializer.Deinitialize();
Instance = null;
}
///
/// Subscribe to Adaptive Performance lifecycle events which are sent when the
/// value changes.
///
public static event LifecycleEventHandler LifecycleEventHandler;
}
///
/// Adaptive Performance lifecycle events which are sent when the lifecycle of
/// is changed.
///
/// instance.
/// Type of lifecycle change on instance
public delegate void LifecycleEventHandler(IAdaptivePerformance instance, LifecycleChangeType changeType);
///
/// Types of Adaptive Performance lifecycle changes.
///
public enum LifecycleChangeType
{
///
/// Adaptive Performance was created.
///
Created,
///
/// Adaptive Performance was destroyed.
///
Destroyed
}
}