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.

TimeReferenceUtility.cs 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using UnityEngine;
  2. using UnityEngine.Timeline;
  3. namespace UnityEditor.Timeline
  4. {
  5. static class TimeReferenceUtility
  6. {
  7. static WindowState state { get { return TimelineWindow.instance.state; } }
  8. public static float PixelToTime(Vector2 mousePos)
  9. {
  10. return PixelToTime(mousePos.x);
  11. }
  12. public static float PixelToTime(float pixelX)
  13. {
  14. return state.PixelToTime(pixelX);
  15. }
  16. public static double GetSnappedTimeAtMousePosition(Vector2 mousePos)
  17. {
  18. return state.GetSnappedTimeAtMousePosition(mousePos);
  19. }
  20. public static double SnapToFrameIfRequired(double currentTime)
  21. {
  22. return TimelinePreferences.instance.snapToFrame ? SnapToFrame(currentTime) : currentTime;
  23. }
  24. public static double SnapToFrame(double time)
  25. {
  26. if (state.timeReferenceMode == TimeReferenceMode.Global)
  27. {
  28. time = state.editSequence.ToGlobalTime(time);
  29. time = TimeUtility.RoundToFrame(time, state.referenceSequence.frameRate);
  30. return state.editSequence.ToLocalTime(time);
  31. }
  32. return TimeUtility.RoundToFrame(time, state.referenceSequence.frameRate);
  33. }
  34. public static string ToTimeString(double time, string format = "F2")
  35. {
  36. if (state.timeReferenceMode == TimeReferenceMode.Global)
  37. time = state.editSequence.ToGlobalTime(time);
  38. return state.timeFormat.ToTimeString(time, state.referenceSequence.frameRate, format);
  39. }
  40. public static double FromTimeString(string timeString)
  41. {
  42. double newTime = state.timeFormat.FromTimeString(timeString, state.referenceSequence.frameRate, -1);
  43. if (newTime >= 0.0)
  44. {
  45. return state.timeReferenceMode == TimeReferenceMode.Global ?
  46. state.editSequence.ToLocalTime(newTime) : newTime;
  47. }
  48. return state.editSequence.time;
  49. }
  50. }
  51. }