SW 중심대학 OSS GIT 서버 박건태, 이승준, 고기완, 이준호 새로운 배포
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.

57 lines
2.0 KiB

4 years ago
  1. using UnityEngine.Timeline;
  2. namespace UnityEditor.Timeline
  3. {
  4. static class TimeReferenceUtility
  5. {
  6. static WindowState state { get { return TimelineWindow.instance.state; } }
  7. public static double SnapToFrame(double time)
  8. {
  9. if (state.timeReferenceMode == TimeReferenceMode.Global)
  10. {
  11. time = state.editSequence.ToGlobalTime(time);
  12. time = TimeUtility.RoundToFrame(time, state.referenceSequence.frameRate);
  13. return state.editSequence.ToLocalTime(time);
  14. }
  15. return TimeUtility.RoundToFrame(time, state.referenceSequence.frameRate);
  16. }
  17. public static string ToTimeString(double time, string format = "F2")
  18. {
  19. if (state.timeReferenceMode == TimeReferenceMode.Global)
  20. time = state.editSequence.ToGlobalTime(time);
  21. return state.editSequence.viewModel.timeInFrames ?
  22. TimeUtility.TimeAsFrames(time, state.referenceSequence.frameRate, format) :
  23. TimeUtility.TimeAsTimeCode(time, state.referenceSequence.frameRate, format);
  24. }
  25. public static double FromTimeString(string timeString)
  26. {
  27. double newTime;
  28. if (state.timeInFrames)
  29. {
  30. double newFrameDouble;
  31. if (double.TryParse(timeString, out newFrameDouble))
  32. newTime = TimeUtility.FromFrames(newFrameDouble, state.referenceSequence.frameRate);
  33. else
  34. newTime = state.editSequence.time;
  35. }
  36. else
  37. {
  38. newTime = TimeUtility.ParseTimeCode(timeString, state.referenceSequence.frameRate, -1);
  39. }
  40. if (newTime >= 0.0)
  41. {
  42. return state.timeReferenceMode == TimeReferenceMode.Global ?
  43. state.editSequence.ToLocalTime(newTime) : newTime;
  44. }
  45. return state.editSequence.time;
  46. }
  47. }
  48. }