Keine Beschreibung
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

IAdaptivePerformanceSettings.cs 41KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Reflection;
  5. using UnityEditor;
  6. using UnityEngine;
  7. namespace UnityEngine.AdaptivePerformance
  8. {
  9. // Changes to tooltips in this file should be reflected in ProviderSettingsEditor as well.
  10. /// <summary>
  11. /// Settings of indexer system.
  12. /// </summary>
  13. [System.Serializable]
  14. public class AdaptivePerformanceIndexerSettings
  15. {
  16. const string m_FeatureName = "Indexer";
  17. [SerializeField, Tooltip("Active")]
  18. bool m_Active = true;
  19. /// <summary>
  20. /// Returns true if Indexer was active, false otherwise.
  21. /// </summary>
  22. public bool active
  23. {
  24. get { return m_Active; }
  25. set
  26. {
  27. if (m_Active == value)
  28. return;
  29. m_Active = value;
  30. AdaptivePerformanceAnalytics.SendAdaptiveFeatureUpdateEvent(m_FeatureName, m_Active);
  31. }
  32. }
  33. [SerializeField, Tooltip("Thermal Action Delay")]
  34. float m_ThermalActionDelay = 10;
  35. /// <summary>
  36. /// Delay after any scaler is applied or unapplied because of thermal state.
  37. /// </summary>
  38. public float thermalActionDelay
  39. {
  40. get { return m_ThermalActionDelay; }
  41. set { m_ThermalActionDelay = value; }
  42. }
  43. [SerializeField, Tooltip("Performance Action Delay")]
  44. float m_PerformanceActionDelay = 4;
  45. /// <summary>
  46. /// Delay after any scaler is applied or unapplied because of performance state.
  47. /// </summary>
  48. public float performanceActionDelay
  49. {
  50. get { return m_PerformanceActionDelay; }
  51. set { m_PerformanceActionDelay = value; }
  52. }
  53. }
  54. /// <summary>
  55. /// Scaler profiles are used to combine all settings of scalers into one profile to be able to change the settings of each scaler at once.
  56. /// </summary>
  57. [System.Serializable]
  58. public class AdaptivePerformanceScalerProfile : AdaptivePerformanceScalerSettings
  59. {
  60. /// <summary>
  61. /// Name of the Scaler Profile. Used to find profiles and switch them during runtime.
  62. /// </summary>
  63. public string Name
  64. {
  65. get { return m_Name; }
  66. set { m_Name = value; }
  67. }
  68. [SerializeField, Tooltip("Name of the scaler profile.")]
  69. string m_Name = "Default Scaler Profile";
  70. }
  71. /// <summary>
  72. /// Settings of indexer system.
  73. /// </summary>
  74. [System.Serializable]
  75. public class AdaptivePerformanceScalerSettings
  76. {
  77. /// <summary>
  78. /// Apply existing external settings to a scaler to override the existing settings.
  79. /// </summary>
  80. /// <param name="settings">Provide existing settings to replace the default settings.</param>
  81. public void ApplySettings(AdaptivePerformanceScalerSettings settings)
  82. {
  83. if (settings == null)
  84. return;
  85. ApplySettingsBase(AdaptiveFramerate, settings.AdaptiveFramerate);
  86. ApplySettingsBase(AdaptiveBatching, settings.AdaptiveBatching);
  87. ApplySettingsBase(AdaptiveLOD, settings.AdaptiveLOD);
  88. ApplySettingsBase(AdaptiveLut, settings.AdaptiveLut);
  89. ApplySettingsBase(AdaptiveMSAA, settings.AdaptiveMSAA);
  90. ApplySettingsBase(AdaptiveResolution, settings.AdaptiveResolution);
  91. ApplySettingsBase(AdaptiveShadowCascade, settings.AdaptiveShadowCascade);
  92. ApplySettingsBase(AdaptiveShadowDistance, settings.AdaptiveShadowDistance);
  93. ApplySettingsBase(AdaptiveShadowmapResolution, settings.AdaptiveShadowmapResolution);
  94. ApplySettingsBase(AdaptiveShadowQuality, settings.AdaptiveShadowQuality);
  95. ApplySettingsBase(AdaptiveTransparency, settings.AdaptiveTransparency);
  96. ApplySettingsBase(AdaptiveSorting, settings.AdaptiveSorting);
  97. ApplySettingsBase(AdaptiveViewDistance, settings.AdaptiveViewDistance);
  98. ApplySettingsBase(AdaptivePhysics, settings.AdaptivePhysics);
  99. ApplySettingsBase(AdaptiveLayerCulling, settings.AdaptiveLayerCulling);
  100. ApplySettingsBase(AdaptiveDecals, settings.AdaptiveDecals);
  101. }
  102. void ApplySettingsBase(AdaptivePerformanceScalerSettingsBase destination, AdaptivePerformanceScalerSettingsBase sources)
  103. {
  104. destination.enabled = sources.enabled;
  105. destination.scale = sources.scale;
  106. destination.visualImpact = sources.visualImpact;
  107. destination.target = sources.target;
  108. destination.minBound = sources.minBound;
  109. destination.maxBound = sources.maxBound;
  110. destination.maxLevel = sources.maxLevel;
  111. }
  112. [SerializeField, Tooltip("Settings for a scaler used by the Indexer to adjust the application update rate using Application.TargetFramerate")]
  113. AdaptivePerformanceScalerSettingsBase m_AdaptiveFramerate = new AdaptivePerformanceScalerSettingsBase
  114. {
  115. name = "Adaptive Framerate",
  116. enabled = false,
  117. scale = 1.0f,
  118. visualImpact = ScalerVisualImpact.High,
  119. target = ScalerTarget.CPU | ScalerTarget.GPU | ScalerTarget.FillRate,
  120. minBound = 15,
  121. maxBound = 60,
  122. maxLevel = 60 - 15
  123. };
  124. /// <summary>
  125. /// A scaler setting used by <see cref="AdaptivePerformanceIndexer"/> to adjust the application update rate using <see cref="Application.targetFrameRate"/>.
  126. /// </summary>
  127. public AdaptivePerformanceScalerSettingsBase AdaptiveFramerate
  128. {
  129. get { return m_AdaptiveFramerate; }
  130. set { m_AdaptiveFramerate = value; }
  131. }
  132. [SerializeField, Tooltip("Settings for a scaler used by the Indexer to adjust the resolution of all render targets that allow dynamic resolution.")]
  133. AdaptivePerformanceScalerSettingsBase m_AdaptiveResolution = new AdaptivePerformanceScalerSettingsBase
  134. {
  135. name = "Adaptive Resolution",
  136. enabled = false,
  137. scale = 1.0f,
  138. visualImpact = ScalerVisualImpact.Low,
  139. target = ScalerTarget.FillRate | ScalerTarget.GPU,
  140. maxLevel = 9,
  141. minBound = 0.5f,
  142. maxBound = 1,
  143. };
  144. /// <summary>
  145. /// A scaler setting used by <see cref="AdaptivePerformanceIndexer"/> to adjust the resolution of all render targets that allow dynamic resolution.
  146. /// </summary>
  147. public AdaptivePerformanceScalerSettingsBase AdaptiveResolution
  148. {
  149. get { return m_AdaptiveResolution; }
  150. set { m_AdaptiveResolution = value; }
  151. }
  152. [SerializeField, Tooltip("Settings for a scaler used by the Indexer to control if dynamic batching is enabled.")]
  153. AdaptivePerformanceScalerSettingsBase m_AdaptiveBatching = new AdaptivePerformanceScalerSettingsBase
  154. {
  155. name = "Adaptive Batching",
  156. enabled = false,
  157. scale = 1,
  158. visualImpact = ScalerVisualImpact.Medium,
  159. target = ScalerTarget.CPU,
  160. maxLevel = 1,
  161. minBound = 0,
  162. maxBound = 1,
  163. };
  164. /// <summary>
  165. /// A scaler setting used by <see cref="AdaptivePerformanceIndexer"/> to control if dynamic batching is enabled.
  166. /// </summary>
  167. public AdaptivePerformanceScalerSettingsBase AdaptiveBatching
  168. {
  169. get { return m_AdaptiveBatching; }
  170. set { m_AdaptiveBatching = value; }
  171. }
  172. [SerializeField, Tooltip("Settings for a scaler used by the Indexer for adjusting at what distance LODs are switched.")]
  173. AdaptivePerformanceScalerSettingsBase m_AdaptiveLOD = new AdaptivePerformanceScalerSettingsBase
  174. {
  175. name = "Adaptive LOD",
  176. enabled = false,
  177. scale = 1,
  178. visualImpact = ScalerVisualImpact.High,
  179. target = ScalerTarget.GPU,
  180. maxLevel = 3,
  181. minBound = 0.4f,
  182. maxBound = 1,
  183. };
  184. /// <summary>
  185. /// A scaler setting used by <see cref="AdaptivePerformanceIndexer"/> for adjusting at what distance LODs are switched.
  186. /// </summary>
  187. public AdaptivePerformanceScalerSettingsBase AdaptiveLOD
  188. {
  189. get { return m_AdaptiveLOD; }
  190. set { m_AdaptiveLOD = value; }
  191. }
  192. [SerializeField, Tooltip("Settings for a scaler used by the Indexer to adjust the size of the palette used for color grading in URP.")]
  193. AdaptivePerformanceScalerSettingsBase m_AdaptiveLut = new AdaptivePerformanceScalerSettingsBase
  194. {
  195. name = "Adaptive Lut",
  196. enabled = false,
  197. scale = 1,
  198. visualImpact = ScalerVisualImpact.Medium,
  199. target = ScalerTarget.GPU | ScalerTarget.CPU,
  200. maxLevel = 1,
  201. minBound = 0,
  202. maxBound = 1,
  203. };
  204. /// <summary>
  205. /// A scaler setting used by <see cref="AdaptivePerformanceIndexer"/> to adjust the size of the palette used for color grading in URP.
  206. /// </summary>
  207. public AdaptivePerformanceScalerSettingsBase AdaptiveLut
  208. {
  209. get { return m_AdaptiveLut; }
  210. set { m_AdaptiveLut = value; }
  211. }
  212. [SerializeField, Tooltip("Settings for a scaler used by the Indexer to adjust the level of antialiasing.")]
  213. AdaptivePerformanceScalerSettingsBase m_AdaptiveMSAA = new AdaptivePerformanceScalerSettingsBase
  214. {
  215. name = "Adaptive MSAA",
  216. enabled = false,
  217. scale = 1,
  218. visualImpact = ScalerVisualImpact.Medium,
  219. target = ScalerTarget.GPU | ScalerTarget.FillRate,
  220. maxLevel = 2,
  221. minBound = 0,
  222. maxBound = 1,
  223. };
  224. /// <summary>
  225. /// A scaler setting used by <see cref="AdaptivePerformanceIndexer"/> to adjust the level of antialiasing.
  226. /// </summary>
  227. public AdaptivePerformanceScalerSettingsBase AdaptiveMSAA
  228. {
  229. get { return m_AdaptiveMSAA; }
  230. set { m_AdaptiveMSAA = value; }
  231. }
  232. [SerializeField, Tooltip("Settings for a scaler used by the Indexer to adjust the number of shadow cascades to be used.")]
  233. AdaptivePerformanceScalerSettingsBase m_AdaptiveShadowCascade = new AdaptivePerformanceScalerSettingsBase
  234. {
  235. name = "Adaptive Shadow Cascade",
  236. enabled = false,
  237. scale = 1,
  238. visualImpact = ScalerVisualImpact.Medium,
  239. target = ScalerTarget.GPU | ScalerTarget.CPU,
  240. maxLevel = 2,
  241. minBound = 0,
  242. maxBound = 1,
  243. };
  244. const string obsoleteMsg = "AdaptiveShadowCascades has been renamed. Please use AdaptiveShadowCascade. (UnityUpgradable) -> AdaptiveShadowCascade";
  245. /// <summary>
  246. /// Obsolete: Please use <see cref="AdaptiveShadowCascade"/>.
  247. /// </summary>
  248. [Obsolete(obsoleteMsg, false)] // ap-obsolete-001 - once removed, ensure all instances of ap-obsolete-001 are removed
  249. public AdaptivePerformanceScalerSettingsBase AdaptiveShadowCascades => AdaptiveShadowCascade;
  250. /// <summary>
  251. /// A scaler setting used by <see cref="AdaptivePerformanceIndexer"/> to adjust the number of shadow cascades to be used.
  252. /// </summary>
  253. public AdaptivePerformanceScalerSettingsBase AdaptiveShadowCascade
  254. {
  255. get { return m_AdaptiveShadowCascade; }
  256. set { m_AdaptiveShadowCascade = value; }
  257. }
  258. [SerializeField, Tooltip("Settings for a scaler used by the Indexer to change the distance at which shadows are rendered.")]
  259. AdaptivePerformanceScalerSettingsBase m_AdaptiveShadowDistance = new AdaptivePerformanceScalerSettingsBase
  260. {
  261. name = "Adaptive Shadow Distance",
  262. enabled = false,
  263. scale = 1,
  264. visualImpact = ScalerVisualImpact.Low,
  265. target = ScalerTarget.GPU,
  266. maxLevel = 3,
  267. minBound = 0.15f,
  268. maxBound = 1,
  269. };
  270. /// <summary>
  271. /// A scaler setting used by <see cref="AdaptivePerformanceIndexer"/> to change the distance at which shadows are rendered.
  272. /// </summary>
  273. public AdaptivePerformanceScalerSettingsBase AdaptiveShadowDistance
  274. {
  275. get { return m_AdaptiveShadowDistance; }
  276. set { m_AdaptiveShadowDistance = value; }
  277. }
  278. [SerializeField, Tooltip("Settings for a scaler used by the Indexer to adjust the resolution of shadow maps.")]
  279. AdaptivePerformanceScalerSettingsBase m_AdaptiveShadowmapResolution = new AdaptivePerformanceScalerSettingsBase
  280. {
  281. name = "Adaptive Shadowmap Resolution",
  282. enabled = false,
  283. scale = 1,
  284. visualImpact = ScalerVisualImpact.Low,
  285. target = ScalerTarget.GPU,
  286. maxLevel = 3,
  287. minBound = 0.15f,
  288. maxBound = 1,
  289. };
  290. /// <summary>
  291. /// A scaler setting used by <see cref="AdaptivePerformanceIndexer"/> to adjust the resolution of shadow maps.
  292. /// </summary>
  293. public AdaptivePerformanceScalerSettingsBase AdaptiveShadowmapResolution
  294. {
  295. get { return m_AdaptiveShadowmapResolution; }
  296. set { m_AdaptiveShadowmapResolution = value; }
  297. }
  298. [SerializeField, Tooltip("Settings for a scaler used by the Indexer to adjust the quality of shadows.")]
  299. AdaptivePerformanceScalerSettingsBase m_AdaptiveShadowQuality = new AdaptivePerformanceScalerSettingsBase
  300. {
  301. name = "Adaptive Shadow Quality",
  302. enabled = false,
  303. scale = 1,
  304. visualImpact = ScalerVisualImpact.High,
  305. target = ScalerTarget.GPU | ScalerTarget.CPU,
  306. maxLevel = 3,
  307. minBound = 0,
  308. maxBound = 1,
  309. };
  310. /// <summary>
  311. /// A scaler setting used by <see cref="AdaptivePerformanceIndexer"/> to adjust the quality of shadows.
  312. /// </summary>
  313. public AdaptivePerformanceScalerSettingsBase AdaptiveShadowQuality
  314. {
  315. get { return m_AdaptiveShadowQuality; }
  316. set { m_AdaptiveShadowQuality = value; }
  317. }
  318. [SerializeField, Tooltip("Settings for a scaler used by the Indexer to change if objects in the scene are sorted by depth before rendering to reduce overdraw.")]
  319. AdaptivePerformanceScalerSettingsBase m_AdaptiveSorting = new AdaptivePerformanceScalerSettingsBase
  320. {
  321. name = "Adaptive Sorting",
  322. enabled = false,
  323. scale = 1,
  324. visualImpact = ScalerVisualImpact.Medium,
  325. target = ScalerTarget.CPU,
  326. maxLevel = 1,
  327. minBound = 0,
  328. maxBound = 1,
  329. };
  330. /// <summary>
  331. /// A scaler setting used by <see cref="AdaptivePerformanceIndexer"/> to change if objects in the scene are sorted by depth before rendering to reduce overdraw.
  332. /// </summary>
  333. public AdaptivePerformanceScalerSettingsBase AdaptiveSorting
  334. {
  335. get { return m_AdaptiveSorting; }
  336. set { m_AdaptiveSorting = value; }
  337. }
  338. [SerializeField, Tooltip("Settings for a scaler used by the Indexer to disable transparent objects rendering")]
  339. AdaptivePerformanceScalerSettingsBase m_AdaptiveTransparency = new AdaptivePerformanceScalerSettingsBase
  340. {
  341. name = "Adaptive Transparency",
  342. enabled = false,
  343. scale = 1,
  344. visualImpact = ScalerVisualImpact.High,
  345. target = ScalerTarget.GPU,
  346. maxLevel = 1,
  347. minBound = 0,
  348. maxBound = 1,
  349. };
  350. /// <summary>
  351. /// A scaler setting used by <see cref="AdaptivePerformanceIndexer"/> to disable transparent objects rendering.
  352. /// </summary>
  353. public AdaptivePerformanceScalerSettingsBase AdaptiveTransparency
  354. {
  355. get { return m_AdaptiveTransparency; }
  356. set { m_AdaptiveTransparency = value; }
  357. }
  358. [SerializeField, Tooltip("Settings for a scaler used by the Indexer to change the view distance")]
  359. AdaptivePerformanceScalerSettingsBase m_AdaptiveViewDistance = new AdaptivePerformanceScalerSettingsBase
  360. {
  361. name = "Adaptive View Distance",
  362. enabled = false,
  363. scale = 1,
  364. visualImpact = ScalerVisualImpact.High,
  365. target = ScalerTarget.GPU,
  366. maxLevel = 40,
  367. minBound = 50f,
  368. maxBound = 1000,
  369. };
  370. /// <summary>
  371. /// A scaler setting used by <see cref="AdaptivePerformanceIndexer"/> to change the view distance.
  372. /// </summary>
  373. public AdaptivePerformanceScalerSettingsBase AdaptiveViewDistance
  374. {
  375. get { return m_AdaptiveViewDistance; }
  376. set { m_AdaptiveViewDistance = value; }
  377. }
  378. [SerializeField, Tooltip("Settings for a scaler used by the Indexer to change physics properties")]
  379. AdaptivePerformanceScalerSettingsBase m_AdaptivePhysics = new AdaptivePerformanceScalerSettingsBase
  380. {
  381. name = "Adaptive Physics",
  382. enabled = false,
  383. scale = 1,
  384. visualImpact = ScalerVisualImpact.Low,
  385. target = ScalerTarget.CPU,
  386. maxLevel = 5,
  387. minBound = 0.5f,
  388. maxBound = 1,
  389. };
  390. /// <summary>
  391. /// A scaler setting used by <see cref="AdaptivePerformanceIndexer"/> to change physics properties.
  392. /// </summary>
  393. public AdaptivePerformanceScalerSettingsBase AdaptivePhysics
  394. {
  395. get { return m_AdaptivePhysics; }
  396. set { m_AdaptivePhysics = value; }
  397. }
  398. /// <summary>
  399. /// A scaler setting used by <see cref="AdaptivePerformanceIndexer"/> to change decal properties.
  400. /// </summary>
  401. public AdaptivePerformanceScalerSettingsBase AdaptiveDecals
  402. {
  403. get { return m_AdaptiveDecals; }
  404. set { m_AdaptiveDecals = value; }
  405. }
  406. [SerializeField, Tooltip("Settings for a scaler used by the Indexer to change decal properties")]
  407. AdaptivePerformanceScalerSettingsBase m_AdaptiveDecals = new AdaptivePerformanceScalerSettingsBase
  408. {
  409. name = "Adaptive Decals",
  410. enabled = false,
  411. scale = 1,
  412. visualImpact = ScalerVisualImpact.Medium,
  413. target = ScalerTarget.GPU,
  414. maxLevel = 20,
  415. minBound = 0.01f,
  416. maxBound = 1,
  417. };
  418. [SerializeField, Tooltip("Settings for a scaler used by the Indexer to change the layer culling distance")]
  419. AdaptivePerformanceScalerSettingsBase m_AdaptiveLayerCulling = new AdaptivePerformanceScalerSettingsBase
  420. {
  421. name = "Adaptive Layer Culling",
  422. enabled = false,
  423. scale = 1,
  424. visualImpact = ScalerVisualImpact.Medium,
  425. target = ScalerTarget.CPU,
  426. maxLevel = 40,
  427. minBound = 0.01f,
  428. maxBound = 1,
  429. };
  430. /// <summary>
  431. /// A scaler setting used by <see cref="AdaptivePerformanceIndexer"/> to change the layer culling distance.
  432. /// </summary>
  433. public AdaptivePerformanceScalerSettingsBase AdaptiveLayerCulling
  434. {
  435. get { return m_AdaptiveLayerCulling; }
  436. set { m_AdaptiveLayerCulling = value; }
  437. }
  438. }
  439. /// <summary>
  440. /// Settings of indexer system.
  441. /// </summary>
  442. [System.Serializable]
  443. public class AdaptivePerformanceScalerSettingsBase
  444. {
  445. [SerializeField, Tooltip("Name of the scaler.")]
  446. string m_Name = "Base Scaler";
  447. /// <summary>
  448. /// Returns the name of the scaler.
  449. /// </summary>
  450. public string name
  451. {
  452. get { return m_Name; }
  453. set
  454. {
  455. m_Name = value;
  456. }
  457. }
  458. [SerializeField, Tooltip("Active")]
  459. bool m_Enabled = false;
  460. /// <summary>
  461. /// Returns true if Indexer was active, false otherwise.
  462. /// </summary>
  463. public bool enabled
  464. {
  465. get { return m_Enabled; }
  466. set { m_Enabled = value; }
  467. }
  468. [SerializeField, Tooltip("Scale to control the quality impact for the scaler. No quality change when 1, improved quality when >1, and lowered quality when <1.")]
  469. float m_Scale = -1.0f;
  470. /// <summary>
  471. /// Scale to control the quality impact for the scaler. No quality change when 1, improved quality when bigger 1, and lowered quality when smaller 1.
  472. /// </summary>
  473. public float scale
  474. {
  475. get { return m_Scale; }
  476. set { m_Scale = value; }
  477. }
  478. [SerializeField, Tooltip("Visual impact the scaler has on the application. The higher the value, the more impact the scaler has on the visuals.")]
  479. ScalerVisualImpact m_VisualImpact = ScalerVisualImpact.Low;
  480. /// <summary>
  481. /// Visual impact the scaler has on the application. The higher the value, the more impact the scaler has on the visuals.
  482. /// </summary>
  483. public ScalerVisualImpact visualImpact
  484. {
  485. get { return m_VisualImpact; }
  486. set { m_VisualImpact = value; }
  487. }
  488. [SerializeField, Tooltip("Application bottleneck that the scaler targets. The target selected has the most impact on the quality control of this scaler.")]
  489. ScalerTarget m_Target = ScalerTarget.CPU;
  490. /// <summary>
  491. /// Application bottleneck that the scaler targets. The target selected has the most impact on the quality control of this scaler.
  492. /// </summary>
  493. public ScalerTarget target
  494. {
  495. get { return m_Target; }
  496. set { m_Target = value; }
  497. }
  498. [SerializeField, Tooltip("Maximum level for the scaler. This is tied to the implementation of the scaler to divide the levels into concrete steps.")]
  499. int m_MaxLevel = 1;
  500. /// <summary>
  501. /// Maximum level for the scaler. This is tied to the implementation of the scaler to divide the levels into concrete steps.
  502. /// </summary>
  503. public int maxLevel
  504. {
  505. get { return m_MaxLevel; }
  506. set { m_MaxLevel = value; }
  507. }
  508. [SerializeField, Tooltip("Minimum value for the scale boundary.")]
  509. float m_MinBound = -1.0f;
  510. /// <summary>
  511. /// Minimum value for the scale boundary.
  512. /// </summary>
  513. public float minBound
  514. {
  515. get { return m_MinBound; }
  516. set { m_MinBound = value; }
  517. }
  518. [SerializeField, Tooltip("Maximum value for the scale boundary.")]
  519. float m_MaxBound = -1.0f;
  520. /// <summary>
  521. /// Maximum value for the scale boundary.
  522. /// </summary>
  523. public float maxBound
  524. {
  525. get { return m_MaxBound; }
  526. set { m_MaxBound = value; }
  527. }
  528. }
  529. /// <summary>
  530. /// Provider Settings Interface as base class of the provider. Used to control the Editor runtime asset instance which stores the Settings.
  531. /// </summary>
  532. public class IAdaptivePerformanceSettings : ScriptableObject
  533. {
  534. [SerializeField, Tooltip("Enable Logging in Devmode")]
  535. bool m_Logging = true;
  536. /// <summary>
  537. /// Control debug logging.
  538. /// This setting only affects development builds. All logging is disabled in release builds.
  539. /// This setting can also be controlled after startup using <see cref="IDevelopmentSettings.Logging"/>.
  540. /// Logging is disabled by default.
  541. /// </summary>
  542. /// <value>Set this to true to enable debug logging, or false to disable it. It is false by default.</value>
  543. public bool logging
  544. {
  545. get { return m_Logging; }
  546. set { m_Logging = value; }
  547. }
  548. [SerializeField, Tooltip("Automatic Performance Mode")]
  549. bool m_AutomaticPerformanceModeEnabled = true;
  550. /// <summary>
  551. /// The initial value of <see cref="IDevicePerformanceControl.AutomaticPerformanceControl"/>.
  552. /// </summary>
  553. /// <value>Set this to true to enable Automatic Performance Mode, or false to disable it. It is true by default.</value>
  554. public bool automaticPerformanceMode
  555. {
  556. get { return m_AutomaticPerformanceModeEnabled; }
  557. set { m_AutomaticPerformanceModeEnabled = value; }
  558. }
  559. [SerializeField, Tooltip("Enables the CPU and GPU boost mode before engine startup to decrease startup time.")]
  560. bool m_EnableBoostOnStartup = true;
  561. /// <summary>
  562. /// Whether CPU and GPU boost mode should be enabled on application startup.
  563. /// </summary>
  564. public bool enableBoostOnStartup
  565. {
  566. get { return m_EnableBoostOnStartup; }
  567. set { m_EnableBoostOnStartup = value; }
  568. }
  569. [SerializeField, Tooltip("Logging Frequency (Development mode only)")]
  570. int m_StatsLoggingFrequencyInFrames = 50;
  571. /// <summary>
  572. /// Adjust the frequency in frames at which the application logs frame statistics to the console.
  573. /// This is only relevant when logging is enabled. See <see cref="IDevelopmentSettings.Logging"/>.
  574. /// This setting can also be controlled after startup using <see cref="IDevelopmentSettings.LoggingFrequencyInFrames"/>.
  575. /// </summary>
  576. /// <value>Logging frequency in frames (default: 50)</value>
  577. public int statsLoggingFrequencyInFrames
  578. {
  579. get { return m_StatsLoggingFrequencyInFrames; }
  580. set { m_StatsLoggingFrequencyInFrames = value; }
  581. }
  582. [SerializeField, Tooltip("Indexer Settings")]
  583. AdaptivePerformanceIndexerSettings m_IndexerSettings;
  584. /// <summary>
  585. /// Settings of indexer system.
  586. /// </summary>
  587. public AdaptivePerformanceIndexerSettings indexerSettings
  588. {
  589. get { return m_IndexerSettings; }
  590. set { m_IndexerSettings = value; }
  591. }
  592. [SerializeField, Tooltip("Scaler Settings")]
  593. AdaptivePerformanceScalerSettings m_ScalerSettings;
  594. /// <summary>
  595. /// Settings of scaler system.
  596. /// </summary>
  597. public AdaptivePerformanceScalerSettings scalerSettings
  598. {
  599. get { return m_ScalerSettings; }
  600. set { m_ScalerSettings = value; }
  601. }
  602. /// <summary>
  603. /// Load a scaler profile from the settings. Unity update the values of all scalers in the profile to new ones.
  604. /// This is a heavy operation using reflection and should not be used per frame and only in load operations as it causes hitching and possible screen artifacts depending on which scalers are used in a scene.
  605. /// </summary>
  606. /// <param name="scalerProfileName">Supply the name of the scaler. You can query a list of available scaler profiles via <see cref="IAdaptivePerformanceSettings.GetAvailableScalerProfiles"/>.</param>
  607. public void LoadScalerProfile(string scalerProfileName)
  608. {
  609. if (scalerProfileName == null || scalerProfileName.Length <= 0)
  610. {
  611. APLog.Debug("Scaler profile name empty. Can not load and apply profile.");
  612. return;
  613. }
  614. if (m_scalerProfileList.Length <= 0)
  615. {
  616. APLog.Debug("No scaler profiles available. Can not load and apply profile. Add more profiles in the Adaptive Performance settings.");
  617. return;
  618. }
  619. if (m_scalerProfileList.Length == 1)
  620. APLog.Debug("Only default scaler profile available. Reset all scalers to default profile.");
  621. for (int i = 0; i < m_scalerProfileList.Length; i++)
  622. {
  623. AdaptivePerformanceScalerProfile scalerProfile = m_scalerProfileList[i];
  624. if (scalerProfile == null)
  625. {
  626. APLog.Debug("Scaler profile is null. Can not load and apply profile. Check Adaptive Performance settings.");
  627. return;
  628. }
  629. if (scalerProfile.Name == null || scalerProfile.Name.Length <= 0)
  630. {
  631. APLog.Debug("Scaler profile name is null or empty. Can not load and apply profile. Check Adaptive Performance settings.");
  632. return;
  633. }
  634. if (scalerProfile.Name == scalerProfileName)
  635. {
  636. scalerSettings.ApplySettings(scalerProfile);
  637. break;
  638. }
  639. }
  640. if (ApplyScalerProfileToAllScalers())
  641. APLog.Debug($"Scaler profile {scalerProfileName} loaded.");
  642. }
  643. bool ApplyScalerProfileToAllScalers()
  644. {
  645. bool success = false;
  646. if (Holder.Instance == null || Holder.Instance.Indexer == null)
  647. return success;
  648. List<AdaptivePerformanceScaler> allScalers = new List<AdaptivePerformanceScaler>();
  649. List<AdaptivePerformanceScaler> scalers = new List<AdaptivePerformanceScaler>();
  650. Holder.Instance.Indexer.GetUnappliedScalers(ref scalers);
  651. allScalers.AddRange(scalers);
  652. Holder.Instance.Indexer.GetAppliedScalers(ref scalers);
  653. allScalers.AddRange(scalers);
  654. Holder.Instance.Indexer.GetDisabledScalers(ref scalers);
  655. allScalers.AddRange(scalers);
  656. if (allScalers.Count <= 0)
  657. {
  658. APLog.Debug($"No scalers found. No scaler profile applied.");
  659. return success;
  660. }
  661. PropertyInfo[] properties = typeof(AdaptivePerformanceScalerSettings).GetProperties();
  662. foreach (PropertyInfo property in properties)
  663. {
  664. var aScaler = allScalers.Find(s => s.GetType().ToString().Contains(property.Name));
  665. if (aScaler)
  666. {
  667. System.Reflection.PropertyInfo prop = typeof(AdaptivePerformanceScalerSettings).GetProperty(property.Name);
  668. var value = prop.GetValue(scalerSettings);
  669. aScaler.Deactivate();
  670. aScaler.ApplyDefaultSetting((AdaptivePerformanceScalerSettingsBase)value);
  671. aScaler.Activate();
  672. success = true;
  673. }
  674. }
  675. return success;
  676. }
  677. /// <summary>
  678. /// Returns a list of all available scaler profiles.
  679. /// </summary>
  680. /// <returns></returns>
  681. public string[] GetAvailableScalerProfiles()
  682. {
  683. string[] scalerNames = new string[m_scalerProfileList.Length];
  684. if (m_scalerProfileList.Length <= 0)
  685. {
  686. APLog.Debug("No scaler profiles available. You can not load and apply profiles. Add more profiles in the Adaptive Performance settings.");
  687. return scalerNames;
  688. }
  689. for (int i = 0; i < m_scalerProfileList.Length; i++)
  690. {
  691. AdaptivePerformanceScalerProfile scalerProfile = m_scalerProfileList[i];
  692. scalerNames[i] = scalerProfile.Name;
  693. }
  694. return scalerNames;
  695. }
  696. [SerializeField] AdaptivePerformanceScalerProfile[] m_scalerProfileList = new AdaptivePerformanceScalerProfile[] { new AdaptivePerformanceScalerProfile {} };
  697. /// <summary>
  698. /// Default scaler profile index.
  699. /// </summary>
  700. public int defaultScalerProfilerIndex
  701. {
  702. get { return m_DefaultScalerProfilerIndex; }
  703. set { m_DefaultScalerProfilerIndex = value; }
  704. }
  705. [SerializeField] internal int m_DefaultScalerProfilerIndex = 0;
  706. #if UNITY_EDITOR
  707. // Default values set when a new Adaptive Performance setting is created
  708. [SerializeField] int k_AssetVersion = 1;
  709. #endif
  710. /// <summary>
  711. /// When Unity enables the serialized object it upgrades old files to the new format in the editor and saves the assets. Empty during runtime.
  712. /// </summary>
  713. public void OnEnable()
  714. {
  715. #if UNITY_EDITOR
  716. if (k_AssetVersion < 2 && !Application.isPlaying)
  717. {
  718. UpgradeToVersion2();
  719. k_AssetVersion = 2;
  720. if (m_scalerProfileList[0] != null)
  721. m_scalerProfileList[0].ApplySettings(scalerSettings);
  722. EditorUtility.SetDirty(this);
  723. AssetDatabase.SaveAssets();
  724. }
  725. #endif
  726. }
  727. #if UNITY_EDITOR
  728. void UpgradeToVersion2()
  729. {
  730. if (m_ScalerSettings == null)
  731. return;
  732. if (m_ScalerSettings.AdaptiveFramerate.scale == -1)
  733. m_ScalerSettings.AdaptiveFramerate.scale = 1;
  734. else
  735. Debug.Log("[Adaptive Performance] Upgraded Adaptive Performance Settings but did not upgrade modified AdaptiveFramerate.scale");
  736. if (m_ScalerSettings.AdaptiveResolution.scale == -1)
  737. m_ScalerSettings.AdaptiveResolution.scale = 1;
  738. else
  739. Debug.Log("[Adaptive Performance] Upgraded Adaptive Performance Settings but did not upgrade modified AdaptiveResolution.scale");
  740. if (m_ScalerSettings.AdaptiveBatching.scale == -1)
  741. m_ScalerSettings.AdaptiveBatching.scale = 1;
  742. else
  743. Debug.Log("[Adaptive Performance] Upgraded Adaptive Performance Settings but did not upgrade modified AdaptiveBatching.scale");
  744. if (m_ScalerSettings.AdaptiveBatching.minBound == -1)
  745. m_ScalerSettings.AdaptiveBatching.minBound = 0;
  746. else
  747. Debug.Log("[Adaptive Performance] Upgraded Adaptive Performance Settings but did not upgrade modified AdaptiveBatching.minBound");
  748. if (m_ScalerSettings.AdaptiveBatching.maxBound == -1)
  749. m_ScalerSettings.AdaptiveBatching.maxBound = 1;
  750. else
  751. Debug.Log("[Adaptive Performance] Upgraded Adaptive Performance Settings but did not upgrade modified AdaptiveBatching.maxBound");
  752. if (m_ScalerSettings.AdaptiveLOD.scale == -1)
  753. m_ScalerSettings.AdaptiveLOD.scale = 1;
  754. else
  755. Debug.Log("[Adaptive Performance] Upgraded Adaptive Performance Settings but did not upgrade modified AdaptiveLOD.scale");
  756. if (m_ScalerSettings.AdaptiveLOD.minBound == -1)
  757. m_ScalerSettings.AdaptiveLOD.minBound = 0.4f;
  758. else
  759. Debug.Log("[Adaptive Performance] Upgraded Adaptive Performance Settings but did not upgrade modified AdaptiveLOD.minBound");
  760. if (m_ScalerSettings.AdaptiveLOD.maxBound == -1)
  761. m_ScalerSettings.AdaptiveLOD.maxBound = 1;
  762. else
  763. Debug.Log("[Adaptive Performance] Upgraded Adaptive Performance Settings but did not upgrade modified AdaptiveLOD.maxBound");
  764. if (m_ScalerSettings.AdaptiveLut.scale == -1)
  765. m_ScalerSettings.AdaptiveLut.scale = 1;
  766. else
  767. Debug.Log("[Adaptive Performance] Upgraded Adaptive Performance Settings but did not upgrade modified AdaptiveLut.scale");
  768. if (m_ScalerSettings.AdaptiveLut.minBound == -1)
  769. m_ScalerSettings.AdaptiveLut.minBound = 0;
  770. else
  771. Debug.Log("[Adaptive Performance] Upgraded Adaptive Performance Settings but did not upgrade modified AdaptiveLut.minBound");
  772. if (m_ScalerSettings.AdaptiveLut.maxBound == -1)
  773. m_ScalerSettings.AdaptiveLut.maxBound = 1;
  774. else
  775. Debug.Log("[Adaptive Performance] Upgraded Adaptive Performance Settings but did not upgrade modified AdaptiveLut.maxBound");
  776. if (m_ScalerSettings.AdaptiveMSAA.scale == -1)
  777. m_ScalerSettings.AdaptiveMSAA.scale = 1;
  778. else
  779. Debug.Log("[Adaptive Performance] Upgraded Adaptive Performance Settings but did not upgrade modified AdaptiveMSAA.scale");
  780. if (m_ScalerSettings.AdaptiveMSAA.minBound == -1)
  781. m_ScalerSettings.AdaptiveMSAA.minBound = 0;
  782. else
  783. Debug.Log("[Adaptive Performance] Upgraded Adaptive Performance Settings but did not upgrade modified AdaptiveMSAA.minBound");
  784. if (m_ScalerSettings.AdaptiveMSAA.maxBound == -1)
  785. m_ScalerSettings.AdaptiveMSAA.maxBound = 1;
  786. else
  787. Debug.Log("[Adaptive Performance] Upgraded Adaptive Performance Settings but did not upgrade modified AdaptiveMSAA.maxBound");
  788. if (m_ScalerSettings.AdaptiveShadowDistance.scale == -1)
  789. m_ScalerSettings.AdaptiveShadowDistance.scale = 1;
  790. else
  791. Debug.Log("[Adaptive Performance] Upgraded Adaptive Performance Settings but did not upgrade modified AdaptiveShadowDistance.scale");
  792. if (m_ScalerSettings.AdaptiveShadowDistance.minBound == -1)
  793. m_ScalerSettings.AdaptiveShadowDistance.minBound = 0;
  794. else
  795. Debug.Log("[Adaptive Performance] Upgraded Adaptive Performance Settings but did not upgrade modified AdaptiveShadowDistance.minBound");
  796. if (m_ScalerSettings.AdaptiveShadowDistance.maxBound == -1)
  797. m_ScalerSettings.AdaptiveShadowDistance.maxBound = 1;
  798. else
  799. Debug.Log("[Adaptive Performance] Upgraded Adaptive Performance Settings but did not upgrade modified AdaptiveShadowDistance.maxBound");
  800. if (m_ScalerSettings.AdaptiveShadowmapResolution.scale == -1)
  801. m_ScalerSettings.AdaptiveShadowmapResolution.scale = 1;
  802. else
  803. Debug.Log("[Adaptive Performance] Upgraded Adaptive Performance Settings but did not upgrade modified AdaptiveShadowmapResolution.scale");
  804. if (m_ScalerSettings.AdaptiveShadowmapResolution.minBound == -1)
  805. m_ScalerSettings.AdaptiveShadowmapResolution.minBound = 0;
  806. else
  807. Debug.Log("[Adaptive Performance] Upgraded Adaptive Performance Settings but did not upgrade modified AdaptiveShadowmapResolution.minBound");
  808. if (m_ScalerSettings.AdaptiveShadowmapResolution.maxBound == -1)
  809. m_ScalerSettings.AdaptiveShadowmapResolution.maxBound = 1;
  810. else
  811. Debug.Log("[Adaptive Performance] Upgraded Adaptive Performance Settings but did not upgrade modified AdaptiveShadowmapResolution.maxBound");
  812. if (m_ScalerSettings.AdaptiveShadowQuality.scale == -1)
  813. m_ScalerSettings.AdaptiveShadowQuality.scale = 1;
  814. else
  815. Debug.Log("[Adaptive Performance] Upgraded Adaptive Performance Settings but did not upgrade modified AdaptiveShadowQuality.scale");
  816. if (m_ScalerSettings.AdaptiveShadowQuality.minBound == -1)
  817. m_ScalerSettings.AdaptiveShadowQuality.minBound = 0;
  818. else
  819. Debug.Log("[Adaptive Performance] Upgraded Adaptive Performance Settings but did not upgrade modified AdaptiveShadowQuality.minBound");
  820. if (m_ScalerSettings.AdaptiveShadowQuality.maxBound == -1)
  821. m_ScalerSettings.AdaptiveShadowQuality.maxBound = 1;
  822. else
  823. Debug.Log("[Adaptive Performance] Upgraded Adaptive Performance Settings but did not upgrade modified AdaptiveShadowQuality.maxBound");
  824. if (m_ScalerSettings.AdaptiveSorting.scale == -1)
  825. m_ScalerSettings.AdaptiveSorting.scale = 1;
  826. else
  827. Debug.Log("[Adaptive Performance] Upgraded Adaptive Performance Settings but did not upgrade modified AdaptiveSorting.scale");
  828. if (m_ScalerSettings.AdaptiveSorting.minBound == -1)
  829. m_ScalerSettings.AdaptiveSorting.minBound = 0;
  830. else
  831. Debug.Log("[Adaptive Performance] Upgraded Adaptive Performance Settings but did not upgrade modified AdaptiveSorting.minBound");
  832. if (m_ScalerSettings.AdaptiveSorting.maxBound == -1)
  833. m_ScalerSettings.AdaptiveSorting.maxBound = 1;
  834. else
  835. Debug.Log("[Adaptive Performance] Upgraded Adaptive Performance Settings but did not upgrade modified AdaptiveSorting.maxBound");
  836. if (m_ScalerSettings.AdaptiveTransparency.scale == -1)
  837. m_ScalerSettings.AdaptiveTransparency.scale = 1;
  838. else
  839. Debug.Log("[Adaptive Performance] Upgraded Adaptive Performance Settings but did not upgrade modified AdaptiveTransparency.scale");
  840. if (m_ScalerSettings.AdaptiveTransparency.minBound == -1)
  841. m_ScalerSettings.AdaptiveTransparency.minBound = 0;
  842. else
  843. Debug.Log("[Adaptive Performance] Upgraded Adaptive Performance Settings but did not upgrade modified AdaptiveTransparency.minBound");
  844. if (m_ScalerSettings.AdaptiveTransparency.maxBound == -1)
  845. m_ScalerSettings.AdaptiveTransparency.maxBound = 1;
  846. else
  847. Debug.Log("[Adaptive Performance] Upgraded Adaptive Performance Settings but did not upgrade modified AdaptiveTransparency.maxBound");
  848. }
  849. #endif
  850. }
  851. }