説明なし
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

FrameTimingUnit.cs 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #if VISUAL_SCRIPTING_ENABLED
  2. using Unity.VisualScripting;
  3. namespace UnityEngine.AdaptivePerformance.VisualScripting
  4. {
  5. [UnitShortTitle("Frame Timing")]
  6. [UnitSubtitle("Frame Time Metric")]
  7. [UnitCategory("AdaptivePerformance/Performance")]
  8. public class FrameTimingUnit : Unit
  9. {
  10. [DoNotSerialize]
  11. public ValueOutput currentFrameTime;
  12. [DoNotSerialize]
  13. public ValueOutput averageFrameTime;
  14. [DoNotSerialize]
  15. public ValueOutput currentGpuFrameTime;
  16. [DoNotSerialize]
  17. public ValueOutput averageGpuFrameTime;
  18. [DoNotSerialize]
  19. public ValueOutput currentCpuFrameTime;
  20. [DoNotSerialize]
  21. public ValueOutput averageCpuFrameTime;
  22. float CurrentFrameTime = -1.0f;
  23. float AverageFrameTime = -1.0f;
  24. float CurrentGpuFrameTime = -1.0f;
  25. float AverageGpuFrameTime = -1.0f;
  26. float CurrentCpuFrameTime = -1.0f;
  27. float AverageCpuFrameTime = -1.0f;
  28. protected override void Definition()
  29. {
  30. currentFrameTime = ValueOutput<float>("Current Frametime", (flow) => { UpdateStats(); return CurrentFrameTime; });
  31. averageFrameTime = ValueOutput<float>("Average Frametime", (flow) => { UpdateStats(); return AverageFrameTime; });
  32. currentGpuFrameTime = ValueOutput<float>("Current Gpu Frametime", (flow) => { UpdateStats(); return CurrentGpuFrameTime; });
  33. averageGpuFrameTime = ValueOutput<float>("Average Gpu Frametime", (flow) => { UpdateStats(); return AverageGpuFrameTime; });
  34. currentCpuFrameTime = ValueOutput<float>("Current Cpu Frametime", (flow) => { UpdateStats(); return CurrentCpuFrameTime; });
  35. averageCpuFrameTime = ValueOutput<float>("Average Cpu Frametime", (flow) => { UpdateStats(); return AverageCpuFrameTime; });
  36. }
  37. void UpdateStats()
  38. {
  39. if (Application.isPlaying && Holder.Instance != null)
  40. {
  41. var ft = Holder.Instance.PerformanceStatus.FrameTiming;
  42. CurrentFrameTime = ft.CurrentFrameTime;
  43. AverageFrameTime = ft.AverageFrameTime;
  44. CurrentGpuFrameTime = ft.CurrentGpuFrameTime;
  45. AverageGpuFrameTime = ft.AverageGpuFrameTime;
  46. CurrentCpuFrameTime = ft.CurrentCpuFrameTime;
  47. AverageCpuFrameTime = ft.AverageCpuFrameTime;
  48. }
  49. }
  50. }
  51. }
  52. #endif