UnityStyles.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEditor;
  4. using UnityEditor.IMGUI.Controls;
  5. using UnityEngine;
  6. namespace Unity.PlasticSCM.Editor.UI
  7. {
  8. // Assumption: Members are called from an OnGUI method ( otherwise style composition will fail)
  9. internal static class UnityStyles
  10. {
  11. internal static void Initialize(
  12. Action repaintPlasticWindow)
  13. {
  14. mRepaintPlasticWindow = repaintPlasticWindow;
  15. mLazyBackgroundStyles.Add(WarningMessage);
  16. mLazyBackgroundStyles.Add(SplitterIndicator);
  17. mLazyBackgroundStyles.Add(PlasticWindow.ActiveTabUnderline);
  18. mLazyBackgroundStyles.Add(Notification.GreenNotification);
  19. mLazyBackgroundStyles.Add(Notification.RedNotification);
  20. mLazyBackgroundStyles.Add(CancelButton);
  21. mLazyBackgroundStyles.Add(Inspector.HeaderBackgroundStyle);
  22. mLazyBackgroundStyles.Add(Inspector.DisabledHeaderBackgroundStyle);
  23. }
  24. internal static class Colors
  25. {
  26. internal static Color Transparent = new Color(255f / 255, 255f / 255, 255f / 255, 0f / 255);
  27. internal static Color GreenBackground = new Color(34f / 255, 161f / 255, 63f / 255);
  28. internal static Color GreenText = new Color(0f / 255, 100f / 255, 0f / 255);
  29. internal static Color Red = new Color(194f / 255, 51f / 255, 62f / 255);
  30. internal static Color Warning = new Color(255f / 255, 255f / 255, 176f / 255);
  31. internal static Color Splitter = new Color(100f / 255, 100f / 255, 100f / 255);
  32. internal static Color BarBorder = EditorGUIUtility.isProSkin ?
  33. (Color)new Color32(35, 35, 35, 255) :
  34. (Color)new Color32(153, 153, 153, 255);
  35. #if UNITY_2019
  36. internal static Color InspectorHeaderBackground = (EditorGUIUtility.isProSkin) ?
  37. new Color(60f / 255, 60f / 255, 60f / 255) :
  38. new Color(203f / 255, 203f / 255, 203f / 255);
  39. #else
  40. internal static Color InspectorHeaderBackground = Transparent;
  41. #endif
  42. #if UNITY_2019_1_OR_NEWER
  43. internal static Color InspectorHeaderBackgroundDisabled = (EditorGUIUtility.isProSkin) ?
  44. new Color(58f / 255, 58f / 255, 58f / 255) :
  45. new Color(199f / 255, 199f / 255, 199f / 255);
  46. #else
  47. internal static Color InspectorHeaderBackgroundDisabled = (EditorGUIUtility.isProSkin) ?
  48. new Color(60f / 255, 60f / 255, 60f / 255) :
  49. new Color(210f / 255, 210f / 255, 210f / 255);
  50. #endif
  51. internal static Color TabUnderline = new Color(58f / 255, 121f / 255, 187f / 255);
  52. internal static Color Link = new Color(0f, 120f / 255, 218f / 255);
  53. internal static Color SecondaryLabel = (EditorGUIUtility.isProSkin) ?
  54. new Color(196f / 255, 196f / 255, 196f / 255) :
  55. new Color(105f / 255, 105f / 255, 105f / 255);
  56. internal static Color BackgroundBar = (EditorGUIUtility.isProSkin) ?
  57. new Color(35f / 255, 35f / 255, 35f / 255) :
  58. new Color(160f / 255, 160f / 255, 160f / 255);
  59. internal static Color TreeViewBackground = (EditorGUIUtility.isProSkin) ?
  60. new Color(48f / 255, 48f / 255, 48f / 255) :
  61. new Color(194f / 255, 194f / 255, 194f / 255);
  62. internal static Color CommentsBackground = (EditorGUIUtility.isProSkin) ?
  63. new Color(60f / 255, 60f / 255, 60f / 255) :
  64. new Color(160f / 255, 160f / 255, 160f / 255);
  65. internal static Color ColumnsBackground = (EditorGUIUtility.isProSkin) ?
  66. new Color(56f / 255, 56f / 255, 56f / 255) :
  67. new Color(221f / 255, 221f / 255, 221f / 255);
  68. }
  69. internal static class HexColors
  70. {
  71. internal const string LINK_COLOR = "#0078DA";
  72. }
  73. internal static class Dialog
  74. {
  75. internal static readonly LazyStyle MessageTitle = new LazyStyle(() =>
  76. {
  77. var style = new GUIStyle(EditorStyles.boldLabel);
  78. style.contentOffset = new Vector2(0, -5);
  79. style.wordWrap = true;
  80. style.fontSize = MODAL_FONT_SIZE + 1;
  81. return style;
  82. });
  83. internal static readonly LazyStyle MessageText = new LazyStyle(() =>
  84. {
  85. var style = new GUIStyle(EditorStyles.label);
  86. style.wordWrap = true;
  87. style.fontSize = MODAL_FONT_SIZE;
  88. return style;
  89. });
  90. internal static readonly LazyStyle Toggle = new LazyStyle(() =>
  91. {
  92. var style = new GUIStyle(EditorStyles.boldLabel);
  93. style.fontSize = MODAL_FONT_SIZE;
  94. style.clipping = TextClipping.Overflow;
  95. return style;
  96. });
  97. internal static readonly LazyStyle RadioToggle = new LazyStyle(() =>
  98. {
  99. var radioToggleStyle = new GUIStyle(EditorStyles.radioButton);
  100. radioToggleStyle.fontSize = MODAL_FONT_SIZE;
  101. radioToggleStyle.clipping = TextClipping.Overflow;
  102. radioToggleStyle.font = EditorStyles.largeLabel.font;
  103. return radioToggleStyle;
  104. });
  105. internal static readonly LazyStyle Foldout = new LazyStyle(() =>
  106. {
  107. GUIStyle paragraphStyle = Paragraph;
  108. var foldoutStyle = new GUIStyle(EditorStyles.foldout);
  109. foldoutStyle.fontSize = MODAL_FONT_SIZE;
  110. foldoutStyle.font = paragraphStyle.font;
  111. return foldoutStyle;
  112. });
  113. internal static readonly LazyStyle EntryLabel = new LazyStyle(() =>
  114. {
  115. var style = new GUIStyle(EditorStyles.textField);
  116. style.wordWrap = true;
  117. style.fontSize = MODAL_FONT_SIZE;
  118. return style;
  119. });
  120. internal static readonly LazyStyle AcceptButtonText = new LazyStyle(() =>
  121. {
  122. var style = new GUIStyle(GetEditorSkin().GetStyle("WhiteLabel"));
  123. style.alignment = TextAnchor.MiddleCenter;
  124. style.fontSize = MODAL_FONT_SIZE + 1;
  125. style.normal.background = null;
  126. return style;
  127. });
  128. internal static readonly LazyStyle NormalButton = new LazyStyle(() =>
  129. {
  130. var style = new GUIStyle(GetEditorSkin().button);
  131. style.alignment = TextAnchor.MiddleCenter;
  132. style.fontSize = MODAL_FONT_SIZE;
  133. return style;
  134. });
  135. }
  136. internal static class Tree
  137. {
  138. internal static readonly LazyStyle IconStyle = new LazyStyle(() =>
  139. {
  140. var style = new GUIStyle(EditorStyles.largeLabel);
  141. style.alignment = TextAnchor.MiddleLeft;
  142. return style;
  143. });
  144. internal static readonly LazyStyle Label = new LazyStyle(() =>
  145. {
  146. var style = new GUIStyle(TreeView.DefaultStyles.label);
  147. style.fontSize = 11;
  148. style.alignment = TextAnchor.MiddleLeft;
  149. return style;
  150. });
  151. internal static readonly LazyStyle SecondaryLabel = new LazyStyle(() =>
  152. {
  153. var style = new GUIStyle(TreeView.DefaultStyles.label);
  154. style.fontSize = 11;
  155. style.alignment = TextAnchor.MiddleLeft;
  156. style.active = new GUIStyleState() { textColor = Colors.SecondaryLabel };
  157. style.focused = new GUIStyleState() { textColor = Colors.SecondaryLabel };
  158. style.hover = new GUIStyleState() { textColor = Colors.SecondaryLabel };
  159. style.normal = new GUIStyleState() { textColor = Colors.SecondaryLabel };
  160. return style;
  161. });
  162. internal static readonly LazyStyle InfoLabel = new LazyStyle(() =>
  163. {
  164. var style = new GUIStyle(MultiColumnHeader.DefaultStyles.columnHeader);
  165. return style;
  166. });
  167. internal static readonly LazyStyle SecondaryBoldLabel = new LazyStyle(() =>
  168. {
  169. var style = new GUIStyle(SecondaryLabel);
  170. style.fontStyle = FontStyle.Bold;
  171. return style;
  172. });
  173. internal static readonly LazyStyle RedLabel = new LazyStyle(() =>
  174. {
  175. var style = new GUIStyle(Label);
  176. style.active = new GUIStyleState() { textColor = Colors.Red };
  177. style.focused = new GUIStyleState() { textColor = Colors.Red };
  178. style.hover = new GUIStyleState() { textColor = Colors.Red };
  179. style.normal = new GUIStyleState() { textColor = Colors.Red };
  180. return style;
  181. });
  182. internal static readonly LazyStyle GreenLabel = new LazyStyle(() =>
  183. {
  184. var style = new GUIStyle(Label);
  185. style.active = new GUIStyleState() { textColor = Colors.GreenText };
  186. style.focused = new GUIStyleState() { textColor = Colors.GreenText };
  187. style.hover = new GUIStyleState() { textColor = Colors.GreenText };
  188. style.normal = new GUIStyleState() { textColor = Colors.GreenText };
  189. return style;
  190. });
  191. internal static readonly LazyStyle BoldLabel = new LazyStyle(() =>
  192. {
  193. var style = new GUIStyle(TreeView.DefaultStyles.boldLabel);
  194. style.fontSize = 11;
  195. style.alignment = TextAnchor.MiddleLeft;
  196. return style;
  197. });
  198. internal static readonly LazyStyle LabelRightAligned = new LazyStyle(() =>
  199. {
  200. var style = new GUIStyle(TreeView.DefaultStyles.label);
  201. style.fontSize = 11;
  202. style.alignment = TextAnchor.MiddleRight;
  203. return style;
  204. });
  205. internal static readonly LazyStyle SecondaryLabelRightAligned = new LazyStyle(() =>
  206. {
  207. var style = new GUIStyle(SecondaryLabel);
  208. style.alignment = TextAnchor.MiddleRight;
  209. return style;
  210. });
  211. internal static readonly LazyStyle SecondaryLabelBoldRightAligned = new LazyStyle(() =>
  212. {
  213. var style = new GUIStyle(SecondaryLabelRightAligned);
  214. style.fontStyle = FontStyle.Bold;
  215. return style;
  216. });
  217. internal static readonly LazyStyle StatusLabel = new LazyStyle(() =>
  218. {
  219. var style = new GUIStyle(EditorStyles.label);
  220. style.alignment = TextAnchor.MiddleCenter;
  221. style.fontSize = 14;
  222. style.padding = new RectOffset(
  223. 0, 0,
  224. UnityConstants.TREEVIEW_STATUS_CONTENT_PADDING, UnityConstants.TREEVIEW_STATUS_CONTENT_PADDING);
  225. style.stretchWidth = false;
  226. return style;
  227. });
  228. internal static readonly LazyStyle Columns = new LazyStyle(() =>
  229. {
  230. var style = new GUIStyle();
  231. style.normal.background = Images.GetColumnsBackgroundTexture();
  232. return style;
  233. });
  234. }
  235. public static class Inspector
  236. {
  237. public static readonly LazyStyle HeaderBackgroundStyle = new LazyStyle(() =>
  238. {
  239. return CreateUnderlineStyle(
  240. Colors.InspectorHeaderBackground,
  241. UnityConstants.INSPECTOR_ACTIONS_HEADER_BACK_RECTANGLE_HEIGHT);
  242. });
  243. public static readonly LazyStyle DisabledHeaderBackgroundStyle = new LazyStyle(() =>
  244. {
  245. return CreateUnderlineStyle(
  246. Colors.InspectorHeaderBackgroundDisabled,
  247. UnityConstants.INSPECTOR_ACTIONS_HEADER_BACK_RECTANGLE_HEIGHT);
  248. });
  249. }
  250. internal static class PlasticWindow
  251. {
  252. internal static readonly LazyStyle TabButton = new LazyStyle(() =>
  253. {
  254. GUIStyle result = new GUIStyle(EditorStyles.label);
  255. result.padding = EditorStyles.toolbarButton.padding;
  256. result.margin = EditorStyles.toolbarButton.margin;
  257. result.contentOffset = EditorStyles.toolbarButton.contentOffset;
  258. result.alignment = EditorStyles.toolbarButton.alignment;
  259. result.fixedHeight = EditorStyles.toolbarButton.fixedHeight;
  260. return result;
  261. });
  262. internal static readonly LazyStyle ActiveTabUnderline = new LazyStyle(() =>
  263. {
  264. return CreateUnderlineStyle(
  265. Colors.TabUnderline,
  266. UnityConstants.ACTIVE_TAB_UNDERLINE_HEIGHT);
  267. });
  268. }
  269. internal static class StatusBar
  270. {
  271. internal static readonly LazyStyle Icon = new LazyStyle(() =>
  272. {
  273. var style = new GUIStyle(EditorStyles.label);
  274. style.padding.left = 0;
  275. style.padding.right = 0;
  276. return style;
  277. });
  278. internal static readonly LazyStyle Label = new LazyStyle(() =>
  279. {
  280. var style = new GUIStyle(EditorStyles.label);
  281. return style;
  282. });
  283. internal static readonly LazyStyle NotificationLabel = new LazyStyle(() =>
  284. {
  285. var style = new GUIStyle(EditorStyles.label);
  286. style.fontStyle = FontStyle.Bold;
  287. return style;
  288. });
  289. internal static readonly LazyStyle Button = new LazyStyle(() =>
  290. {
  291. var style = new GUIStyle(EditorStyles.miniButtonLeft);
  292. style.fixedWidth = 60;
  293. return style;
  294. });
  295. }
  296. internal static class DiffPanel
  297. {
  298. internal static readonly LazyStyle HeaderLabel = new LazyStyle(() =>
  299. {
  300. var style = new GUIStyle(EditorStyles.label);
  301. style.fontSize = 10;
  302. style.fontStyle = FontStyle.Bold;
  303. #if UNITY_2019_1_OR_NEWER
  304. style.contentOffset = new Vector2(0, 1.5f);
  305. #endif
  306. return style;
  307. });
  308. }
  309. internal static class PendingChangesTab
  310. {
  311. internal static readonly LazyStyle CommentPlaceHolder = new LazyStyle(() =>
  312. {
  313. var style = new GUIStyle();
  314. style.normal = new GUIStyleState() { textColor = Color.gray };
  315. style.padding = new RectOffset(7, 0, 4, 0);
  316. return style;
  317. });
  318. internal static readonly LazyStyle CommentTextArea = new LazyStyle(() =>
  319. {
  320. var style = new GUIStyle(EditorStyles.textArea);
  321. style.margin = new RectOffset(7, 4, 0, 0);
  322. style.padding = new RectOffset(0, 0, 4, 0);
  323. return style;
  324. });
  325. internal static readonly LazyStyle CommentWarningIcon = new LazyStyle(() =>
  326. {
  327. var style = new GUIStyle(EditorStyles.label);
  328. style.fontSize = 10;
  329. #if !UNITY_2019_1_OR_NEWER
  330. style.margin = new RectOffset(0, 0, 0, 0);
  331. #endif
  332. return style;
  333. });
  334. internal static readonly LazyStyle HeaderLabel = new LazyStyle(() =>
  335. {
  336. var style = new GUIStyle(EditorStyles.label);
  337. style.fontSize = 10;
  338. style.fontStyle = FontStyle.Bold;
  339. #if UNITY_2019_1_OR_NEWER
  340. style.contentOffset = new Vector2(0, 1.5f);
  341. #endif
  342. return style;
  343. });
  344. internal static readonly LazyStyle Comment = new LazyStyle(() =>
  345. {
  346. var style = new GUIStyle();
  347. style.normal.background = Images.GetCommentBackgroundTexture();
  348. return style;
  349. });
  350. internal static readonly GUIStyle DefaultMultiColumHeader = MultiColumnHeader.DefaultStyles.background;
  351. }
  352. internal static class IncomingChangesTab
  353. {
  354. internal static readonly LazyStyle PendingConflictsLabel = new LazyStyle(() =>
  355. {
  356. var style = new GUIStyle(EditorStyles.label);
  357. style.fontSize = 11;
  358. style.padding.top = 2;
  359. style.fontStyle = FontStyle.Bold;
  360. return style;
  361. });
  362. internal static readonly LazyStyle RedPendingConflictsOfTotalLabel = new LazyStyle(() =>
  363. {
  364. var style = new GUIStyle(PendingConflictsLabel);
  365. style.normal = new GUIStyleState() { textColor = Colors.Red };
  366. return style;
  367. });
  368. internal static readonly LazyStyle GreenPendingConflictsOfTotalLabel = new LazyStyle(() =>
  369. {
  370. var style = new GUIStyle(PendingConflictsLabel);
  371. style.normal = new GUIStyleState() { textColor = Colors.GreenText };
  372. return style;
  373. });
  374. internal static readonly LazyStyle ChangesToApplySummaryLabel = new LazyStyle(() =>
  375. {
  376. var style = new GUIStyle(EditorStyles.label);
  377. style.fontSize = 11;
  378. style.padding.top = 2;
  379. return style;
  380. });
  381. internal readonly static LazyStyle HeaderWarningLabel
  382. = new LazyStyle(() =>
  383. {
  384. var style = new GUIStyle(EditorStyles.label);
  385. style.fontSize = 11;
  386. #if !UNITY_2019_1_OR_NEWER
  387. style.margin = new RectOffset(0, 0, 0, 0);
  388. #endif
  389. return style;
  390. });
  391. }
  392. internal static class ChangesetsTab
  393. {
  394. internal static readonly LazyStyle HeaderLabel = new LazyStyle(() =>
  395. {
  396. var style = new GUIStyle(EditorStyles.label);
  397. style.fontSize = 10;
  398. style.fontStyle = FontStyle.Bold;
  399. #if UNITY_2019_1_OR_NEWER
  400. style.contentOffset = new Vector2(0, 1.5f);
  401. #endif
  402. return style;
  403. });
  404. }
  405. internal static class HistoryTab
  406. {
  407. internal static readonly LazyStyle HeaderLabel = new LazyStyle(() =>
  408. {
  409. var style = new GUIStyle(EditorStyles.label);
  410. style.fontSize = 10;
  411. style.fontStyle = FontStyle.Bold;
  412. #if UNITY_2019_1_OR_NEWER
  413. style.contentOffset = new Vector2(0, 1.5f);
  414. #endif
  415. return style;
  416. });
  417. }
  418. internal static class DirectoryConflictResolution
  419. {
  420. internal readonly static LazyStyle WarningLabel
  421. = new LazyStyle(() =>
  422. {
  423. var style = new GUIStyle(EditorStyles.label);
  424. style.alignment = TextAnchor.MiddleLeft;
  425. #if !UNITY_2019_1_OR_NEWER
  426. style.margin = new RectOffset(0, 0, 0, 0);
  427. #endif
  428. return style;
  429. });
  430. }
  431. internal static class Notification
  432. {
  433. internal static readonly LazyStyle Label = new LazyStyle(() =>
  434. {
  435. var style = new GUIStyle(EditorStyles.label);
  436. #if !UNITY_2019_1_OR_NEWER
  437. style.fontSize = 10;
  438. #endif
  439. style.normal = new GUIStyleState() { textColor = Color.white };
  440. return style;
  441. });
  442. internal static readonly LazyStyle GreenNotification = new LazyStyle(() =>
  443. {
  444. var style = new GUIStyle();
  445. style.wordWrap = true;
  446. style.margin = new RectOffset();
  447. style.padding = new RectOffset(4, 4, 2, 2);
  448. style.stretchWidth = true;
  449. style.stretchHeight = true;
  450. style.alignment = TextAnchor.UpperLeft;
  451. var bg = new Texture2D(1, 1);
  452. bg.SetPixel(0, 0, Colors.GreenBackground);
  453. bg.Apply();
  454. style.normal.background = bg;
  455. return style;
  456. });
  457. internal static readonly LazyStyle RedNotification = new LazyStyle(() =>
  458. {
  459. var style = new GUIStyle();
  460. style.wordWrap = true;
  461. style.margin = new RectOffset();
  462. style.padding = new RectOffset(4, 4, 2, 2);
  463. style.stretchWidth = true;
  464. style.stretchHeight = true;
  465. style.alignment = TextAnchor.UpperLeft;
  466. var bg = new Texture2D(1, 1);
  467. bg.SetPixel(0, 0, Colors.Red);
  468. bg.Apply();
  469. style.normal.background = bg;
  470. return style;
  471. });
  472. }
  473. internal static class DirectoryConflicts
  474. {
  475. internal readonly static LazyStyle TitleLabel = new LazyStyle(() =>
  476. {
  477. var style = new GUIStyle(EditorStyles.largeLabel);
  478. RectOffset margin = new RectOffset(
  479. style.margin.left,
  480. style.margin.right,
  481. style.margin.top - 1,
  482. style.margin.bottom);
  483. style.margin = margin;
  484. style.fontStyle = FontStyle.Bold;
  485. return style;
  486. });
  487. internal readonly static LazyStyle BoldLabel = new LazyStyle(() =>
  488. {
  489. var style = new GUIStyle(EditorStyles.label);
  490. style.fontStyle = FontStyle.Bold;
  491. return style;
  492. });
  493. internal readonly static LazyStyle FileNameTextField = new LazyStyle(() =>
  494. {
  495. var style = new GUIStyle(EditorStyles.textField);
  496. RectOffset margin = new RectOffset(
  497. style.margin.left,
  498. style.margin.right,
  499. style.margin.top + 2,
  500. style.margin.bottom);
  501. style.margin = margin;
  502. return style;
  503. });
  504. }
  505. internal static readonly LazyStyle ActionToolbar = new LazyStyle(() =>
  506. {
  507. var style = new GUIStyle(EditorStyles.toolbar);
  508. style.fixedHeight = 40f;
  509. style.padding = new RectOffset(5, 5, 5, 5);
  510. return style;
  511. });
  512. internal static readonly LazyStyle SplitterIndicator = new LazyStyle(() =>
  513. {
  514. return CreateUnderlineStyle(
  515. Colors.Splitter,
  516. UnityConstants.SPLITTER_INDICATOR_HEIGHT);
  517. });
  518. internal static readonly LazyStyle HelpBoxLabel = new LazyStyle(() =>
  519. {
  520. var style = new GUIStyle(EditorStyles.label);
  521. style.fontSize = 10;
  522. style.wordWrap = true;
  523. return style;
  524. });
  525. internal static readonly LazyStyle ProgressLabel = new LazyStyle(() =>
  526. {
  527. var style = new GUIStyle(EditorStyles.label);
  528. style.fontSize = 10;
  529. #if !UNITY_2019_1_OR_NEWER
  530. style.margin = new RectOffset(0, 0, 0, 0);
  531. #endif
  532. return style;
  533. });
  534. internal static readonly LazyStyle TextFieldWithWrapping = new LazyStyle(() =>
  535. {
  536. var style = new GUIStyle(GetEditorSkin().textArea);
  537. style.normal = new GUIStyleState() {
  538. textColor = GetEditorSkin().textArea.normal.textColor,
  539. background = Images.GetTreeviewBackgroundTexture()
  540. };
  541. style.wordWrap = true;
  542. return style;
  543. });
  544. internal static readonly LazyStyle Search = new LazyStyle(() =>
  545. {
  546. var style = new GUIStyle();
  547. style.normal = new GUIStyleState() { textColor = Color.gray };
  548. style.padding = new RectOffset(18, 0, 0, 0);
  549. return style;
  550. });
  551. internal static readonly LazyStyle WarningMessage = new LazyStyle(() =>
  552. {
  553. var style = new GUIStyle(GetEditorSkin().box);
  554. style.wordWrap = true;
  555. style.margin = new RectOffset();
  556. style.padding = new RectOffset(8, 8, 6, 6);
  557. style.stretchWidth = true;
  558. style.alignment = TextAnchor.UpperLeft;
  559. var bg = new Texture2D(1, 1);
  560. bg.SetPixel(0, 0, Colors.Warning);
  561. bg.Apply();
  562. style.normal.background = bg;
  563. return style;
  564. });
  565. internal static readonly LazyStyle CancelButton = new LazyStyle(() =>
  566. {
  567. var normalIcon = Images.GetImage(Images.Name.IconCloseButton);
  568. var pressedIcon = Images.GetImage(Images.Name.IconPressedCloseButton);
  569. var style = new GUIStyle();
  570. style.normal = new GUIStyleState() { background = normalIcon };
  571. style.onActive = new GUIStyleState() { background = pressedIcon };
  572. style.active = new GUIStyleState() { background = pressedIcon };
  573. return style;
  574. });
  575. internal static readonly LazyStyle MiniToggle = new LazyStyle(() =>
  576. {
  577. var style = new GUIStyle(EditorStyles.boldLabel);
  578. style.fontSize = MODAL_FONT_SIZE - 1;
  579. style.clipping = TextClipping.Overflow;
  580. return style;
  581. });
  582. internal static readonly LazyStyle Paragraph = new LazyStyle(() =>
  583. {
  584. var style = new GUIStyle(EditorStyles.largeLabel);
  585. style.wordWrap = true;
  586. style.richText = true;
  587. style.fontSize = MODAL_FONT_SIZE;
  588. return style;
  589. });
  590. static GUISkin GetEditorSkin()
  591. {
  592. GUISkin editorSkin = null;
  593. if (EditorGUIUtility.isProSkin)
  594. editorSkin = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Scene);
  595. else
  596. editorSkin = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector);
  597. return editorSkin;
  598. }
  599. static GUIStyle CreateUnderlineStyle(Color color, int height)
  600. {
  601. GUIStyle style = new GUIStyle();
  602. Texture2D pixel = new Texture2D(1, height);
  603. for (int i = 0; i < height; i++)
  604. pixel.SetPixel(0, i, color);
  605. pixel.wrapMode = TextureWrapMode.Repeat;
  606. pixel.Apply();
  607. style.normal.background = pixel;
  608. style.fixedHeight = height;
  609. return style;
  610. }
  611. static void EnsureBackgroundStyles(LazyStyle lazy)
  612. {
  613. // The editor cleans the GUIStyleState.background property
  614. // when entering the edit mode (exiting the play mode)
  615. // and also in other situations (e.g when you use Zoom app)
  616. // Because of this, we have to reset them in order to
  617. // re-instantiate them the next time they're used
  618. if (!mLazyBackgroundStyles.Contains(lazy))
  619. return;
  620. bool needsRepaint = false;
  621. foreach (LazyStyle style in mLazyBackgroundStyles)
  622. {
  623. if (!style.IsInitialized)
  624. continue;
  625. if (style.Value.normal.background != null)
  626. continue;
  627. style.Reset();
  628. needsRepaint = true;
  629. }
  630. if (!needsRepaint)
  631. return;
  632. if (mRepaintPlasticWindow != null)
  633. mRepaintPlasticWindow();
  634. }
  635. static List<LazyStyle> mLazyBackgroundStyles = new List<LazyStyle>();
  636. internal class LazyStyle
  637. {
  638. internal bool IsInitialized { get; private set; }
  639. internal LazyStyle(Func<GUIStyle> builder)
  640. {
  641. mBuilder = builder;
  642. IsInitialized = false;
  643. }
  644. internal GUIStyle Value { get; private set; }
  645. internal void Reset()
  646. {
  647. IsInitialized = false;
  648. }
  649. public static implicit operator GUIStyle(LazyStyle lazy)
  650. {
  651. if (lazy.IsInitialized)
  652. {
  653. EnsureBackgroundStyles(lazy);
  654. return lazy.Value;
  655. }
  656. lazy.Value = lazy.mBuilder();
  657. lazy.IsInitialized = true;
  658. return lazy.Value;
  659. }
  660. readonly Func<GUIStyle> mBuilder;
  661. }
  662. static Action mRepaintPlasticWindow;
  663. const int MODAL_FONT_SIZE = 13;
  664. }
  665. }