No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ClipDrawer.cs 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  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. struct 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 = L10n.Tr("HOLD");
  100. public static readonly Texture2D s_IconNoRecord = EditorGUIUtility.LoadIcon("console.erroricon.sml");
  101. public static readonly GUIContent s_ClipNotRecorable = L10n.TextContent("", "This clip is not recordable");
  102. public static readonly GUIContent s_ClipNoRecordInBlend = L10n.TextContent("", "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.GetParentTrack() as AnimationTrack;
  165. var selectionBorder = ClipBorder.Selection();
  166. if (TimelineWindow.instance.state.recording && animTrack == null && drawData.clip.GetParentTrack().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. {
  176. bool shouldDrawLeftLine = Math.Abs(drawData.previousClip.start - drawData.clip.start) < double.Epsilon;
  177. DrawClipBlendSelectionBorder(drawData.clipCenterSection, selectionBorder, drawData.clipBlends, shouldDrawLeftLine);
  178. }
  179. }
  180. public static void DrawClipSelectionBorder(Rect clipRect, ClipBorder border, ClipBlends blends)
  181. {
  182. var thickness = border.thickness;
  183. var color = border.color;
  184. var min = clipRect.min;
  185. var max = clipRect.max;
  186. //Left line
  187. if (blends.inKind == BlendKind.None)
  188. EditorGUI.DrawRect(new Rect(min.x, min.y, thickness, max.y - min.y), color);
  189. else
  190. DrawBlendLine(blends.inRect, blends.inKind == BlendKind.Mix ? BlendAngle.Descending : BlendAngle.Ascending, thickness, color);
  191. //Right line
  192. if (blends.outKind == BlendKind.None)
  193. EditorGUI.DrawRect(new Rect(max.x - thickness, min.y, thickness, max.y - min.y), color);
  194. else
  195. DrawBlendLine(blends.outRect, BlendAngle.Descending, thickness, color);
  196. //Top line
  197. var xTop1 = blends.inKind == BlendKind.Mix ? blends.inRect.xMin : min.x;
  198. var xTop2 = max.x;
  199. EditorGUI.DrawRect(new Rect(xTop1, min.y, xTop2 - xTop1, thickness), color);
  200. //Bottom line
  201. var xBottom1 = blends.inKind == BlendKind.Ease ? blends.inRect.xMin : min.x;
  202. var xBottom2 = blends.outKind == BlendKind.None ? max.x : blends.outRect.xMax;
  203. EditorGUI.DrawRect(new Rect(xBottom1, max.y - thickness, xBottom2 - xBottom1, thickness), color);
  204. }
  205. static Vector3[] s_BlendLines = new Vector3[4];
  206. static void DrawBlendLine(Rect rect, BlendAngle blendAngle, float width, Color color)
  207. {
  208. var halfWidth = width / 2.0f;
  209. Vector2 p0, p1;
  210. var inverse = 1.0f;
  211. if (blendAngle == BlendAngle.Descending)
  212. {
  213. p0 = rect.min;
  214. p1 = rect.max;
  215. }
  216. else
  217. {
  218. p0 = new Vector2(rect.xMax, rect.yMin);
  219. p1 = new Vector2(rect.xMin, rect.yMax);
  220. inverse = -1.0f;
  221. }
  222. s_BlendLines[0] = new Vector3(p0.x - halfWidth, p0.y + halfWidth * inverse);
  223. s_BlendLines[1] = new Vector3(p1.x - halfWidth, p1.y + halfWidth * inverse);
  224. s_BlendLines[2] = new Vector3(p1.x + halfWidth, p1.y - halfWidth * inverse);
  225. s_BlendLines[3] = new Vector3(p0.x + halfWidth, p0.y - halfWidth * inverse);
  226. Graphics.DrawPolygonAA(color, s_BlendLines);
  227. }
  228. static void DrawClipBlendSelectionBorder(Rect clipRect, ClipBorder border, ClipBlends blends, bool shouldLeftLine = false)
  229. {
  230. var color = border.color;
  231. var thickness = border.thickness;
  232. if (blends.inKind == BlendKind.Mix)
  233. {
  234. DrawBlendLine(blends.inRect, BlendAngle.Descending, thickness, color);
  235. var xBottom1 = blends.inRect.xMin;
  236. var xBottom2 = blends.inRect.xMax;
  237. EditorGUI.DrawRect(new Rect(xBottom1, clipRect.max.y - thickness, xBottom2 - xBottom1, thickness), color);
  238. if (shouldLeftLine)
  239. EditorGUI.DrawRect(new Rect(xBottom1, clipRect.min.y, thickness, clipRect.max.y - clipRect.min.y), color);
  240. }
  241. }
  242. static void DrawClipDefaultBorder(Rect clipRect, ClipBorder border, ClipBlends blends)
  243. {
  244. var color = border.color;
  245. var thickness = border.thickness;
  246. // Draw vertical lines at the edges of the clip
  247. EditorGUI.DrawRect(new Rect(clipRect.xMin, clipRect.y, thickness, clipRect.height), color); //left
  248. //only draw the right one when no out mix blend
  249. if (blends.outKind != BlendKind.Mix)
  250. EditorGUI.DrawRect(new Rect(clipRect.xMax - thickness, clipRect.y, thickness, clipRect.height), color); //right
  251. //draw a vertical line for the previous clip
  252. if (blends.inKind == BlendKind.Mix)
  253. EditorGUI.DrawRect(new Rect(blends.inRect.xMin, blends.inRect.y, thickness, blends.inRect.height), color); //left
  254. //Draw blend line
  255. if (blends.inKind == BlendKind.Mix)
  256. DrawBlendLine(blends.inRect, BlendAngle.Descending, thickness, color);
  257. }
  258. static void DrawClipTimescale(Rect targetRect, Rect clippedRect, double timeScale)
  259. {
  260. if (timeScale != 1.0)
  261. {
  262. const float xOffset = 4.0f;
  263. const float yOffset = 6.0f;
  264. var segmentLength = timeScale > 1.0f ? 5.0f : 15.0f;
  265. // clamp to the visible region to reduce the line count (case 1213189), but adject the start segment to match the visuals of drawing targetRect
  266. var startX = clippedRect.min.x - ((clippedRect.min.x - targetRect.min.x) % (segmentLength * 2));
  267. var endX = clippedRect.max.x;
  268. var start = new Vector3(startX + xOffset, targetRect.min.y + yOffset, 0.0f);
  269. var end = new Vector3(endX - xOffset, targetRect.min.y + yOffset, 0.0f);
  270. Graphics.DrawDottedLine(start, end, segmentLength, DirectorStyles.Instance.customSkin.colorClipFont);
  271. 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);
  272. }
  273. }
  274. static void DrawClipInOut(Rect targetRect, TimelineClip clip)
  275. {
  276. var assetDuration = TimelineHelpers.GetClipAssetEndTime(clip);
  277. bool drawClipOut = assetDuration < double.MaxValue &&
  278. assetDuration - clip.end > TimeUtility.kTimeEpsilon;
  279. bool drawClipIn = clip.clipIn > 0.0;
  280. if (!drawClipIn && !drawClipOut)
  281. return;
  282. var rect = targetRect;
  283. if (drawClipOut)
  284. {
  285. var icon = DirectorStyles.Instance.clipOut;
  286. var iconRect = new Rect(rect.xMax - icon.fixedWidth - 2.0f,
  287. rect.yMin + (rect.height - icon.fixedHeight) * 0.5f,
  288. icon.fixedWidth, icon.fixedHeight);
  289. GUI.Label(iconRect, GUIContent.none, icon);
  290. }
  291. if (drawClipIn)
  292. {
  293. var icon = DirectorStyles.Instance.clipIn;
  294. var iconRect = new Rect(2.0f + rect.xMin,
  295. rect.yMin + (rect.height - icon.fixedHeight) * 0.5f,
  296. icon.fixedWidth, icon.fixedHeight);
  297. GUI.Label(iconRect, GUIContent.none, icon);
  298. }
  299. }
  300. static void DrawClipLabel(ClipDrawData data, Rect availableRect, Color color)
  301. {
  302. var errorText = data.ClipDrawOptions.errorText;
  303. var hasError = !string.IsNullOrEmpty(errorText);
  304. var textColor = hasError ? DirectorStyles.kClipErrorColor : color;
  305. var tooltip = hasError ? errorText : data.ClipDrawOptions.tooltip;
  306. var displayTitle = data.ClipDrawOptions.displayClipName;
  307. if (hasError)
  308. DrawClipLabel(data.title, availableRect, textColor, k_ClipErrorIcons, null, tooltip, displayTitle);
  309. else
  310. DrawClipLabel(data.title, availableRect, textColor, data.leftIcons, data.rightIcons, tooltip, displayTitle);
  311. }
  312. static void DrawClipLabel(string title, Rect availableRect, Color color, string errorText = "", bool displayTitle = true)
  313. {
  314. var hasError = !string.IsNullOrEmpty(errorText);
  315. var textColor = hasError ? DirectorStyles.kClipErrorColor : color;
  316. if (hasError)
  317. DrawClipLabel(title, availableRect, textColor, k_ClipErrorIcons, null, errorText, displayTitle);
  318. else
  319. DrawClipLabel(title, availableRect, textColor, null, null, errorText, displayTitle);
  320. }
  321. static void DrawClipLabel(string title, Rect availableRect, Color textColor, IconData[] leftIcons, IconData[] rightIcons, string tooltipMessage = "", bool displayTitle = true)
  322. {
  323. var neededIconWidthLeft = 0.0f;
  324. var neededIconWidthRight = 0.0f;
  325. if (leftIcons != null)
  326. for (int i = 0, n = leftIcons.Length; i < n; ++i)
  327. neededIconWidthLeft += leftIcons[i].width + k_IconsPadding;
  328. if (rightIcons != null)
  329. for (int i = 0, n = rightIcons.Length; i < n; ++i)
  330. neededIconWidthRight += rightIcons[i].width + k_IconsPadding;
  331. var neededIconWidth = Mathf.Max(neededIconWidthLeft, neededIconWidthRight);
  332. float iconPosX = availableRect.center.x;
  333. float halfTextWidth = 0;
  334. if (displayTitle)
  335. {
  336. s_TitleContent.text = title;
  337. var neededTextWidth = DirectorStyles.Instance.fontClip.CalcSize(s_TitleContent).x;
  338. if (neededTextWidth > availableRect.width)
  339. s_TitleContent.text = DirectorStyles.Elipsify(title, availableRect.width, neededTextWidth);
  340. halfTextWidth = neededTextWidth / 2.0f;
  341. }
  342. else
  343. {
  344. // text is set explicitly to an empty string to avoid drawing the default text on mac.
  345. s_TitleContent.text = String.Empty;
  346. iconPosX -= neededIconWidth / 2.0f;
  347. }
  348. // Atomic operation: We either show all icons or no icons at all
  349. if (halfTextWidth + neededIconWidth < availableRect.width / 2.0f)
  350. {
  351. if (leftIcons != null)
  352. DrawClipIcons(leftIcons, IconData.Side.Left, iconPosX - halfTextWidth, availableRect.center.y);
  353. if (rightIcons != null)
  354. DrawClipIcons(rightIcons, IconData.Side.Right, iconPosX + halfTextWidth, availableRect.center.y);
  355. }
  356. //draw label even if empty to display tooltip
  357. s_TitleContent.tooltip = tooltipMessage;
  358. DrawClipName(availableRect, s_TitleContent, textColor);
  359. }
  360. static void DrawClipIcons(IconData[] icons, IconData.Side side, float positionX, float positionY)
  361. {
  362. float offset = k_IconsPadding;
  363. foreach (var iconData in icons)
  364. {
  365. offset += (iconData.width / 2.0f + k_IconsPadding);
  366. var iconRect =
  367. new Rect(0.0f, 0.0f, iconData.width, iconData.height)
  368. {
  369. center = new Vector2(positionX + offset * (int)side, positionY)
  370. };
  371. DrawIcon(iconRect, iconData.tint, iconData.icon);
  372. offset += iconData.width / 2.0f;
  373. }
  374. }
  375. static void DrawClipName(Rect rect, GUIContent content, Color textColor)
  376. {
  377. Graphics.ShadowLabel(rect, content, DirectorStyles.Instance.fontClip, textColor, Color.black);
  378. }
  379. static void DrawIcon(Rect imageRect, Color color, Texture2D icon)
  380. {
  381. GUI.DrawTexture(imageRect, icon, ScaleMode.ScaleAndCrop, true, 0, color, 0, 0);
  382. }
  383. static void DrawClipBackground(Rect clipCenterSection, bool selected)
  384. {
  385. if (Event.current.type != EventType.Repaint)
  386. return;
  387. var color = selected ? DirectorStyles.Instance.customSkin.clipSelectedBckg : DirectorStyles.Instance.customSkin.clipBckg;
  388. EditorGUI.DrawRect(clipCenterSection, color);
  389. }
  390. static Vector3[] s_BlendVertices = new Vector3[3];
  391. static void DrawClipBlends(ClipBlends blends, Color inColor, Color outColor, Color backgroundColor)
  392. {
  393. switch (blends.inKind)
  394. {
  395. case BlendKind.Ease:
  396. // 2
  397. // / |
  398. // / |
  399. // 0---1
  400. EditorGUI.DrawRect(blends.inRect, backgroundColor);
  401. s_BlendVertices[0] = new Vector3(blends.inRect.xMin, blends.inRect.yMax);
  402. s_BlendVertices[1] = new Vector3(blends.inRect.xMax, blends.inRect.yMax);
  403. s_BlendVertices[2] = new Vector3(blends.inRect.xMax, blends.inRect.yMin);
  404. Graphics.DrawPolygonAA(inColor, s_BlendVertices);
  405. break;
  406. case BlendKind.Mix:
  407. // 0---2
  408. // \ |
  409. // \ |
  410. // 1
  411. s_BlendVertices[0] = new Vector3(blends.inRect.xMin, blends.inRect.yMin);
  412. s_BlendVertices[1] = new Vector3(blends.inRect.xMax, blends.inRect.yMax);
  413. s_BlendVertices[2] = new Vector3(blends.inRect.xMax, blends.inRect.yMin);
  414. Graphics.DrawPolygonAA(inColor, s_BlendVertices);
  415. break;
  416. }
  417. if (blends.outKind != BlendKind.None)
  418. {
  419. if (blends.outKind == BlendKind.Ease)
  420. EditorGUI.DrawRect(blends.outRect, backgroundColor);
  421. // 0
  422. // | \
  423. // | \
  424. // 1---2
  425. s_BlendVertices[0] = new Vector3(blends.outRect.xMin, blends.outRect.yMin);
  426. s_BlendVertices[1] = new Vector3(blends.outRect.xMin, blends.outRect.yMax);
  427. s_BlendVertices[2] = new Vector3(blends.outRect.xMax, blends.outRect.yMax);
  428. Graphics.DrawPolygonAA(outColor, s_BlendVertices);
  429. }
  430. }
  431. static void DrawClipSwatch(Rect targetRect, Color swatchColor)
  432. {
  433. // Draw Colored Line at the bottom.
  434. var colorRect = targetRect;
  435. colorRect.yMin = colorRect.yMax - k_ClipSwatchLineThickness;
  436. EditorGUI.DrawRect(colorRect, swatchColor);
  437. }
  438. public static void DrawSimpleClip(TimelineClip clip, Rect targetRect, ClipBorder border, Color overlay, ClipDrawOptions drawOptions)
  439. {
  440. GUI.BeginClip(targetRect);
  441. var clipRect = new Rect(0.0f, 0.0f, targetRect.width, targetRect.height);
  442. var orgColor = GUI.color;
  443. GUI.color = overlay;
  444. DrawClipBackground(clipRect, false);
  445. GUI.color = orgColor;
  446. if (clipRect.width <= k_MinClipWidth)
  447. {
  448. clipRect.width = k_MinClipWidth;
  449. }
  450. DrawClipSwatch(targetRect, drawOptions.highlightColor * overlay);
  451. if (targetRect.width >= k_ClipInOutMinWidth)
  452. DrawClipInOut(clipRect, clip);
  453. var textRect = clipRect;
  454. textRect.xMin += k_ClipLabelPadding;
  455. textRect.xMax -= k_ClipLabelPadding;
  456. if (textRect.width > k_ClipLabelMinWidth)
  457. DrawClipLabel(clip.displayName, textRect, Color.white, drawOptions.errorText, drawOptions.displayClipName);
  458. DrawClipSelectionBorder(clipRect, border, ClipBlends.kNone);
  459. GUI.EndClip();
  460. }
  461. public static void DrawDefaultClip(ClipDrawData drawData)
  462. {
  463. var customSkin = DirectorStyles.Instance.customSkin;
  464. var blendInColor = drawData.selected ? customSkin.clipBlendInSelected : customSkin.clipBlendIn;
  465. var blendOutColor = drawData.selected ? customSkin.clipBlendOutSelected : customSkin.clipBlendOut;
  466. var easeBackgroundColor = customSkin.clipEaseBckgColor;
  467. DrawClipBlends(drawData.clipBlends, blendInColor, blendOutColor, easeBackgroundColor);
  468. DrawClipBackground(drawData.clipCenterSection, drawData.selected);
  469. if (drawData.targetRect.width > k_MinClipWidth)
  470. {
  471. DrawClipEditorBackground(drawData);
  472. }
  473. else
  474. {
  475. drawData.targetRect.width = k_MinClipWidth;
  476. drawData.clipCenterSection.width = k_MinClipWidth;
  477. }
  478. if (!drawData.ClipDrawOptions.hideScaleIndicator)
  479. DrawClipTimescale(drawData.targetRect, drawData.clippedRect, drawData.clip.timeScale);
  480. if (drawData.targetRect.width >= k_ClipInOutMinWidth)
  481. DrawClipInOut(drawData.targetRect, drawData.clip);
  482. var labelRect = drawData.clipCenterSection;
  483. if (drawData.targetRect.width >= k_ClipLoopsMinWidth)
  484. {
  485. bool selected = drawData.selected || drawData.inlineCurvesSelected;
  486. if (selected)
  487. {
  488. if (drawData.loopRects != null && drawData.loopRects.Any())
  489. {
  490. DrawLoops(drawData);
  491. var l = drawData.loopRects[0];
  492. labelRect.xMax = Math.Min(labelRect.xMax, l.x - drawData.unclippedRect.x);
  493. }
  494. }
  495. }
  496. labelRect.xMin += k_ClipLabelPadding;
  497. labelRect.xMax -= k_ClipLabelPadding;
  498. if (labelRect.width > k_ClipLabelMinWidth)
  499. {
  500. DrawClipLabel(drawData, labelRect, Color.white);
  501. }
  502. DrawClipSwatch(drawData.targetRect, drawData.ClipDrawOptions.highlightColor);
  503. DrawClipBorder(drawData);
  504. }
  505. static void DrawClipEditorBackground(ClipDrawData drawData)
  506. {
  507. var isRepaint = (Event.current.type == EventType.Repaint);
  508. if (isRepaint && drawData.clipEditor != null)
  509. {
  510. var customBodyRect = drawData.clippedRect;
  511. customBodyRect.yMin += k_ClipInlineWidth;
  512. customBodyRect.yMax -= k_ClipSwatchLineThickness;
  513. var region = new ClipBackgroundRegion(customBodyRect, drawData.localVisibleStartTime, drawData.localVisibleEndTime);
  514. try
  515. {
  516. drawData.clipEditor.DrawBackground(drawData.clip, region);
  517. }
  518. catch (Exception e)
  519. {
  520. Debug.LogException(e);
  521. }
  522. }
  523. }
  524. public static void DrawAnimationRecordBorder(ClipDrawData drawData)
  525. {
  526. if (!drawData.clip.GetParentTrack().IsRecordingToClip(drawData.clip))
  527. return;
  528. var time = new DiscreteTime(TimelineWindow.instance.state.editSequence.time);
  529. var start = new DiscreteTime(drawData.clip.start + drawData.clip.mixInDuration);
  530. var end = new DiscreteTime(drawData.clip.end - drawData.clip.mixOutDuration);
  531. if (time < start || time >= end)
  532. return;
  533. DrawClipSelectionBorder(drawData.clipCenterSection, ClipBorder.Recording(), ClipBlends.kNone);
  534. }
  535. public static void DrawRecordProhibited(ClipDrawData drawData)
  536. {
  537. DrawRecordInvalidClip(drawData);
  538. DrawRecordOnBlend(drawData);
  539. }
  540. public static void DrawRecordOnBlend(ClipDrawData drawData)
  541. {
  542. double time = TimelineWindow.instance.state.editSequence.time;
  543. if (time >= drawData.clip.start && time < drawData.clip.start + drawData.clip.mixInDuration)
  544. {
  545. Rect r = Rect.MinMaxRect(drawData.clippedRect.xMin, drawData.clippedRect.yMin, drawData.clipCenterSection.xMin, drawData.clippedRect.yMax);
  546. DrawInvalidRecordIcon(r, Styles.s_ClipNoRecordInBlend);
  547. }
  548. if (time <= drawData.clip.end && time > drawData.clip.end - drawData.clip.mixOutDuration)
  549. {
  550. Rect r = Rect.MinMaxRect(drawData.clipCenterSection.xMax, drawData.clippedRect.yMin, drawData.clippedRect.xMax, drawData.clippedRect.yMax);
  551. DrawInvalidRecordIcon(r, Styles.s_ClipNoRecordInBlend);
  552. }
  553. }
  554. public static void DrawRecordInvalidClip(ClipDrawData drawData)
  555. {
  556. if (drawData.clip.recordable)
  557. return;
  558. double time = TimelineWindow.instance.state.editSequence.time;
  559. if (time < drawData.clip.start + drawData.clip.mixInDuration || time > drawData.clip.end - drawData.clip.mixOutDuration)
  560. return;
  561. DrawInvalidRecordIcon(drawData.clipCenterSection, Styles.s_ClipNotRecorable);
  562. }
  563. public static void DrawInvalidRecordIcon(Rect rect, GUIContent helpText)
  564. {
  565. EditorGUI.DrawRect(rect, new Color(0, 0, 0, 0.30f));
  566. var icon = Styles.s_IconNoRecord;
  567. if (rect.width < icon.width || rect.height < icon.height)
  568. return;
  569. float x = rect.x + (rect.width - icon.width) * 0.5f;
  570. float y = rect.y + (rect.height - icon.height) * 0.5f;
  571. Rect r = new Rect(x, y, icon.width, icon.height);
  572. GUI.Label(r, helpText);
  573. GUI.DrawTexture(r, icon, ScaleMode.ScaleAndCrop, true, 0, Color.white, 0, 0);
  574. }
  575. }
  576. }