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.

UnityStyles.cs 30KB

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