暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

UnityStyles.cs 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  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 ToggleOn = new LazyStyle(() =>
  259. {
  260. GUIStyle result = new GUIStyle(Toggle);
  261. result.hover.textColor = Colors.ToggleHoverText;
  262. return result;
  263. });
  264. static readonly LazyStyle Toggle = new LazyStyle(() =>
  265. {
  266. GUIStyle result = new GUIStyle(EditorStyles.miniButton);
  267. result.fixedHeight = 22;
  268. result.fixedWidth = 85;
  269. result.fontSize = 12;
  270. return result;
  271. });
  272. }
  273. internal static class PlasticWindow
  274. {
  275. internal static readonly LazyStyle TabButton = new LazyStyle(() =>
  276. {
  277. GUIStyle result = new GUIStyle(EditorStyles.label);
  278. result.padding = EditorStyles.toolbarButton.padding;
  279. result.margin = EditorStyles.toolbarButton.margin;
  280. result.contentOffset = EditorStyles.toolbarButton.contentOffset;
  281. result.alignment = EditorStyles.toolbarButton.alignment;
  282. result.fixedHeight = EditorStyles.toolbarButton.fixedHeight;
  283. return result;
  284. });
  285. internal static readonly LazyStyle ActiveTabUnderline = new LazyStyle(() =>
  286. {
  287. return CreateUnderlineStyle(
  288. Colors.TabUnderline,
  289. UnityConstants.ACTIVE_TAB_UNDERLINE_HEIGHT);
  290. });
  291. }
  292. internal static class StatusBar
  293. {
  294. internal static readonly LazyStyle Icon = new LazyStyle(() =>
  295. {
  296. var style = new GUIStyle(EditorStyles.label);
  297. style.padding.left = 0;
  298. style.padding.right = 0;
  299. return style;
  300. });
  301. internal static readonly LazyStyle Label = new LazyStyle(() =>
  302. {
  303. var style = new GUIStyle(EditorStyles.label);
  304. return style;
  305. });
  306. internal static readonly LazyStyle LinkLabel = new LazyStyle(() =>
  307. {
  308. var style = new GUIStyle(EditorStyles.linkLabel);
  309. style.padding = EditorStyles.label.padding;
  310. return style;
  311. });
  312. internal static readonly LazyStyle NotificationLabel = new LazyStyle(() =>
  313. {
  314. var style = new GUIStyle(EditorStyles.label);
  315. style.fontStyle = FontStyle.Bold;
  316. return style;
  317. });
  318. internal static readonly LazyStyle Button = new LazyStyle(() =>
  319. {
  320. var style = new GUIStyle(EditorStyles.miniButtonLeft);
  321. style.fixedWidth = 60;
  322. return style;
  323. });
  324. internal static readonly LazyStyle NotificationPanel = new LazyStyle(() =>
  325. {
  326. var style = new GUIStyle(EditorStyles.helpBox);
  327. style.fixedHeight = 24;
  328. return style;
  329. });
  330. internal static readonly LazyStyle NotificationPanelCloseButton = new LazyStyle(() =>
  331. {
  332. var style = new GUIStyle(EditorStyles.label);
  333. style.fixedHeight = 16;
  334. style.fixedWidth = 16;
  335. return style;
  336. });
  337. }
  338. internal static class DiffPanel
  339. {
  340. internal static readonly LazyStyle HeaderLabel = new LazyStyle(() =>
  341. {
  342. var style = new GUIStyle(EditorStyles.label);
  343. style.fontSize = 10;
  344. style.fontStyle = FontStyle.Bold;
  345. #if UNITY_2019_1_OR_NEWER
  346. style.contentOffset = new Vector2(0, 1.5f);
  347. #endif
  348. return style;
  349. });
  350. }
  351. internal static class PendingChangesTab
  352. {
  353. internal static readonly LazyStyle CommentPlaceHolder = new LazyStyle(() =>
  354. {
  355. var style = new GUIStyle();
  356. style.normal = new GUIStyleState() { textColor = Color.gray };
  357. style.padding = new RectOffset(7, 0, 4, 0);
  358. return style;
  359. });
  360. internal static readonly LazyStyle CommentTextArea = new LazyStyle(() =>
  361. {
  362. var style = new GUIStyle(EditorStyles.textArea);
  363. style.margin = new RectOffset(7, 4, 0, 0);
  364. style.padding = new RectOffset(0, 0, 4, 0);
  365. return style;
  366. });
  367. internal static readonly LazyStyle CommentWarningIcon = new LazyStyle(() =>
  368. {
  369. var style = new GUIStyle(EditorStyles.label);
  370. style.fontSize = 10;
  371. #if !UNITY_2019_1_OR_NEWER
  372. style.margin = new RectOffset(0, 0, 0, 0);
  373. #endif
  374. return style;
  375. });
  376. internal static readonly LazyStyle HeaderLabel = new LazyStyle(() =>
  377. {
  378. var style = new GUIStyle(EditorStyles.label);
  379. style.fontSize = 10;
  380. style.fontStyle = FontStyle.Bold;
  381. #if UNITY_2019_1_OR_NEWER
  382. style.contentOffset = new Vector2(0, 1.5f);
  383. #endif
  384. return style;
  385. });
  386. internal static readonly LazyStyle Comment = new LazyStyle(() =>
  387. {
  388. var style = new GUIStyle();
  389. style.normal.background = Images.GetCommentBackgroundTexture();
  390. return style;
  391. });
  392. internal static readonly GUIStyle DefaultMultiColumHeader = MultiColumnHeader.DefaultStyles.background;
  393. }
  394. internal static class IncomingChangesTab
  395. {
  396. internal static readonly LazyStyle PendingConflictsLabel = new LazyStyle(() =>
  397. {
  398. var style = new GUIStyle(EditorStyles.label);
  399. style.fontSize = 11;
  400. style.padding.top = 2;
  401. style.fontStyle = FontStyle.Bold;
  402. return style;
  403. });
  404. internal static readonly LazyStyle RedPendingConflictsOfTotalLabel = new LazyStyle(() =>
  405. {
  406. var style = new GUIStyle(PendingConflictsLabel);
  407. style.normal = new GUIStyleState() { textColor = Colors.Red };
  408. return style;
  409. });
  410. internal static readonly LazyStyle GreenPendingConflictsOfTotalLabel = new LazyStyle(() =>
  411. {
  412. var style = new GUIStyle(PendingConflictsLabel);
  413. style.normal = new GUIStyleState() { textColor = Colors.GreenText };
  414. return style;
  415. });
  416. internal static readonly LazyStyle ChangesToApplySummaryLabel = new LazyStyle(() =>
  417. {
  418. var style = new GUIStyle(EditorStyles.label);
  419. style.fontSize = 11;
  420. style.padding.top = 2;
  421. return style;
  422. });
  423. internal readonly static LazyStyle HeaderWarningLabel
  424. = new LazyStyle(() =>
  425. {
  426. var style = new GUIStyle(EditorStyles.label);
  427. style.fontSize = 11;
  428. #if !UNITY_2019_1_OR_NEWER
  429. style.margin = new RectOffset(0, 0, 0, 0);
  430. #endif
  431. return style;
  432. });
  433. }
  434. internal static class ChangesetsTab
  435. {
  436. internal static readonly LazyStyle HeaderLabel = new LazyStyle(() =>
  437. {
  438. var style = new GUIStyle(EditorStyles.label);
  439. style.fontSize = 10;
  440. style.fontStyle = FontStyle.Bold;
  441. #if UNITY_2019_1_OR_NEWER
  442. style.contentOffset = new Vector2(0, 1.5f);
  443. #endif
  444. return style;
  445. });
  446. }
  447. internal static class HistoryTab
  448. {
  449. internal static readonly LazyStyle HeaderLabel = new LazyStyle(() =>
  450. {
  451. var style = new GUIStyle(EditorStyles.label);
  452. style.fontSize = 10;
  453. style.fontStyle = FontStyle.Bold;
  454. #if UNITY_2019_1_OR_NEWER
  455. style.contentOffset = new Vector2(0, 1.5f);
  456. #endif
  457. return style;
  458. });
  459. }
  460. internal static class DirectoryConflictResolution
  461. {
  462. internal readonly static LazyStyle WarningLabel
  463. = new LazyStyle(() =>
  464. {
  465. var style = new GUIStyle(EditorStyles.label);
  466. style.alignment = TextAnchor.MiddleLeft;
  467. #if !UNITY_2019_1_OR_NEWER
  468. style.margin = new RectOffset(0, 0, 0, 0);
  469. #endif
  470. return style;
  471. });
  472. }
  473. internal static class Notification
  474. {
  475. internal static readonly LazyStyle Label = new LazyStyle(() =>
  476. {
  477. var style = new GUIStyle(EditorStyles.label);
  478. #if !UNITY_2019_1_OR_NEWER
  479. style.fontSize = 10;
  480. #endif
  481. style.normal = new GUIStyleState() { textColor = Color.white };
  482. return style;
  483. });
  484. internal static readonly LazyStyle GreenNotification = new LazyStyle(() =>
  485. {
  486. var style = new GUIStyle();
  487. style.wordWrap = true;
  488. style.margin = new RectOffset();
  489. style.padding = new RectOffset(4, 4, 2, 2);
  490. style.stretchWidth = true;
  491. style.stretchHeight = true;
  492. style.alignment = TextAnchor.UpperLeft;
  493. var bg = new Texture2D(1, 1);
  494. bg.SetPixel(0, 0, Colors.GreenBackground);
  495. bg.Apply();
  496. style.normal.background = bg;
  497. return style;
  498. });
  499. internal static readonly LazyStyle RedNotification = new LazyStyle(() =>
  500. {
  501. var style = new GUIStyle();
  502. style.wordWrap = true;
  503. style.margin = new RectOffset();
  504. style.padding = new RectOffset(4, 4, 2, 2);
  505. style.stretchWidth = true;
  506. style.stretchHeight = true;
  507. style.alignment = TextAnchor.UpperLeft;
  508. var bg = new Texture2D(1, 1);
  509. bg.SetPixel(0, 0, Colors.Red);
  510. bg.Apply();
  511. style.normal.background = bg;
  512. return style;
  513. });
  514. }
  515. internal static class DirectoryConflicts
  516. {
  517. internal readonly static LazyStyle TitleLabel = new LazyStyle(() =>
  518. {
  519. var style = new GUIStyle(EditorStyles.largeLabel);
  520. RectOffset margin = new RectOffset(
  521. style.margin.left,
  522. style.margin.right,
  523. style.margin.top - 1,
  524. style.margin.bottom);
  525. style.margin = margin;
  526. style.fontStyle = FontStyle.Bold;
  527. return style;
  528. });
  529. internal readonly static LazyStyle BoldLabel = new LazyStyle(() =>
  530. {
  531. var style = new GUIStyle(EditorStyles.label);
  532. style.fontStyle = FontStyle.Bold;
  533. return style;
  534. });
  535. internal readonly static LazyStyle FileNameTextField = new LazyStyle(() =>
  536. {
  537. var style = new GUIStyle(EditorStyles.textField);
  538. RectOffset margin = new RectOffset(
  539. style.margin.left,
  540. style.margin.right,
  541. style.margin.top + 2,
  542. style.margin.bottom);
  543. style.margin = margin;
  544. return style;
  545. });
  546. }
  547. internal static readonly LazyStyle ActionToolbar = new LazyStyle(() =>
  548. {
  549. var style = new GUIStyle(EditorStyles.toolbar);
  550. style.fixedHeight = 40f;
  551. style.padding = new RectOffset(5, 5, 5, 5);
  552. return style;
  553. });
  554. internal static readonly LazyStyle SplitterIndicator = new LazyStyle(() =>
  555. {
  556. return CreateUnderlineStyle(
  557. Colors.Splitter,
  558. UnityConstants.SPLITTER_INDICATOR_HEIGHT);
  559. });
  560. internal static readonly LazyStyle HelpBoxLabel = new LazyStyle(() =>
  561. {
  562. var style = new GUIStyle(EditorStyles.label);
  563. style.fontSize = 10;
  564. style.wordWrap = true;
  565. return style;
  566. });
  567. internal static readonly LazyStyle ProgressLabel = new LazyStyle(() =>
  568. {
  569. var style = new GUIStyle(EditorStyles.label);
  570. style.fontSize = 10;
  571. #if !UNITY_2019_1_OR_NEWER
  572. style.margin = new RectOffset(0, 0, 0, 0);
  573. #endif
  574. return style;
  575. });
  576. internal static readonly LazyStyle TextFieldWithWrapping = new LazyStyle(() =>
  577. {
  578. var style = new GUIStyle(GetEditorSkin().textArea);
  579. style.normal = new GUIStyleState() {
  580. textColor = GetEditorSkin().textArea.normal.textColor,
  581. background = Images.GetTreeviewBackgroundTexture()
  582. };
  583. style.wordWrap = true;
  584. return style;
  585. });
  586. internal static readonly LazyStyle Search = new LazyStyle(() =>
  587. {
  588. var style = new GUIStyle();
  589. style.normal = new GUIStyleState() { textColor = Color.gray };
  590. style.padding = new RectOffset(18, 0, 0, 0);
  591. return style;
  592. });
  593. internal static readonly LazyStyle WarningMessage = new LazyStyle(() =>
  594. {
  595. var style = new GUIStyle(GetEditorSkin().box);
  596. style.wordWrap = true;
  597. style.margin = new RectOffset();
  598. style.padding = new RectOffset(8, 8, 6, 6);
  599. style.stretchWidth = true;
  600. style.alignment = TextAnchor.UpperLeft;
  601. var bg = new Texture2D(1, 1);
  602. bg.SetPixel(0, 0, Colors.Warning);
  603. bg.Apply();
  604. style.normal.background = bg;
  605. return style;
  606. });
  607. internal static readonly LazyStyle CancelButton = new LazyStyle(() =>
  608. {
  609. var normalIcon = Images.GetImage(Images.Name.IconCloseButton);
  610. var pressedIcon = Images.GetImage(Images.Name.IconPressedCloseButton);
  611. var style = new GUIStyle();
  612. style.normal = new GUIStyleState() { background = normalIcon };
  613. style.onActive = new GUIStyleState() { background = pressedIcon };
  614. style.active = new GUIStyleState() { background = pressedIcon };
  615. return style;
  616. });
  617. internal static readonly LazyStyle MiniToggle = new LazyStyle(() =>
  618. {
  619. var style = new GUIStyle(EditorStyles.boldLabel);
  620. style.fontSize = MODAL_FONT_SIZE - 1;
  621. style.clipping = TextClipping.Overflow;
  622. return style;
  623. });
  624. internal static readonly LazyStyle Paragraph = new LazyStyle(() =>
  625. {
  626. var style = new GUIStyle(EditorStyles.largeLabel);
  627. style.wordWrap = true;
  628. style.richText = true;
  629. style.fontSize = MODAL_FONT_SIZE;
  630. return style;
  631. });
  632. static GUISkin GetEditorSkin()
  633. {
  634. GUISkin editorSkin = null;
  635. if (EditorGUIUtility.isProSkin)
  636. editorSkin = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Scene);
  637. else
  638. editorSkin = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector);
  639. return editorSkin;
  640. }
  641. static GUIStyle CreateUnderlineStyle(Color color, int height)
  642. {
  643. GUIStyle style = new GUIStyle();
  644. Texture2D pixel = new Texture2D(1, height);
  645. for (int i = 0; i < height; i++)
  646. pixel.SetPixel(0, i, color);
  647. pixel.wrapMode = TextureWrapMode.Repeat;
  648. pixel.Apply();
  649. style.normal.background = pixel;
  650. style.fixedHeight = height;
  651. return style;
  652. }
  653. static void EnsureBackgroundStyles(LazyStyle lazy)
  654. {
  655. // The editor cleans the GUIStyleState.background property
  656. // when entering the edit mode (exiting the play mode)
  657. // and also in other situations (e.g when you use Zoom app)
  658. // Because of this, we have to reset them in order to
  659. // re-instantiate them the next time they're used
  660. if (!mLazyBackgroundStyles.Contains(lazy))
  661. return;
  662. bool needsRepaint = false;
  663. foreach (LazyStyle style in mLazyBackgroundStyles)
  664. {
  665. if (!style.IsInitialized)
  666. continue;
  667. if (style.Value.normal.background != null)
  668. continue;
  669. style.Reset();
  670. needsRepaint = true;
  671. }
  672. if (!needsRepaint)
  673. return;
  674. if (mRepaintPlasticWindow != null)
  675. mRepaintPlasticWindow();
  676. }
  677. static List<LazyStyle> mLazyBackgroundStyles = new List<LazyStyle>();
  678. internal class LazyStyle
  679. {
  680. internal bool IsInitialized { get; private set; }
  681. internal LazyStyle(Func<GUIStyle> builder)
  682. {
  683. mBuilder = builder;
  684. IsInitialized = false;
  685. }
  686. internal GUIStyle Value { get; private set; }
  687. internal void Reset()
  688. {
  689. IsInitialized = false;
  690. }
  691. public static implicit operator GUIStyle(LazyStyle lazy)
  692. {
  693. if (lazy.IsInitialized)
  694. {
  695. EnsureBackgroundStyles(lazy);
  696. return lazy.Value;
  697. }
  698. lazy.Value = lazy.mBuilder();
  699. lazy.IsInitialized = true;
  700. return lazy.Value;
  701. }
  702. readonly Func<GUIStyle> mBuilder;
  703. }
  704. static Action mRepaintPlasticWindow;
  705. const int MODAL_FONT_SIZE = 13;
  706. }
  707. }