暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IAdaptivePerformance.cs 9.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. using System.ComponentModel;
  2. namespace UnityEngine.AdaptivePerformance
  3. {
  4. /// <summary>
  5. /// Constants used by Adaptive Performance.
  6. /// </summary>
  7. public static class Constants
  8. {
  9. /// <summary>
  10. /// The minimum temperature level.
  11. /// See <see cref="ThermalMetrics.TemperatureLevel"/>.
  12. /// </summary>
  13. /// <value>0.0</value>
  14. public const float MinTemperatureLevel = 0.0f;
  15. /// <summary>
  16. /// The maximum temperature level.
  17. /// See <see cref="ThermalMetrics.TemperatureLevel"/>.
  18. /// </summary>
  19. /// <value>1.0</value>
  20. public const float MaxTemperatureLevel = 1.0f;
  21. /// <summary>
  22. /// The minimum CPU level.
  23. /// Used by <see cref="IDevicePerformanceControl.CpuLevel"/> and <see cref="PerformanceMetrics.CurrentCpuLevel"/>.
  24. /// </summary>
  25. /// <value>0</value>
  26. public const int MinCpuPerformanceLevel = 0;
  27. /// <summary>
  28. /// The minimum GPU level.
  29. /// Used by <see cref="IDevicePerformanceControl.GpuLevel"/> and <see cref="PerformanceMetrics.CurrentGpuLevel"/>.
  30. /// </summary>
  31. /// <value>0</value>
  32. public const int MinGpuPerformanceLevel = 0;
  33. /// <summary>
  34. /// UnknownPerformanceLevel is the value of <see cref="IDevicePerformanceControl.GpuLevel"/>, <see cref="PerformanceMetrics.CurrentGpuLevel"/>,
  35. /// <see cref="IDevicePerformanceControl.CpuLevel"/>, and <see cref="PerformanceMetrics.CurrentCpuLevel"/> if the current performance level is unknown.
  36. /// This can happen when AdaptivePerformance is not supported or when the device is in throttling state (see <see cref="WarningLevel.Throttling"/>).
  37. /// </summary>
  38. /// <value>-1</value>
  39. public const int UnknownPerformanceLevel = -1;
  40. /// <summary>
  41. /// The number of past frames that are considered to calculate average frame times.
  42. /// </summary>
  43. /// <value>100</value>
  44. public const int DefaultAverageFrameCount = 100;
  45. }
  46. /// <summary>
  47. /// The main interface to access Adaptive Performance.
  48. /// None of the properties in this interface change after startup.
  49. /// This means the references returned by the properties may be cached by the user.
  50. /// </summary>
  51. public interface IAdaptivePerformance
  52. {
  53. /// <summary>
  54. /// Returns true if Adaptive Performance was initialized successfully, false otherwise.
  55. /// This means that Adaptive Performance is enabled in StartupSettings and the application runs on a device that supports Adaptive Performance.
  56. /// </summary>
  57. /// <value>True when Adaptive Performance is initialized, running and available, false otherwise.</value>
  58. bool Initialized { get; }
  59. /// <summary>
  60. /// Returns true if Adaptive Performance was initialized and is actively running, false otherwise.
  61. /// This means that Adaptive Performance is enabled in StartupSettings.
  62. /// </summary>
  63. /// <value>True when Adaptive Performance is initialized and available, false otherwise.</value>
  64. bool Active { get; }
  65. /// <summary>
  66. /// Access thermal status information of the device.
  67. /// </summary>
  68. /// <value>Interface to access thermal status information of the device.</value>
  69. IThermalStatus ThermalStatus { get; }
  70. /// <summary>
  71. /// Access performance status information of the device and your application.
  72. /// </summary>
  73. /// <value>Interface to access performance status information of the device and your application.</value>
  74. IPerformanceStatus PerformanceStatus { get; }
  75. /// <summary>
  76. /// Control CPU and GPU performance of the device.
  77. /// </summary>
  78. /// <value>Interface to control CPU and GPU performance levels of the device.</value>
  79. IDevicePerformanceControl DevicePerformanceControl { get; }
  80. /// <summary>
  81. /// Access performance mode status information of the device.
  82. /// </summary>
  83. /// <value>Interface to access performance mode status information of the device.</value>
  84. IPerformanceModeStatus PerformanceModeStatus { get; }
  85. /// <summary>
  86. /// Access to development (logging) settings.
  87. /// </summary>
  88. /// <value>Interface to control CPU and GPU performance levels of the device.</value>
  89. IDevelopmentSettings DevelopmentSettings { get; }
  90. /// <summary>
  91. /// Access to the Indexer system. See <see cref="AdaptivePerformanceIndexer"/>
  92. /// </summary>
  93. /// <value>Interface to scalers that are active and their associated settings.</value>
  94. AdaptivePerformanceIndexer Indexer { get; }
  95. /// <summary>
  96. /// Access to the Settings. See <see cref="IAdaptivePerformanceSettings"/>.
  97. /// </summary>
  98. /// <value>Interface to settings that are loaded from the provider settings object during startup.</value>
  99. IAdaptivePerformanceSettings Settings { get; }
  100. /// <summary>
  101. /// Access to the active Subsystem. See <see cref="Provider.AdaptivePerformanceSubsystem"/>.
  102. /// </summary>
  103. /// <value>Reference to active Subsystem.</value>
  104. Provider.AdaptivePerformanceSubsystem Subsystem { get; }
  105. /// <summary>
  106. /// List of supported Features by the loaded provider. See <see cref="Provider.Feature"/>.
  107. /// </summary>
  108. /// <param name="feature">The feature in question. See <see cref="Provider.Feature"/>.</param>
  109. /// <returns>True if the requested feature is supported, false otherwise.</returns>
  110. bool SupportedFeature(Provider.Feature feature);
  111. /// <summary>
  112. /// Initiates the initialization process for Adaptive Performance by attempting to initialize the loaders. When
  113. /// this completes successfully, <see cref="Initialized"/> will be <c>true</c>. Adaptive Performance can now be
  114. /// started by calling the <see cref="StartAdaptivePerformance"/> method.
  115. /// </summary>
  116. void InitializeAdaptivePerformance();
  117. /// <summary>
  118. /// Attempts to start Adaptive Performance by requesting the active loader and all subsystems to start. When
  119. /// this completes successfully, <see cref="Active"/> will be <c>true</c>.
  120. /// </summary>
  121. void StartAdaptivePerformance();
  122. /// <summary>
  123. /// Attempts to stop Adaptive Performance by requesting the active loader and all subsystems to stop. When
  124. /// this completes successfully, <see cref="Active"/> will be <c>false</c>.
  125. /// </summary>
  126. void StopAdaptivePerformance();
  127. /// <summary>
  128. /// Stops Adaptive Performance (if still running) and initiates the tear down process. When this completes
  129. /// successfully, <see cref="Initialized"/> will be <c>false</c>.
  130. /// </summary>
  131. void DeinitializeAdaptivePerformance();
  132. }
  133. /// <summary>
  134. /// Global access to the default Adaptive Performance interface and lifecycle management controls.
  135. /// </summary>
  136. public static class Holder
  137. {
  138. static IAdaptivePerformance m_Instance;
  139. /// <summary>
  140. /// Global access to the default Adaptive Performance interface to access the main manager object.
  141. /// </summary>
  142. public static IAdaptivePerformance Instance
  143. {
  144. get { return m_Instance; }
  145. internal set
  146. {
  147. if(value == null)
  148. LifecycleEventHandler?.Invoke(m_Instance, LifecycleChangeType.Destroyed);
  149. else
  150. LifecycleEventHandler?.Invoke(value, LifecycleChangeType.Created);
  151. m_Instance = value;
  152. }
  153. }
  154. /// <summary>
  155. /// Create and attach the Adaptive Performance to the scene and initiate the startup process for the provider.
  156. /// After initialization is complete, <see cref="Instance"/> is made available.
  157. /// <remarks>
  158. /// Should only be used when "Initialize on Startup" is disabled.
  159. /// </remarks>
  160. /// </summary>
  161. public static void Initialize()
  162. {
  163. if (Instance != null)
  164. return;
  165. AdaptivePerformanceInitializer.Initialize();
  166. if (Instance != null)
  167. Instance.InitializeAdaptivePerformance();
  168. }
  169. /// <summary>
  170. /// Stops Adaptive Performance (if still running) and initiates the tear down process. Once complete,
  171. /// <see cref="Instance"/> is no longer available. All Adaptive Performance objects are removed from the
  172. /// scene.
  173. /// </summary>
  174. public static void Deinitialize()
  175. {
  176. if (Instance != null)
  177. Instance.DeinitializeAdaptivePerformance();
  178. AdaptivePerformanceInitializer.Deinitialize();
  179. Instance = null;
  180. }
  181. /// <summary>
  182. /// Subscribe to Adaptive Performance lifecycle events which are sent when the <see cref="Instance"/>
  183. /// value changes.
  184. /// </summary>
  185. public static event LifecycleEventHandler LifecycleEventHandler;
  186. }
  187. /// <summary>
  188. /// Adaptive Performance lifecycle events which are sent when the lifecycle of <see cref="IAdaptivePerformance"/>
  189. /// is changed.
  190. /// </summary>
  191. /// <param name="instance"><see cref="IAdaptivePerformance"/> instance.</param>
  192. /// <param name="changeType">Type of lifecycle change on <c>instance</c></param>
  193. public delegate void LifecycleEventHandler(IAdaptivePerformance instance, LifecycleChangeType changeType);
  194. /// <summary>
  195. /// Types of Adaptive Performance lifecycle changes.
  196. /// </summary>
  197. public enum LifecycleChangeType
  198. {
  199. /// <summary>
  200. /// Adaptive Performance was created.
  201. /// </summary>
  202. Created,
  203. /// <summary>
  204. /// Adaptive Performance was destroyed.
  205. /// </summary>
  206. Destroyed
  207. }
  208. }