ClipDrawer.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  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, 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. var start = new Vector3(targetRect.min.x + xOffset, targetRect.min.y + yOffset, 0.0f);
  261. var end = new Vector3(targetRect.max.x - xOffset, targetRect.min.y + yOffset, 0.0f);
  262. Graphics.DrawDottedLine(start, end, segmentLength, DirectorStyles.Instance.customSkin.colorClipFont);
  263. 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);
  264. }
  265. }
  266. static void DrawClipInOut(Rect targetRect, TimelineClip clip)
  267. {
  268. var assetDuration = TimelineHelpers.GetClipAssetEndTime(clip);
  269. bool drawClipOut = assetDuration<double.MaxValue &&
  270. assetDuration - clip.end> TimeUtility.kTimeEpsilon;
  271. bool drawClipIn = clip.clipIn > 0.0;
  272. if (!drawClipIn && !drawClipOut)
  273. return;
  274. var rect = targetRect;
  275. if (drawClipOut)
  276. {
  277. var icon = DirectorStyles.Instance.clipOut;
  278. var iconRect = new Rect(rect.xMax - icon.fixedWidth - 2.0f,
  279. rect.yMin + (rect.height - icon.fixedHeight) * 0.5f,
  280. icon.fixedWidth, icon.fixedHeight);
  281. GUI.Label(iconRect, GUIContent.none, icon);
  282. }
  283. if (drawClipIn)
  284. {
  285. var icon = DirectorStyles.Instance.clipIn;
  286. var iconRect = new Rect(2.0f + rect.xMin,
  287. rect.yMin + (rect.height - icon.fixedHeight) * 0.5f,
  288. icon.fixedWidth, icon.fixedHeight);
  289. GUI.Label(iconRect, GUIContent.none, icon);
  290. }
  291. }
  292. static void DrawClipLabel(ClipDrawData data, Rect availableRect, Color color)
  293. {
  294. var errorText = data.ClipDrawOptions.errorText;
  295. var hasError = !string.IsNullOrEmpty(errorText);
  296. var textColor = hasError ? DirectorStyles.kClipErrorColor : color;
  297. var tooltip = hasError ? errorText : data.ClipDrawOptions.tooltip;
  298. if (hasError)
  299. DrawClipLabel(data.title, availableRect, textColor, k_ClipErrorIcons, null, tooltip);
  300. else
  301. DrawClipLabel(data.title, availableRect, textColor, data.leftIcons, data.rightIcons, tooltip);
  302. }
  303. static void DrawClipLabel(string title, Rect availableRect, Color color, string errorText = "")
  304. {
  305. var hasError = !string.IsNullOrEmpty(errorText);
  306. var textColor = hasError ? DirectorStyles.kClipErrorColor : color;
  307. if (hasError)
  308. DrawClipLabel(title, availableRect, textColor, k_ClipErrorIcons, null, errorText);
  309. else
  310. DrawClipLabel(title, availableRect, textColor, null, null, errorText);
  311. }
  312. static void DrawClipLabel(string title, Rect availableRect, Color textColor, IconData[] leftIcons, IconData[] rightIcons, string tooltipMessage = "")
  313. {
  314. s_TitleContent.text = title;
  315. var neededTextWidth = DirectorStyles.Instance.fontClip.CalcSize(s_TitleContent).x;
  316. var neededIconWidthLeft = 0.0f;
  317. var neededIconWidthRight = 0.0f;
  318. if (leftIcons != null)
  319. for (int i = 0, n = leftIcons.Length; i < n; ++i)
  320. neededIconWidthLeft += leftIcons[i].width + k_IconsPadding;
  321. if (rightIcons != null)
  322. for (int i = 0, n = rightIcons.Length; i < n; ++i)
  323. neededIconWidthRight += rightIcons[i].width + k_IconsPadding;
  324. var neededIconWidth = Mathf.Max(neededIconWidthLeft, neededIconWidthRight);
  325. // Atomic operation: We either show all icons or no icons at all
  326. var showIcons = neededTextWidth / 2.0f + neededIconWidth < availableRect.width / 2.0f;
  327. if (showIcons)
  328. {
  329. if (leftIcons != null)
  330. DrawClipIcons(leftIcons, IconData.Side.Left, neededTextWidth, availableRect);
  331. if (rightIcons != null)
  332. DrawClipIcons(rightIcons, IconData.Side.Right, neededTextWidth, availableRect);
  333. }
  334. if (neededTextWidth > availableRect.width)
  335. s_TitleContent.text = DirectorStyles.Elipsify(title, availableRect.width, neededTextWidth);
  336. s_TitleContent.tooltip = tooltipMessage;
  337. DrawClipName(availableRect, s_TitleContent, textColor);
  338. }
  339. static void DrawClipIcons(IconData[] icons, IconData.Side side, float labelWidth, Rect availableRect)
  340. {
  341. var halfText = labelWidth / 2.0f;
  342. var offset = halfText + k_IconsPadding;
  343. foreach (var iconData in icons)
  344. {
  345. offset += iconData.width / 2.0f + k_IconsPadding;
  346. var iconRect =
  347. new Rect(0.0f, 0.0f, iconData.width, iconData.height)
  348. {
  349. center = new Vector2(availableRect.center.x + offset * (int)side, availableRect.center.y)
  350. };
  351. DrawIcon(iconRect, iconData.tint, iconData.icon);
  352. offset += iconData.width / 2.0f;
  353. }
  354. }
  355. static void DrawClipName(Rect rect, GUIContent content, Color textColor)
  356. {
  357. Graphics.ShadowLabel(rect, content, DirectorStyles.Instance.fontClip, textColor, Color.black);
  358. }
  359. static void DrawIcon(Rect imageRect, Color color, Texture2D icon)
  360. {
  361. GUI.DrawTexture(imageRect, icon, ScaleMode.ScaleAndCrop, true, 0, color, 0, 0);
  362. }
  363. static void DrawClipBackground(Rect clipCenterSection, bool selected)
  364. {
  365. if (Event.current.type != EventType.Repaint)
  366. return;
  367. var color = selected ? DirectorStyles.Instance.customSkin.clipSelectedBckg : DirectorStyles.Instance.customSkin.clipBckg;
  368. EditorGUI.DrawRect(clipCenterSection, color);
  369. }
  370. static Vector3[] s_BlendVertices = new Vector3[3];
  371. static void DrawClipBlends(ClipBlends blends, Color inColor, Color outColor, Color backgroundColor)
  372. {
  373. switch (blends.inKind)
  374. {
  375. case BlendKind.Ease:
  376. // 2
  377. // / |
  378. // / |
  379. // 0---1
  380. EditorGUI.DrawRect(blends.inRect, backgroundColor);
  381. s_BlendVertices[0] = new Vector3(blends.inRect.xMin, blends.inRect.yMax);
  382. s_BlendVertices[1] = new Vector3(blends.inRect.xMax, blends.inRect.yMax);
  383. s_BlendVertices[2] = new Vector3(blends.inRect.xMax, blends.inRect.yMin);
  384. Graphics.DrawPolygonAA(inColor, s_BlendVertices);
  385. break;
  386. case BlendKind.Mix:
  387. // 0---2
  388. // \ |
  389. // \ |
  390. // 1
  391. s_BlendVertices[0] = new Vector3(blends.inRect.xMin, blends.inRect.yMin);
  392. s_BlendVertices[1] = new Vector3(blends.inRect.xMax, blends.inRect.yMax);
  393. s_BlendVertices[2] = new Vector3(blends.inRect.xMax, blends.inRect.yMin);
  394. Graphics.DrawPolygonAA(inColor, s_BlendVertices);
  395. break;
  396. }
  397. if (blends.outKind != BlendKind.None)
  398. {
  399. if (blends.outKind == BlendKind.Ease)
  400. EditorGUI.DrawRect(blends.outRect, backgroundColor);
  401. // 0
  402. // | \
  403. // | \
  404. // 1---2
  405. s_BlendVertices[0] = new Vector3(blends.outRect.xMin, blends.outRect.yMin);
  406. s_BlendVertices[1] = new Vector3(blends.outRect.xMin, blends.outRect.yMax);
  407. s_BlendVertices[2] = new Vector3(blends.outRect.xMax, blends.outRect.yMax);
  408. Graphics.DrawPolygonAA(outColor, s_BlendVertices);
  409. }
  410. }
  411. static void DrawClipSwatch(Rect targetRect, Color swatchColor)
  412. {
  413. // Draw Colored Line at the bottom.
  414. var colorRect = targetRect;
  415. colorRect.yMin = colorRect.yMax - k_ClipSwatchLineThickness;
  416. EditorGUI.DrawRect(colorRect, swatchColor);
  417. }
  418. public static void DrawSimpleClip(TimelineClip clip, Rect targetRect, ClipBorder border, Color overlay, ClipDrawOptions drawOptions)
  419. {
  420. GUI.BeginClip(targetRect);
  421. var clipRect = new Rect(0.0f, 0.0f, targetRect.width, targetRect.height);
  422. var orgColor = GUI.color;
  423. GUI.color = overlay;
  424. DrawClipBackground(clipRect, false);
  425. GUI.color = orgColor;
  426. if (clipRect.width <= k_MinClipWidth)
  427. {
  428. clipRect.width = k_MinClipWidth;
  429. }
  430. DrawClipSwatch(targetRect, drawOptions.highlightColor * overlay);
  431. if (targetRect.width >= k_ClipInOutMinWidth)
  432. DrawClipInOut(clipRect, clip);
  433. var textRect = clipRect;
  434. textRect.xMin += k_ClipLabelPadding;
  435. textRect.xMax -= k_ClipLabelPadding;
  436. if (textRect.width > k_ClipLabelMinWidth)
  437. DrawClipLabel(clip.displayName, textRect, Color.white, drawOptions.errorText);
  438. if (border != null)
  439. DrawClipSelectionBorder(clipRect, border, ClipBlends.kNone);
  440. GUI.EndClip();
  441. }
  442. public static void DrawDefaultClip(ClipDrawData drawData)
  443. {
  444. var customSkin = DirectorStyles.Instance.customSkin;
  445. var blendInColor = drawData.selected ? customSkin.clipBlendInSelected : customSkin.clipBlendIn;
  446. var blendOutColor = drawData.selected ? customSkin.clipBlendOutSelected : customSkin.clipBlendOut;
  447. var easeBackgroundColor = customSkin.clipEaseBckgColor;
  448. DrawClipBlends(drawData.clipBlends, blendInColor, blendOutColor, easeBackgroundColor);
  449. DrawClipBackground(drawData.clipCenterSection, drawData.selected);
  450. if (drawData.targetRect.width > k_MinClipWidth)
  451. {
  452. DrawClipEditorBackground(drawData);
  453. }
  454. else
  455. {
  456. drawData.targetRect.width = k_MinClipWidth;
  457. drawData.clipCenterSection.width = k_MinClipWidth;
  458. }
  459. DrawClipTimescale(drawData.targetRect, drawData.clip.timeScale);
  460. if (drawData.targetRect.width >= k_ClipInOutMinWidth)
  461. DrawClipInOut(drawData.targetRect, drawData.clip);
  462. var labelRect = drawData.clipCenterSection;
  463. if (drawData.targetRect.width >= k_ClipLoopsMinWidth)
  464. {
  465. bool selected = drawData.selected || drawData.inlineCurvesSelected;
  466. if (selected)
  467. {
  468. if (drawData.loopRects != null && drawData.loopRects.Any())
  469. {
  470. DrawLoops(drawData);
  471. var l = drawData.loopRects[0];
  472. labelRect.xMax = Math.Min(labelRect.xMax, l.x - drawData.unclippedRect.x);
  473. }
  474. }
  475. }
  476. labelRect.xMin += k_ClipLabelPadding;
  477. labelRect.xMax -= k_ClipLabelPadding;
  478. if (labelRect.width > k_ClipLabelMinWidth)
  479. {
  480. DrawClipLabel(drawData, labelRect, Color.white);
  481. }
  482. DrawClipSwatch(drawData.targetRect, drawData.ClipDrawOptions.highlightColor);
  483. DrawClipBorder(drawData);
  484. }
  485. static void DrawClipEditorBackground(ClipDrawData drawData)
  486. {
  487. var isRepaint = (Event.current.type == EventType.Repaint);
  488. if (isRepaint && drawData.clipEditor != null)
  489. {
  490. var customBodyRect = drawData.clippedRect;
  491. customBodyRect.yMin += k_ClipInlineWidth;
  492. customBodyRect.yMax -= k_ClipSwatchLineThickness;
  493. var region = new ClipBackgroundRegion(customBodyRect, drawData.localVisibleStartTime, drawData.localVisibleEndTime);
  494. try
  495. {
  496. drawData.clipEditor.DrawBackground(drawData.clip, region);
  497. }
  498. catch (Exception e)
  499. {
  500. Debug.LogException(e);
  501. }
  502. }
  503. }
  504. public static void DrawAnimationRecordBorder(ClipDrawData drawData)
  505. {
  506. if (!drawData.clip.parentTrack.IsRecordingToClip(drawData.clip))
  507. return;
  508. var time = TimelineWindow.instance.state.editSequence.time;
  509. if (time < drawData.clip.start + drawData.clip.mixInDuration || time > drawData.clip.end - drawData.clip.mixOutDuration)
  510. return;
  511. DrawClipSelectionBorder(drawData.clipCenterSection, ClipBorder.Recording(), ClipBlends.kNone);
  512. }
  513. public static void DrawRecordProhibited(ClipDrawData drawData)
  514. {
  515. DrawRecordInvalidClip(drawData);
  516. DrawRecordOnBlend(drawData);
  517. }
  518. public static void DrawRecordOnBlend(ClipDrawData drawData)
  519. {
  520. double time = TimelineWindow.instance.state.editSequence.time;
  521. if (time >= drawData.clip.start && time < drawData.clip.start + drawData.clip.mixInDuration)
  522. {
  523. Rect r = Rect.MinMaxRect(drawData.clippedRect.xMin, drawData.clippedRect.yMin, drawData.clipCenterSection.xMin, drawData.clippedRect.yMax);
  524. DrawInvalidRecordIcon(r, Styles.s_ClipNoRecordInBlend);
  525. }
  526. if (time <= drawData.clip.end && time > drawData.clip.end - drawData.clip.mixOutDuration)
  527. {
  528. Rect r = Rect.MinMaxRect(drawData.clipCenterSection.xMax, drawData.clippedRect.yMin, drawData.clippedRect.xMax, drawData.clippedRect.yMax);
  529. DrawInvalidRecordIcon(r, Styles.s_ClipNoRecordInBlend);
  530. }
  531. }
  532. public static void DrawRecordInvalidClip(ClipDrawData drawData)
  533. {
  534. if (drawData.clip.recordable)
  535. return;
  536. double time = TimelineWindow.instance.state.editSequence.time;
  537. if (time < drawData.clip.start + drawData.clip.mixInDuration || time > drawData.clip.end - drawData.clip.mixOutDuration)
  538. return;
  539. DrawInvalidRecordIcon(drawData.clipCenterSection, Styles.s_ClipNotRecorable);
  540. }
  541. public static void DrawInvalidRecordIcon(Rect rect, GUIContent helpText)
  542. {
  543. EditorGUI.DrawRect(rect, new Color(0, 0, 0, 0.30f));
  544. var icon = Styles.s_IconNoRecord;
  545. if (rect.width < icon.width || rect.height < icon.height)
  546. return;
  547. float x = rect.x + (rect.width - icon.width) * 0.5f;
  548. float y = rect.y + (rect.height - icon.height) * 0.5f;
  549. Rect r = new Rect(x, y, icon.width, icon.height);
  550. GUI.Label(r, helpText);
  551. GUI.DrawTexture(r, icon, ScaleMode.ScaleAndCrop, true, 0, Color.white, 0, 0);
  552. }
  553. }
  554. }