ISequenceState.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System;
  2. using UnityEngine.Playables;
  3. using UnityEngine.Timeline;
  4. namespace UnityEditor.Timeline
  5. {
  6. interface ISequenceState : IDisposable
  7. {
  8. TimelineAsset asset { get; }
  9. PlayableDirector director { get; }
  10. TimelineClip hostClip { get; }
  11. double start { get; }
  12. double timeScale { get; }
  13. double duration { get; }
  14. bool isReadOnly { get; }
  15. TimelineAssetViewModel viewModel { get; }
  16. double time { get; set; }
  17. int frame { get; set; }
  18. float frameRate { get; set; }
  19. Range GetEvaluableRange();
  20. string TimeAsString(double timeValue, string format = "F2");
  21. double ToGlobalTime(double t);
  22. double ToLocalTime(double t);
  23. void ResetIsReadOnly();
  24. }
  25. /**
  26. * This class is used to hold default values for an implementation of ISequenceState.
  27. * It could be removed in a phase 2, but it is currently used to limit the scope of
  28. * this refactoring: it allows client code to access sequence info without having to
  29. * worry about `currentSequence` being null.
  30. * In the future this should be removed and we should pass around the correct data
  31. * structure (i.e. SequenceState OR WindowState) based on the situation.
  32. */
  33. class NullSequenceState : ISequenceState
  34. {
  35. public TimelineAsset asset { get { return null; } }
  36. public PlayableDirector director { get { return null; } }
  37. public TimelineClip hostClip { get { return null; } }
  38. public double start { get { return 0.0; } }
  39. public double timeScale { get { return 1.0; } }
  40. public double duration { get { return 0.0; } }
  41. public bool isReadOnly { get { return false; } }
  42. TimelineAssetViewModel m_ViewModel;
  43. public TimelineAssetViewModel viewModel
  44. {
  45. get
  46. {
  47. if (m_ViewModel == null)
  48. m_ViewModel = TimelineWindowViewPrefs.CreateUnassociatedViewModel();
  49. return m_ViewModel;
  50. }
  51. }
  52. public double time
  53. {
  54. get { return 0.0; }
  55. set { /* NO-OP*/ }
  56. }
  57. public int frame
  58. {
  59. get { return 0; }
  60. set { /* NO-OP*/ }
  61. }
  62. public float frameRate
  63. {
  64. get { return TimelineAsset.EditorSettings.kDefaultFps; }
  65. set { /* NO-OP*/ }
  66. }
  67. public Range GetEvaluableRange()
  68. {
  69. return new Range();
  70. }
  71. public string TimeAsString(double timeValue, string format = "F2")
  72. {
  73. return TimeUtility.TimeAsTimeCode(timeValue, frameRate, format);
  74. }
  75. public double ToGlobalTime(double t)
  76. {
  77. return t;
  78. }
  79. public double ToLocalTime(double t)
  80. {
  81. return t;
  82. }
  83. public void ResetIsReadOnly()
  84. {
  85. // NO-OP
  86. }
  87. public void Dispose()
  88. {
  89. // NO-OP
  90. }
  91. }
  92. }