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.

OnPerformanceModeUnit.cs 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #if VISUAL_SCRIPTING_ENABLED
  2. using Unity.VisualScripting;
  3. namespace UnityEngine.AdaptivePerformance.VisualScripting
  4. {
  5. [UnitShortTitle("On Performance Mode")]
  6. [UnitSubtitle("Performance Mode")]
  7. [UnitCategory("AdaptivePerformance/Performance")]
  8. public class OnPerformanceModeUnit : EventUnit<PerformanceMode>
  9. {
  10. [DoNotSerialize]
  11. public ValueOutput PerformanceMode { get; private set; }
  12. [DoNotSerialize]
  13. public ValueOutput IsStandard { get; private set; }
  14. [DoNotSerialize]
  15. public ValueOutput IsBattery { get; private set; }
  16. [DoNotSerialize]
  17. public ValueOutput IsOptimize { get; private set; }
  18. [DoNotSerialize]
  19. public ValueOutput IsCpu { get; private set; }
  20. [DoNotSerialize]
  21. public ValueOutput IsGpu { get; private set; }
  22. string m_PerformanceMode = AdaptivePerformance.PerformanceMode.Unknown.ToString();
  23. bool m_IsStandard = false;
  24. bool m_IsBattery = false;
  25. bool m_IsOptimize = false;
  26. bool m_IsCpu = false;
  27. bool m_IsGpu = false;
  28. protected override bool register => true;
  29. public override EventHook GetHook(GraphReference reference)
  30. {
  31. return new EventHook(AdaptivePerformanceEventHooks.OnPerformanceModeEvent);
  32. }
  33. protected override void AssignArguments(Flow flow, PerformanceMode mode)
  34. {
  35. flow.SetValue(PerformanceMode, mode.ToString());
  36. flow.SetValue(IsStandard, mode == AdaptivePerformance.PerformanceMode.Standard);
  37. flow.SetValue(IsBattery, mode == AdaptivePerformance.PerformanceMode.Battery);
  38. flow.SetValue(IsOptimize, mode == AdaptivePerformance.PerformanceMode.Optimize);
  39. flow.SetValue(IsCpu, mode == AdaptivePerformance.PerformanceMode.CPU);
  40. flow.SetValue(IsGpu, mode == AdaptivePerformance.PerformanceMode.GPU);
  41. }
  42. protected override void Definition()
  43. {
  44. base.Definition();
  45. PerformanceMode = ValueOutput<string>(nameof(PerformanceMode), (flow) => { UpdateStats(); return m_PerformanceMode; });
  46. IsStandard = ValueOutput<bool>(nameof(IsStandard), (flow) => { UpdateStats(); return m_IsStandard; });
  47. IsBattery = ValueOutput<bool>(nameof(IsBattery), (flow) => { UpdateStats(); return m_IsBattery; });
  48. IsOptimize = ValueOutput<bool>(nameof(IsOptimize), (flow) => { UpdateStats(); return m_IsOptimize; });
  49. IsCpu = ValueOutput<bool>(nameof(IsCpu), (flow) => { UpdateStats(); return m_IsCpu; });
  50. IsGpu = ValueOutput<bool>(nameof(IsGpu), (flow) => { UpdateStats(); return m_IsGpu; });
  51. }
  52. void UpdateStats()
  53. {
  54. if (Application.isPlaying && Holder.Instance != null)
  55. {
  56. var pm = Holder.Instance.PerformanceModeStatus.PerformanceMode;
  57. m_PerformanceMode = pm.ToString();
  58. m_IsStandard = pm == AdaptivePerformance.PerformanceMode.Standard;
  59. m_IsBattery = pm == AdaptivePerformance.PerformanceMode.Battery;
  60. m_IsOptimize = pm == AdaptivePerformance.PerformanceMode.Optimize;
  61. m_IsCpu = pm == AdaptivePerformance.PerformanceMode.CPU;
  62. m_IsGpu = pm == AdaptivePerformance.PerformanceMode.GPU;
  63. }
  64. }
  65. }
  66. }
  67. #endif