FTrackCache.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using UnityEngine;
  2. namespace Flux
  3. {
  4. [System.Flags]
  5. public enum FTrackCacheType
  6. {
  7. None = 0, // doesn't use cache, always evaluates
  8. Editor = 1, // uses cache when in editor scrubbing
  9. Runtime = 2 // uses cache when in runtime
  10. }
  11. /// @brief Base for FTrack caching.
  12. public abstract class FTrackCache {
  13. private FTrack _track = null;
  14. /// @brief Track it's caching
  15. public FTrack Track { get { return _track; } protected set { _track = value; } }
  16. private bool _isBuilt = false;
  17. /// @brief Is the cache already built?
  18. public bool IsBuilt { get { return _isBuilt; } }
  19. public FTrackCache( FTrack track )
  20. {
  21. _track = track;
  22. }
  23. /**
  24. * @brief Build cache
  25. * @param rebuild Rebuild it if it already exists
  26. */
  27. public void Build( bool rebuild )
  28. {
  29. if( IsBuilt )
  30. {
  31. if( !rebuild )
  32. return;
  33. Clear();
  34. }
  35. _isBuilt = BuildInternal();
  36. }
  37. /// @override
  38. public void Build()
  39. {
  40. Build( true );
  41. }
  42. /// @brief Handles the actual building of the cache
  43. protected abstract bool BuildInternal();
  44. /// @brief Clears the cache
  45. public void Clear()
  46. {
  47. if( !IsBuilt )
  48. return;
  49. _isBuilt = !ClearInternal();
  50. }
  51. /// @brief Handles the actual clearing of the cache
  52. protected abstract bool ClearInternal();
  53. /**
  54. * @brief Used to playback the cached data
  55. * @param sequenceTime Sequence time we're playing
  56. */
  57. public abstract void GetPlaybackAt( float sequenceTime );
  58. }
  59. }