ClipDrawer.cs 27 KB

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