PerformUndoTask.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
  5. {
  6. internal class PerformUndoTask : TestTaskBase
  7. {
  8. private const double warningThreshold = 1000;
  9. internal Action<int> RevertAllDownToGroup = Undo.RevertAllDownToGroup;
  10. internal Action<string> LogWarning = Debug.LogWarning;
  11. internal Action<string, string, float> DisplayProgressBar = EditorUtility.DisplayProgressBar;
  12. internal Action ClearProgressBar = EditorUtility.ClearProgressBar;
  13. internal Func<DateTime> TimeNow = () => DateTime.Now;
  14. public override IEnumerator Execute(TestJobData testJobData)
  15. {
  16. if (testJobData.undoGroup < 0)
  17. {
  18. yield break;
  19. }
  20. DisplayProgressBar("Undo", "Reverting changes to the scene", 0);
  21. var undoStartTime = TimeNow();
  22. RevertAllDownToGroup(testJobData.undoGroup);
  23. var timeDelta = TimeNow() - undoStartTime;
  24. if (timeDelta.TotalMilliseconds >= warningThreshold)
  25. {
  26. LogWarning($"Undo after editor test run took {timeDelta.Seconds} second{(timeDelta.Seconds == 1 ? "" : "s")}.");
  27. }
  28. ClearProgressBar();
  29. }
  30. }
  31. }