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.

OnThermalMetricUnit.cs 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #if VISUAL_SCRIPTING_ENABLED
  2. using System;
  3. using Unity.VisualScripting;
  4. namespace UnityEngine.AdaptivePerformance.VisualScripting
  5. {
  6. [UnitShortTitle("On Thermal Metric")]
  7. [UnitSubtitle("Throttling and Thermal Info")]
  8. [UnitCategory("AdaptivePerformance/Thermal")]
  9. public class OnThermalMetricUnit : EventUnit<WarningLevel>
  10. {
  11. [DoNotSerialize]
  12. public ValueOutput warningLevel { get; private set; }
  13. [DoNotSerialize]
  14. public ValueOutput throttlingImminent;
  15. [DoNotSerialize]
  16. public ValueOutput throttling;
  17. string WarningLevel = "unknown";
  18. bool ThrottlingImminent = false;
  19. bool Throttling = false;
  20. protected override bool register => true;
  21. public override EventHook GetHook(GraphReference reference)
  22. {
  23. return new EventHook(AdaptivePerformanceEventHooks.OnThermalEvent);
  24. }
  25. protected override void AssignArguments(Flow flow, WarningLevel data)
  26. {
  27. flow.SetValue(warningLevel, data.ToString());
  28. flow.SetValue(throttlingImminent, data == AdaptivePerformance.WarningLevel.ThrottlingImminent);
  29. flow.SetValue(throttling, data == AdaptivePerformance.WarningLevel.Throttling);
  30. }
  31. protected override void Definition()
  32. {
  33. base.Definition();
  34. warningLevel = ValueOutput<String>(nameof(warningLevel), (flow) => { UpdateStats(); return WarningLevel; });
  35. throttlingImminent = ValueOutput<bool>("throttlingImminent", (flow) => { UpdateStats(); return ThrottlingImminent; });
  36. throttling = ValueOutput<bool>("throttling", (flow) => { UpdateStats(); return Throttling; });
  37. }
  38. void UpdateStats()
  39. {
  40. if (Application.isPlaying && Holder.Instance != null)
  41. {
  42. var tm = Holder.Instance.ThermalStatus.ThermalMetrics;
  43. ThrottlingImminent = tm.WarningLevel == AdaptivePerformance.WarningLevel.ThrottlingImminent;
  44. Throttling = tm.WarningLevel == AdaptivePerformance.WarningLevel.Throttling;
  45. WarningLevel = tm.WarningLevel.ToString();
  46. }
  47. }
  48. }
  49. }
  50. #endif