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

UnityStyles.cs 29KB

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