Bez popisu
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.

OnPerformanceLevelsUnit.cs 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #if VISUAL_SCRIPTING_ENABLED
  2. using System;
  3. using Unity.VisualScripting;
  4. namespace UnityEngine.AdaptivePerformance.VisualScripting
  5. {
  6. [UnitShortTitle("On Performance Level")]
  7. [UnitSubtitle("CPU and GPU Levels")]
  8. [UnitCategory("AdaptivePerformance/Performance")]
  9. public class OnPerformanceLevelsUnit : EventUnit<PerformanceLevelChangeEventArgs>
  10. {
  11. [DoNotSerialize]
  12. public ValueOutput CpuLevel;
  13. [DoNotSerialize]
  14. public ValueOutput GpuLevel;
  15. int cpuLevel = -1;
  16. int gpuLevel = -1;
  17. protected override bool register => true;
  18. public override EventHook GetHook(GraphReference reference)
  19. {
  20. return new EventHook(AdaptivePerformanceEventHooks.OnPerformanceLevelEvent);
  21. }
  22. protected override void AssignArguments(Flow flow, PerformanceLevelChangeEventArgs data)
  23. {
  24. flow.SetValue(CpuLevel, data.CpuLevel);
  25. flow.SetValue(GpuLevel, data.GpuLevel);
  26. }
  27. protected override void Definition()
  28. {
  29. base.Definition();
  30. CpuLevel = ValueOutput<int>("CPU Level", (flow) => { UpdateStats(); return cpuLevel; });
  31. GpuLevel = ValueOutput<int>("GPU Level", (flow) => { UpdateStats(); return gpuLevel; });
  32. }
  33. void UpdateStats()
  34. {
  35. if (Application.isPlaying && Holder.Instance != null)
  36. {
  37. var pm = Holder.Instance.PerformanceStatus.PerformanceMetrics;
  38. cpuLevel = pm.CurrentCpuLevel;
  39. gpuLevel = pm.CurrentGpuLevel;
  40. }
  41. }
  42. }
  43. }
  44. #endif