Marker.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. namespace UnityEngine.Timeline
  3. {
  4. /// <summary>
  5. /// Use Marker as a base class when creating a custom marker.
  6. /// </summary>
  7. /// <remarks>
  8. /// A marker is a point in time.
  9. /// </remarks>
  10. public abstract class Marker : ScriptableObject, IMarker
  11. {
  12. [SerializeField, TimeField, Tooltip("Time for the marker")] double m_Time;
  13. /// <inheritdoc/>
  14. public TrackAsset parent { get; private set; }
  15. /// <inheritdoc/>
  16. /// <remarks>
  17. /// The marker time cannot be negative.
  18. /// </remarks>
  19. public double time
  20. {
  21. get { return m_Time; }
  22. set { m_Time = Math.Max(value, 0); }
  23. }
  24. void IMarker.Initialize(TrackAsset parentTrack)
  25. {
  26. // We only really want to update the parent when the object is first deserialized
  27. // If not a cloned track would "steal" the source's markers
  28. if (parent == null)
  29. {
  30. parent = parentTrack;
  31. try
  32. {
  33. OnInitialize(parentTrack);
  34. }
  35. catch (Exception e)
  36. {
  37. Debug.LogError(e.Message, this);
  38. }
  39. }
  40. }
  41. /// <summary>
  42. /// Override this method to receive a callback when the marker is initialized.
  43. /// </summary>
  44. public virtual void OnInitialize(TrackAsset aPent)
  45. {
  46. }
  47. }
  48. }