AnimationTimelineClipEditor.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using UnityEditor.Timeline;
  2. using UnityEngine;
  3. using UnityEngine.Timeline;
  4. namespace UnityUIPlayables.Editor
  5. {
  6. public class AnimationTimelineClipEditor<TAnimationBehaviour> : ClipEditor
  7. where TAnimationBehaviour : AnimationBehaviour, new()
  8. {
  9. private Texture2D _pointTexture;
  10. public override void OnCreate(TimelineClip clip, TrackAsset track, TimelineClip clonedFrom)
  11. {
  12. }
  13. public override void OnClipChanged(TimelineClip clip)
  14. {
  15. }
  16. public override void DrawBackground(TimelineClip clip, ClipBackgroundRegion region)
  17. {
  18. var animationTimelineClip = (AnimationTimelineClip<TAnimationBehaviour>) clip.asset;
  19. var duration = clip.duration;
  20. var behaviour = animationTimelineClip.template;
  21. var loopDuration = behaviour.LoopDuration;
  22. if (loopDuration <= 0.0f)
  23. {
  24. return;
  25. }
  26. if (_pointTexture == null)
  27. {
  28. _pointTexture = Resources.Load<Texture2D>("tex_unityuiplayables_icon_diamond");
  29. }
  30. var time = 0.0f;
  31. var position = region.position;
  32. position.width = 12;
  33. position.height = 12;
  34. position.y += position.height / 2;
  35. var lengthPerLoop = (float) (region.position.width * loopDuration / duration);
  36. while (true)
  37. {
  38. time += loopDuration;
  39. if (time < duration)
  40. {
  41. position.x += lengthPerLoop;
  42. GUI.DrawTexture(position, _pointTexture, ScaleMode.ScaleToFit, true, 1, Color.grey, Vector4.zero,
  43. Vector4.zero);
  44. }
  45. else
  46. {
  47. break;
  48. }
  49. }
  50. }
  51. }
  52. }