FakeScopedMarker.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. namespace UnityEditor.Performance.ProfileAnalyzer
  6. {
  7. // Using Profiler.Begin/End calls is tricky, because any scope that could throw ExitGUI,
  8. // which is likely most parts of this code base, would cause Begin-End-Mismatches if such an exception is thrown in between of them.
  9. // On versions from 2018.3 and up this issue can be avoided by via using(ProfilerMarker.Auto(){}.
  10. // Faking this behavior for pre 2018.3 versions, so that construction calls Profiler.Begin and Disposal calls Profiler.End
  11. // won't work either and still cause Begin-End-Mismatches, especially in Deep Profiling, because the begin and end calls would be
  12. // outside of the scope they would be expected to occure in
  13. // So any version without ProfilerMarker API can use this stand in instead and just not add instrumentation.
  14. // Paste this into any files that need these markers and then use ProfilerMarkerAbstracted:
  15. // #if UNITY_2018_3_OR_NEWER
  16. // using ProfilerMarkerAbstracted = Unity.Profiling.ProfilerMarker;
  17. // #else
  18. // using ProfilerMarkerAbstracted = UnityEditor.Performance.ProfileAnalyzer.FakeScopedMarker;
  19. // #endif
  20. #if !UNITY_2018_3_OR_NEWER
  21. internal struct FakeScopedMarker
  22. {
  23. public FakeScopedMarker(string markerName)
  24. {
  25. }
  26. public IDisposable Auto() { return null; }
  27. }
  28. #endif
  29. }