Geen omschrijving
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.

PerformanceModeControl.cs 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System.Collections;
  2. using UnityEngine;
  3. using UnityEngine.AdaptivePerformance;
  4. public class PerformanceModeControl : MonoBehaviour
  5. {
  6. public SampleFactory objectFactory;
  7. IAdaptivePerformance m_AP;
  8. int m_OriginalLimitCount;
  9. void OnPerformanceModeEvent(PerformanceMode performanceMode)
  10. {
  11. switch (performanceMode)
  12. {
  13. case PerformanceMode.Optimize:
  14. case PerformanceMode.CPU:
  15. case PerformanceMode.GPU:
  16. objectFactory.LimitCount = m_OriginalLimitCount;
  17. break;
  18. case PerformanceMode.Unknown:
  19. objectFactory.LimitCount = m_OriginalLimitCount / 10;
  20. break;
  21. case PerformanceMode.Standard:
  22. objectFactory.LimitCount = m_OriginalLimitCount / 4;
  23. break;
  24. case PerformanceMode.Battery:
  25. objectFactory.LimitCount = m_OriginalLimitCount / 25;
  26. break;
  27. }
  28. }
  29. void Start()
  30. {
  31. m_AP = Holder.Instance;
  32. if (m_AP == null)
  33. {
  34. Debug.Log("[Performance Mode Control] Warning Adaptive Performance Manager was not found and does not report");
  35. return;
  36. }
  37. m_OriginalLimitCount = objectFactory.LimitCount;
  38. m_AP.PerformanceModeStatus.PerformanceModeEvent += OnPerformanceModeEvent;
  39. OnPerformanceModeEvent(m_AP.PerformanceModeStatus.PerformanceMode);
  40. StartCoroutine(TestTimeout());
  41. }
  42. IEnumerator TestTimeout()
  43. {
  44. while (true)
  45. {
  46. yield return new WaitForSeconds(300);
  47. #if UNITY_EDITOR
  48. UnityEditor.EditorApplication.isPlaying = false;
  49. #else
  50. Application.Quit();
  51. #endif
  52. }
  53. }
  54. }