ClipDrawer.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. using System;
  2. using UnityEngine.Timeline;
  3. using UnityEngine;
  4. using System.Linq;
  5. using System.Collections.Generic;
  6. namespace UnityEditor.Timeline
  7. {
  8. enum BlendKind
  9. {
  10. None,
  11. Ease,
  12. Mix
  13. }
  14. enum BlendAngle
  15. {
  16. Descending,
  17. Ascending
  18. }
  19. struct IconData
  20. {
  21. public enum Side { Left = -1, Right = 1 }
  22. public Texture2D icon;
  23. public Color tint;
  24. public float width { get { return 16; } }
  25. public float height { get { return 16; } }
  26. public IconData(Texture2D icon)
  27. {
  28. this.icon = icon;
  29. tint = Color.white;
  30. }
  31. }
  32. class ClipBorder
  33. {
  34. public readonly Color color;
  35. public readonly float thickness;
  36. ClipBorder(Color color, float thickness)
  37. {
  38. this.color = color;
  39. this.thickness = thickness;
  40. }
  41. const float k_ClipSelectionBorder = 1.0f;
  42. const float k_ClipRecordingBorder = 2.0f;
  43. public static ClipBorder Recording()
  44. {
  45. return new ClipBorder(DirectorStyles.Instance.customSkin.colorRecordingClipOutline, k_ClipRecordingBorder);
  46. }
  47. public static ClipBorder Selection()
  48. {
  49. return new ClipBorder(Color.white, k_ClipSelectionBorder);
  50. }
  51. public static ClipBorder Default()
  52. {
  53. return new ClipBorder(DirectorStyles.Instance.customSkin.clipBorderColor, k_ClipSelectionBorder);
  54. }
  55. }
  56. struct ClipBlends
  57. {
  58. public readonly BlendKind inKind;
  59. public readonly Rect inRect;
  60. public readonly BlendKind outKind;
  61. public readonly Rect outRect;
  62. public ClipBlends(BlendKind inKind, Rect inRect, BlendKind outKind, Rect outRect)
  63. {
  64. this.inKind = inKind;
  65. this.inRect = inRect;
  66. this.outKind = outKind;
  67. this.outRect = outRect;
  68. }
  69. public static readonly ClipBlends kNone = new ClipBlends(BlendKind.None, Rect.zero, BlendKind.None, Rect.zero);
  70. }
  71. struct ClipDrawData
  72. {
  73. public TimelineClip clip; // clip being drawn
  74. public Rect targetRect; // rectangle to draw to
  75. public Rect unclippedRect; // the clip's unclipped rect
  76. public Rect clippedRect; // the clip's clipped rect to the visible time area
  77. public Rect clipCenterSection; // clip center section
  78. public string title; // clip title
  79. public bool selected; // is the clip selected
  80. public bool inlineCurvesSelected; // is the inline curve of the clip selected
  81. public double localVisibleStartTime;
  82. public double localVisibleEndTime;
  83. public IconData[] leftIcons;
  84. public IconData[] rightIcons;
  85. public TimelineClip previousClip;
  86. public bool previousClipSelected;
  87. public bool supportsLooping;
  88. public int minLoopIndex;
  89. public List<Rect> loopRects;
  90. public ClipBlends clipBlends;
  91. public ClipDrawOptions ClipDrawOptions;
  92. public ClipEditor clipEditor;
  93. }
  94. static class ClipDrawer
  95. {
  96. public static class Styles
  97. {
  98. public static readonly Texture2D iconWarn = EditorGUIUtility.LoadIconRequired("console.warnicon.inactive.sml");
  99. public static readonly string HoldText = LocalizationDatabase.GetLocalizedString("HOLD");
  100. public static readonly Texture2D s_IconNoRecord = EditorGUIUtility.LoadIcon("console.erroricon.sml");
  101. public static readonly GUIContent s_ClipNotRecorable = EditorGUIUtility.TrTextContent("", "This clip is not recordable");
  102. public static readonly GUIContent s_ClipNoRecordInBlend = EditorGUIUtility.TrTextContent("", "Recording in blends in prohibited");
  103. }
  104. const float k_ClipSwatchLineThickness = 4.0f;
  105. const float k_MinClipWidth = 7.0f;
  106. const float k_ClipInOutMinWidth = 15.0f;
  107. const float k_ClipLoopsMinWidth = 20.0f;
  108. const float k_ClipLabelPadding = 6.0f;
  109. const float k_ClipLabelMinWidth = 10.0f;
  110. const float k_IconsPadding = 1.0f;
  111. const float k_ClipInlineWidth = 1.0f;
  112. static readonly GUIContent s_TitleContent = new GUIContent();
  113. static readonly IconData[] k_ClipErrorIcons = { new IconData {icon = Styles.iconWarn, tint = DirectorStyles.kClipErrorColor} };
  114. static readonly Dictionary<int, string> s_LoopStringCache = new Dictionary<int, string>(100);
  115. // caches the loopstring to avoid allocation from string concats
  116. static string GetLoopString(int loopIndex)
  117. {
  118. string loopString = null;
  119. if (!s_LoopStringCache.TryGetValue(loopIndex, out loopString))
  120. {
  121. loopString = "L" + loopIndex;
  122. s_LoopStringCache[loopIndex] = loopString;
  123. }
  124. return loopString;
  125. }
  126. static void DrawLoops(ClipDrawData drawData)
  127. {
  128. if (drawData.loopRects == null || drawData.loopRects.Count == 0)
  129. return;
  130. var oldColor = GUI.color;
  131. int loopIndex = drawData.minLoopIndex;
  132. for (int l = 0; l < drawData.loopRects.Count; l++)
  133. {
  134. Rect theRect = drawData.loopRects[l];
  135. theRect.x -= drawData.unclippedRect.x;
  136. theRect.x += 1;
  137. theRect.width -= 2.0f;
  138. theRect.y = 5.0f;
  139. theRect.height -= 4.0f;
  140. theRect.xMin -= 4f;
  141. if (theRect.width >= 5f)
  142. {
  143. using (new GUIViewportScope(drawData.clipCenterSection))
  144. {
  145. GUI.color = new Color(0.0f, 0.0f, 0.0f, 0.2f);
  146. GUI.Label(theRect, GUIContent.none, DirectorStyles.Instance.displayBackground);
  147. if (theRect.width > 36.0f)
  148. {
  149. var style = DirectorStyles.Instance.fontClipLoop;
  150. GUI.color = new Color(0.0f, 0.0f, 0.0f, 0.3f);
  151. var loopContent = new GUIContent(drawData.supportsLooping ? GetLoopString(loopIndex) : Styles.HoldText);
  152. GUI.Label(theRect, loopContent, style);
  153. }
  154. }
  155. }
  156. loopIndex++;
  157. if (!drawData.supportsLooping)
  158. break;
  159. }
  160. GUI.color = oldColor;
  161. }
  162. static void DrawClipBorder(ClipDrawData drawData)
  163. {
  164. var animTrack = drawData.clip.parentTrack as AnimationTrack;
  165. var selectionBorder = ClipBorder.Selection();
  166. if (TimelineWindow.instance.state.recording && animTrack == null && drawData.clip.parentTrack.IsRecordingToClip(drawData.clip))
  167. {
  168. DrawClipSelectionBorder(drawData.clipCenterSection, selectionBorder, drawData.clipBlends);
  169. return;
  170. }
  171. DrawClipDefaultBorder(drawData.clipCenterSection, ClipBorder.Default(), drawData.clipBlends);
  172. if (drawData.selected)
  173. DrawClipSelectionBorder(drawData.clipCenterSection, selectionBorder, drawData.clipBlends);
  174. if (drawData.previousClip != null && drawData.previousClipSelected)
  175. DrawClipBlendSelectionBorder(drawData.clipCenterSection, selectionBorder, drawData.clipBlends);
  176. }
  177. public static void DrawClipSelectionBorder(Rect clipRect, ClipBorder border, ClipBlends blends)
  178. {
  179. var thickness = border.thickness;
  180. var color = border.color;
  181. var min = clipRect.min;
  182. var max = clipRect.max;
  183. //Left line
  184. if (blends.inKind == BlendKind.None)
  185. EditorGUI.DrawRect(new Rect(min.x, min.y, thickness, max.y - min.y), color);
  186. else
  187. DrawBlendLine(blends.inRect, blends.inKind == BlendKind.Mix ? BlendAngle.Descending : BlendAngle.Ascending, thickness, color);
  188. //Right line
  189. if (blends.outKind == BlendKind.None)
  190. EditorGUI.DrawRect(new Rect(max.x - thickness, min.y, thickness, max.y - min.y), color);
  191. else
  192. DrawBlendLine(blends.outRect, BlendAngle.Descending, thickness, color);
  193. //Top line
  194. var xTop1 = blends.inKind == BlendKind.Mix ? blends.inRect.xMin : min.x;
  195. var xTop2 = max.x;
  196. EditorGUI.DrawRect(new Rect(xTop1, min.y, xTop2 - xTop1, thickness), color);
  197. //Bottom line
  198. var xBottom1 = blends.inKind == BlendKind.Ease ? blends.inRect.xMin : min.x;
  199. var xBottom2 = blends.outKind == BlendKind.None ? max.x : blends.outRect.xMax;
  200. EditorGUI.DrawRect(new Rect(xBottom1, max.y - thickness, xBottom2 - xBottom1, thickness), color);
  201. }
  202. static Vector3[] s_BlendLines = new Vector3[4];
  203. static void DrawBlendLine(Rect rect, BlendAngle blendAngle, float width, Color color)
  204. {
  205. var halfWidth = width / 2.0f;
  206. Vector2 p0, p1;
  207. var inverse = 1.0f;
  208. if (blendAngle == BlendAngle.Descending)
  209. {
  210. p0 = rect.min;
  211. p1 = rect.max;
  212. }
  213. else
  214. {
  215. p0 = new Vector2(rect.xMax, rect.yMin);
  216. p1 = new Vector2(rect.xMin, rect.yMax);
  217. inverse = -1.0f;
  218. }
  219. s_BlendLines[0] = new Vector3(p0.x - halfWidth, p0.y + halfWidth * inverse);
  220. s_BlendLines[1] = new Vector3(p1.x - halfWidth, p1.y + halfWidth * inverse);
  221. s_BlendLines[2] = new Vector3(p1.x + halfWidth, p1.y - halfWidth * inverse);
  222. s_BlendLines[3] = new Vector3(p0.x + halfWidth, p0.y - halfWidth * inverse);
  223. Graphics.DrawPolygonAA(color, s_BlendLines);
  224. }
  225. static void DrawClipBlendSelectionBorder(Rect clipRect, ClipBorder border, ClipBlends blends)
  226. {
  227. var color = border.color;
  228. var thickness = border.thickness;
  229. if (blends.inKind == BlendKind.Mix)
  230. {
  231. DrawBlendLine(blends.inRect, BlendAngle.Descending, thickness, color);
  232. var xBottom1 = blends.inRect.xMin;
  233. var xBottom2 = blends.inRect.xMax;
  234. EditorGUI.DrawRect(new Rect(xBottom1, clipRect.max.y - thickness, xBottom2 - xBottom1, thickness), color);
  235. }
  236. }
  237. static void DrawClipDefaultBorder(Rect clipRect, ClipBorder border, ClipBlends blends)
  238. {
  239. var color = border.color;
  240. var thickness = border.thickness;
  241. // Draw vertical lines at the edges of the clip
  242. EditorGUI.DrawRect(new Rect(clipRect.xMin, clipRect.y, thickness, clipRect.height), color); //left
  243. //only draw the right one when no out mix blend
  244. if (blends.outKind != BlendKind.Mix)
  245. EditorGUI.DrawRect(new Rect(clipRect.xMax - thickness, clipRect.y, thickness, clipRect.height), color); //right
  246. //draw a vertical line for the previous clip
  247. if (blends.inKind == BlendKind.Mix)
  248. EditorGUI.DrawRect(new Rect(blends.inRect.xMin, blends.inRect.y, thickness, blends.inRect.height), color); //left
  249. //Draw blend line
  250. if (blends.inKind == BlendKind.Mix)
  251. DrawBlendLine(blends.inRect, BlendAngle.Descending, thickness, color);
  252. }
  253. static void DrawClipTimescale(Rect targetRect, Rect clippedRect, double timeScale)
  254. {
  255. if (timeScale != 1.0)
  256. {
  257. const float xOffset = 4.0f;
  258. const float yOffset = 6.0f;
  259. var segmentLength = timeScale > 1.0f ? 5.0f : 15.0f;
  260. // clamp to the visible region to reduce the line count (case 1213189), but adject the start segment to match the visuals of drawing targetRect
  261. var startX = clippedRect.min.x - ((clippedRect.min.x - targetRect.min.x) % (segmentLength*2));
  262. var endX = clippedRect.max.x;
  263. var start = new Vector3(startX + xOffset, targetRect.min.y + yOffset, 0.0f);
  264. var end = new Vector3(endX - xOffset, targetRect.min.y + yOffset, 0.0f);
  265. Graphics.DrawDottedLine(start, end, segmentLength, DirectorStyles.Instance.customSkin.colorClipFont);
  266. Graphics.DrawDottedLine(start + new Vector3(0.0f, 1.0f, 0.0f), end + new Vector3(0.0f, 1.0f, 0.0f), segmentLength, DirectorStyles.Instance.customSkin.colorClipFont);
  267. }
  268. }
  269. static void DrawClipInOut(Rect targetRect, TimelineClip clip)
  270. {
  271. var assetDuration = TimelineHelpers.GetClipAssetEndTime(clip);
  272. bool drawClipOut = assetDuration<double.MaxValue &&
  273. assetDuration - clip.end> TimeUtility.kTimeEpsilon;
  274. bool drawClipIn = clip.clipIn > 0.0;
  275. if (!drawClipIn && !drawClipOut)
  276. return;
  277. var rect = targetRect;
  278. if (drawClipOut)
  279. {
  280. var icon = DirectorStyles.Instance.clipOut;
  281. var iconRect = new Rect(rect.xMax - icon.fixedWidth - 2.0f,
  282. rect.yMin + (rect.height - icon.fixedHeight) * 0.5f,
  283. icon.fixedWidth, icon.fixedHeight);
  284. GUI.Label(iconRect, GUIContent.none, icon);
  285. }
  286. if (drawClipIn)
  287. {
  288. var icon = DirectorStyles.Instance.clipIn;
  289. var iconRect = new Rect(2.0f + rect.xMin,
  290. rect.yMin + (rect.height - icon.fixedHeight) * 0.5f,
  291. icon.fixedWidth, icon.fixedHeight);
  292. GUI.Label(iconRect, GUIContent.none, icon);
  293. }
  294. }
  295. static void DrawClipLabel(ClipDrawData data, Rect availableRect, Color color)
  296. {
  297. var errorText = data.ClipDrawOptions.errorText;
  298. var hasError = !string.IsNullOrEmpty(errorText);
  299. var textColor = hasError ? DirectorStyles.kClipErrorColor : color;
  300. var tooltip = hasError ? errorText : data.ClipDrawOptions.tooltip;
  301. if (hasError)
  302. DrawClipLabel(data.title, availableRect, textColor, k_ClipErrorIcons, null, tooltip);
  303. else
  304. DrawClipLabel(data.title, availableRect, textColor, data.leftIcons, data.rightIcons, tooltip);
  305. }
  306. static void DrawClipLabel(string title, Rect availableRect, Color color, string errorText = "")
  307. {
  308. var hasError = !string.IsNullOrEmpty(errorText);
  309. var textColor = hasError ? DirectorStyles.kClipErrorColor : color;
  310. if (hasError)
  311. DrawClipLabel(title, availableRect, textColor, k_ClipErrorIcons, null, errorText);
  312. else
  313. DrawClipLabel(title, availableRect, textColor, null, null, errorText);
  314. }
  315. static void DrawClipLabel(string title, Rect availableRect, Color textColor, IconData[] leftIcons, IconData[] rightIcons, string tooltipMessage = "")
  316. {
  317. s_TitleContent.text = title;
  318. var neededTextWidth = DirectorStyles.Instance.fontClip.CalcSize(s_TitleContent).x;
  319. var neededIconWidthLeft = 0.0f;
  320. var neededIconWidthRight = 0.0f;
  321. if (leftIcons != null)
  322. for (int i = 0, n = leftIcons.Length; i < n; ++i)
  323. neededIconWidthLeft += leftIcons[i].width + k_IconsPadding;
  324. if (rightIcons != null)
  325. for (int i = 0, n = rightIcons.Length; i < n; ++i)
  326. neededIconWidthRight += rightIcons[i].width + k_IconsPadding;
  327. var neededIconWidth = Mathf.Max(neededIconWidthLeft, neededIconWidthRight);
  328. // Atomic operation: We either show all icons or no icons at all
  329. var showIcons = neededTextWidth / 2.0f + neededIconWidth < availableRect.width / 2.0f;
  330. if (showIcons)
  331. {
  332. if (leftIcons != null)
  333. DrawClipIcons(leftIcons, IconData.Side.Left, neededTextWidth, availableRect);
  334. if (rightIcons != null)
  335. DrawClipIcons(rightIcons, IconData.Side.Right, neededTextWidth, availableRect);
  336. }
  337. if (neededTextWidth > availableRect.width)
  338. s_TitleContent.text = DirectorStyles.Elipsify(title, availableRect.width, neededTextWidth);
  339. s_TitleContent.tooltip = tooltipMessage;
  340. DrawClipName(availableRect, s_TitleContent, textColor);
  341. }
  342. static void DrawClipIcons(IconData[] icons, IconData.Side side, float labelWidth, Rect availableRect)
  343. {
  344. var halfText = labelWidth / 2.0f;
  345. var offset = halfText + k_IconsPadding;
  346. foreach (var iconData in icons)
  347. {
  348. offset += iconData.width / 2.0f + k_IconsPadding;
  349. var iconRect =
  350. new Rect(0.0f, 0.0f, iconData.width, iconData.height)
  351. {
  352. center = new Vector2(availableRect.center.x + offset * (int)side, availableRect.center.y)
  353. };
  354. DrawIcon(iconRect, iconData.tint, iconData.icon);
  355. offset += iconData.width / 2.0f;
  356. }
  357. }
  358. static void DrawClipName(Rect rect, GUIContent content, Color textColor)
  359. {
  360. Graphics.ShadowLabel(rect, content, DirectorStyles.Instance.fontClip, textColor, Color.black);
  361. }
  362. static void DrawIcon(Rect imageRect, Color color, Texture2D icon)
  363. {
  364. GUI.DrawTexture(imageRect, icon, ScaleMode.ScaleAndCrop, true, 0, color, 0, 0);
  365. }
  366. static void DrawClipBackground(Rect clipCenterSection, bool selected)
  367. {
  368. if (Event.current.type != EventType.Repaint)
  369. return;
  370. var color = selected ? DirectorStyles.Instance.customSkin.clipSelectedBckg : DirectorStyles.Instance.customSkin.clipBckg;
  371. EditorGUI.DrawRect(clipCenterSection, color);
  372. }
  373. static Vector3[] s_BlendVertices = new Vector3[3];
  374. static void DrawClipBlends(ClipBlends blends, Color inColor, Color outColor, Color backgroundColor)
  375. {
  376. switch (blends.inKind)
  377. {
  378. case BlendKind.Ease:
  379. // 2
  380. // / |
  381. // / |
  382. // 0---1
  383. EditorGUI.DrawRect(blends.inRect, backgroundColor);
  384. s_BlendVertices[0] = new Vector3(blends.inRect.xMin, blends.inRect.yMax);
  385. s_BlendVertices[1] = new Vector3(blends.inRect.xMax, blends.inRect.yMax);
  386. s_BlendVertices[2] = new Vector3(blends.inRect.xMax, blends.inRect.yMin);
  387. Graphics.DrawPolygonAA(inColor, s_BlendVertices);
  388. break;
  389. case BlendKind.Mix:
  390. // 0---2
  391. // \ |
  392. // \ |
  393. // 1
  394. s_BlendVertices[0] = new Vector3(blends.inRect.xMin, blends.inRect.yMin);
  395. s_BlendVertices[1] = new Vector3(blends.inRect.xMax, blends.inRect.yMax);
  396. s_BlendVertices[2] = new Vector3(blends.inRect.xMax, blends.inRect.yMin);
  397. Graphics.DrawPolygonAA(inColor, s_BlendVertices);
  398. break;
  399. }
  400. if (blends.outKind != BlendKind.None)
  401. {
  402. if (blends.outKind == BlendKind.Ease)
  403. EditorGUI.DrawRect(blends.outRect, backgroundColor);
  404. // 0
  405. // | \
  406. // | \
  407. // 1---2
  408. s_BlendVertices[0] = new Vector3(blends.outRect.xMin, blends.outRect.yMin);
  409. s_BlendVertices[1] = new Vector3(blends.outRect.xMin, blends.outRect.yMax);
  410. s_BlendVertices[2] = new Vector3(blends.outRect.xMax, blends.outRect.yMax);
  411. Graphics.DrawPolygonAA(outColor, s_BlendVertices);
  412. }
  413. }
  414. static void DrawClipSwatch(Rect targetRect, Color swatchColor)
  415. {
  416. // Draw Colored Line at the bottom.
  417. var colorRect = targetRect;
  418. colorRect.yMin = colorRect.yMax - k_ClipSwatchLineThickness;
  419. EditorGUI.DrawRect(colorRect, swatchColor);
  420. }
  421. public static void DrawSimpleClip(TimelineClip clip, Rect targetRect, ClipBorder border, Color overlay, ClipDrawOptions drawOptions)
  422. {
  423. GUI.BeginClip(targetRect);
  424. var clipRect = new Rect(0.0f, 0.0f, targetRect.width, targetRect.height);
  425. var orgColor = GUI.color;
  426. GUI.color = overlay;
  427. DrawClipBackground(clipRect, false);
  428. GUI.color = orgColor;
  429. if (clipRect.width <= k_MinClipWidth)
  430. {
  431. clipRect.width = k_MinClipWidth;
  432. }
  433. DrawClipSwatch(targetRect, drawOptions.highlightColor * overlay);
  434. if (targetRect.width >= k_ClipInOutMinWidth)
  435. DrawClipInOut(clipRect, clip);
  436. var textRect = clipRect;
  437. textRect.xMin += k_ClipLabelPadding;
  438. textRect.xMax -= k_ClipLabelPadding;
  439. if (textRect.width > k_ClipLabelMinWidth)
  440. DrawClipLabel(clip.displayName, textRect, Color.white, drawOptions.errorText);
  441. if (border != null)
  442. DrawClipSelectionBorder(clipRect, border, ClipBlends.kNone);
  443. GUI.EndClip();
  444. }
  445. public static void DrawDefaultClip(ClipDrawData drawData)
  446. {
  447. var customSkin = DirectorStyles.Instance.customSkin;
  448. var blendInColor = drawData.selected ? customSkin.clipBlendInSelected : customSkin.clipBlendIn;
  449. var blendOutColor = drawData.selected ? customSkin.clipBlendOutSelected : customSkin.clipBlendOut;
  450. var easeBackgroundColor = customSkin.clipEaseBckgColor;
  451. DrawClipBlends(drawData.clipBlends, blendInColor, blendOutColor, easeBackgroundColor);
  452. DrawClipBackground(drawData.clipCenterSection, drawData.selected);
  453. if (drawData.targetRect.width > k_MinClipWidth)
  454. {
  455. DrawClipEditorBackground(drawData);
  456. }
  457. else
  458. {
  459. drawData.targetRect.width = k_MinClipWidth;
  460. drawData.clipCenterSection.width = k_MinClipWidth;
  461. }
  462. DrawClipTimescale(drawData.targetRect, drawData.clippedRect, drawData.clip.timeScale);
  463. if (drawData.targetRect.width >= k_ClipInOutMinWidth)
  464. DrawClipInOut(drawData.targetRect, drawData.clip);
  465. var labelRect = drawData.clipCenterSection;
  466. if (drawData.targetRect.width >= k_ClipLoopsMinWidth)
  467. {
  468. bool selected = drawData.selected || drawData.inlineCurvesSelected;
  469. if (selected)
  470. {
  471. if (drawData.loopRects != null && drawData.loopRects.Any())
  472. {
  473. DrawLoops(drawData);
  474. var l = drawData.loopRects[0];
  475. labelRect.xMax = Math.Min(labelRect.xMax, l.x - drawData.unclippedRect.x);
  476. }
  477. }
  478. }
  479. labelRect.xMin += k_ClipLabelPadding;
  480. labelRect.xMax -= k_ClipLabelPadding;
  481. if (labelRect.width > k_ClipLabelMinWidth)
  482. {
  483. DrawClipLabel(drawData, labelRect, Color.white);
  484. }
  485. DrawClipSwatch(drawData.targetRect, drawData.ClipDrawOptions.highlightColor);
  486. DrawClipBorder(drawData);
  487. }
  488. static void DrawClipEditorBackground(ClipDrawData drawData)
  489. {
  490. var isRepaint = (Event.current.type == EventType.Repaint);
  491. if (isRepaint && drawData.clipEditor != null)
  492. {
  493. var customBodyRect = drawData.clippedRect;
  494. customBodyRect.yMin += k_ClipInlineWidth;
  495. customBodyRect.yMax -= k_ClipSwatchLineThickness;
  496. var region = new ClipBackgroundRegion(customBodyRect, drawData.localVisibleStartTime, drawData.localVisibleEndTime);
  497. try
  498. {
  499. drawData.clipEditor.DrawBackground(drawData.clip, region);
  500. }
  501. catch (Exception e)
  502. {
  503. Debug.LogException(e);
  504. }
  505. }
  506. }
  507. public static void DrawAnimationRecordBorder(ClipDrawData drawData)
  508. {
  509. if (!drawData.clip.parentTrack.IsRecordingToClip(drawData.clip))
  510. return;
  511. var time = new DiscreteTime(TimelineWindow.instance.state.editSequence.time);
  512. var start = new DiscreteTime(drawData.clip.start + drawData.clip.mixInDuration);
  513. var end = new DiscreteTime(drawData.clip.end - drawData.clip.mixOutDuration);
  514. if (time < start || time >= end)
  515. return;
  516. DrawClipSelectionBorder(drawData.clipCenterSection, ClipBorder.Recording(), ClipBlends.kNone);
  517. }
  518. public static void DrawRecordProhibited(ClipDrawData drawData)
  519. {
  520. DrawRecordInvalidClip(drawData);
  521. DrawRecordOnBlend(drawData);
  522. }
  523. public static void DrawRecordOnBlend(ClipDrawData drawData)
  524. {
  525. double time = TimelineWindow.instance.state.editSequence.time;
  526. if (time >= drawData.clip.start && time < drawData.clip.start + drawData.clip.mixInDuration)
  527. {
  528. Rect r = Rect.MinMaxRect(drawData.clippedRect.xMin, drawData.clippedRect.yMin, drawData.clipCenterSection.xMin, drawData.clippedRect.yMax);
  529. DrawInvalidRecordIcon(r, Styles.s_ClipNoRecordInBlend);
  530. }
  531. if (time <= drawData.clip.end && time > drawData.clip.end - drawData.clip.mixOutDuration)
  532. {
  533. Rect r = Rect.MinMaxRect(drawData.clipCenterSection.xMax, drawData.clippedRect.yMin, drawData.clippedRect.xMax, drawData.clippedRect.yMax);
  534. DrawInvalidRecordIcon(r, Styles.s_ClipNoRecordInBlend);
  535. }
  536. }
  537. public static void DrawRecordInvalidClip(ClipDrawData drawData)
  538. {
  539. if (drawData.clip.recordable)
  540. return;
  541. double time = TimelineWindow.instance.state.editSequence.time;
  542. if (time < drawData.clip.start + drawData.clip.mixInDuration || time > drawData.clip.end - drawData.clip.mixOutDuration)
  543. return;
  544. DrawInvalidRecordIcon(drawData.clipCenterSection, Styles.s_ClipNotRecorable);
  545. }
  546. public static void DrawInvalidRecordIcon(Rect rect, GUIContent helpText)
  547. {
  548. EditorGUI.DrawRect(rect, new Color(0, 0, 0, 0.30f));
  549. var icon = Styles.s_IconNoRecord;
  550. if (rect.width < icon.width || rect.height < icon.height)
  551. return;
  552. float x = rect.x + (rect.width - icon.width) * 0.5f;
  553. float y = rect.y + (rect.height - icon.height) * 0.5f;
  554. Rect r = new Rect(x, y, icon.width, icon.height);
  555. GUI.Label(r, helpText);
  556. GUI.DrawTexture(r, icon, ScaleMode.ScaleAndCrop, true, 0, Color.white, 0, 0);
  557. }
  558. }
  559. }