No Description
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.

BoostUI.cs 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using UnityEngine;
  2. using UnityEngine.AdaptivePerformance;
  3. using UnityEngine.UI;
  4. public class BoostUI : MonoBehaviour
  5. {
  6. private IAdaptivePerformance ap;
  7. public GameObject CPUNoBoost, CPUBoost;
  8. public GameObject GPUNoBoost, GPUBoost;
  9. void Start()
  10. {
  11. ap = Holder.Instance;
  12. if (ap == null || !ap.Active)
  13. {
  14. Debug.Log("[AP BoostUI] Adaptive Performance not active");
  15. return;
  16. }
  17. ap.PerformanceStatus.PerformanceBoostChangeEvent += OnBoostModeEvent;
  18. Activate(CPUNoBoost);
  19. Activate(GPUNoBoost);
  20. }
  21. private void OnDestroy()
  22. {
  23. if (ap == null || !ap.Active)
  24. return;
  25. ap.PerformanceStatus.PerformanceBoostChangeEvent -= OnBoostModeEvent;
  26. }
  27. void OnBoostModeEvent(PerformanceBoostChangeEventArgs ev)
  28. {
  29. DisableAllBoostModes();
  30. if (ev.CpuBoost)
  31. Activate(CPUBoost);
  32. else
  33. Activate(CPUNoBoost);
  34. if (ev.GpuBoost)
  35. Activate(GPUBoost);
  36. else
  37. Activate(GPUNoBoost);
  38. }
  39. void DisableAllBoostModes()
  40. {
  41. CPUNoBoost.SetActive(false);
  42. CPUBoost.SetActive(false);
  43. GPUNoBoost.SetActive(false);
  44. GPUBoost.SetActive(false);
  45. }
  46. void Activate(GameObject go)
  47. {
  48. go.SetActive(true);
  49. }
  50. }