TMP_UIStyleManager.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections;
  4. namespace TMPro.EditorUtilities
  5. {
  6. public static class TMP_UIStyleManager
  7. {
  8. public static GUIStyle label;
  9. public static GUIStyle textAreaBoxWindow;
  10. public static GUIStyle boldFoldout;
  11. public static GUIStyle panelTitle;
  12. public static GUIStyle sectionHeader;
  13. public static GUIStyle centeredLabel;
  14. public static GUIStyle rightLabel;
  15. public static GUIStyle wrappingTextArea;
  16. public static GUIStyle alignmentButtonLeft;
  17. public static GUIStyle alignmentButtonMid;
  18. public static GUIStyle alignmentButtonRight;
  19. // Alignment Button Textures
  20. public static Texture2D alignLeft;
  21. public static Texture2D alignCenter;
  22. public static Texture2D alignRight;
  23. public static Texture2D alignJustified;
  24. public static Texture2D alignFlush;
  25. public static Texture2D alignGeoCenter;
  26. public static Texture2D alignTop;
  27. public static Texture2D alignMiddle;
  28. public static Texture2D alignBottom;
  29. public static Texture2D alignBaseline;
  30. public static Texture2D alignMidline;
  31. public static Texture2D alignCapline;
  32. public static Texture2D sectionHeaderTexture;
  33. public static GUIContent[] alignContentA;
  34. public static GUIContent[] alignContentB;
  35. static TMP_UIStyleManager()
  36. {
  37. // Find to location of the TextMesh Pro Asset Folder (as users may have moved it)
  38. var tmproAssetFolderPath = TMP_EditorUtility.packageRelativePath;
  39. if (EditorGUIUtility.isProSkin)
  40. {
  41. alignLeft = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/Editor Resources/Textures/btn_AlignLeft.psd", typeof(Texture2D)) as Texture2D;
  42. alignCenter = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/Editor Resources/Textures/btn_AlignCenter.psd", typeof(Texture2D)) as Texture2D;
  43. alignRight = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/Editor Resources/Textures/btn_AlignRight.psd", typeof(Texture2D)) as Texture2D;
  44. alignJustified = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/Editor Resources/Textures/btn_AlignJustified.psd", typeof(Texture2D)) as Texture2D;
  45. alignFlush = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/Editor Resources/Textures/btn_AlignFlush.psd", typeof(Texture2D)) as Texture2D;
  46. alignGeoCenter = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/Editor Resources/Textures/btn_AlignCenterGeo.psd", typeof(Texture2D)) as Texture2D;
  47. alignTop = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/Editor Resources/Textures/btn_AlignTop.psd", typeof(Texture2D)) as Texture2D;
  48. alignMiddle = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/Editor Resources/Textures/btn_AlignMiddle.psd", typeof(Texture2D)) as Texture2D;
  49. alignBottom = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/Editor Resources/Textures/btn_AlignBottom.psd", typeof(Texture2D)) as Texture2D;
  50. alignBaseline = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/Editor Resources/Textures/btn_AlignBaseLine.psd", typeof(Texture2D)) as Texture2D;
  51. alignMidline = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/Editor Resources/Textures/btn_AlignMidLine.psd", typeof(Texture2D)) as Texture2D;
  52. alignCapline = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/Editor Resources/Textures/btn_AlignCapLine.psd", typeof(Texture2D)) as Texture2D;
  53. sectionHeaderTexture = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/Editor Resources/Textures/SectionHeader_Dark.psd", typeof(Texture2D)) as Texture2D;
  54. }
  55. else
  56. {
  57. alignLeft = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/Editor Resources/Textures/btn_AlignLeft_Light.psd", typeof(Texture2D)) as Texture2D;
  58. alignCenter = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/Editor Resources/Textures/btn_AlignCenter_Light.psd", typeof(Texture2D)) as Texture2D;
  59. alignRight = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/Editor Resources/Textures/btn_AlignRight_Light.psd", typeof(Texture2D)) as Texture2D;
  60. alignJustified = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/Editor Resources/Textures/btn_AlignJustified_Light.psd", typeof(Texture2D)) as Texture2D;
  61. alignFlush = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/Editor Resources/Textures/btn_AlignFlush_Light.psd", typeof(Texture2D)) as Texture2D;
  62. alignGeoCenter = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/Editor Resources/Textures/btn_AlignCenterGeo_Light.psd", typeof(Texture2D)) as Texture2D;
  63. alignTop = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/Editor Resources/Textures/btn_AlignTop_Light.psd", typeof(Texture2D)) as Texture2D;
  64. alignMiddle = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/Editor Resources/Textures/btn_AlignMiddle_Light.psd", typeof(Texture2D)) as Texture2D;
  65. alignBottom = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/Editor Resources/Textures/btn_AlignBottom_Light.psd", typeof(Texture2D)) as Texture2D;
  66. alignBaseline = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/Editor Resources/Textures/btn_AlignBaseLine_Light.psd", typeof(Texture2D)) as Texture2D;
  67. alignMidline = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/Editor Resources/Textures/btn_AlignMidLine_Light.psd", typeof(Texture2D)) as Texture2D;
  68. alignCapline = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/Editor Resources/Textures/btn_AlignCapLine_Light.psd", typeof(Texture2D)) as Texture2D;
  69. sectionHeaderTexture = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/Editor Resources/Textures/SectionHeader_Light.psd", typeof(Texture2D)) as Texture2D;
  70. }
  71. label = new GUIStyle(EditorStyles.label) { richText = true, wordWrap = true, stretchWidth = true };
  72. textAreaBoxWindow = new GUIStyle(EditorStyles.textArea) { richText = true };
  73. boldFoldout = new GUIStyle(EditorStyles.foldout) { fontStyle = FontStyle.Bold };
  74. panelTitle = new GUIStyle(EditorStyles.label) { fontStyle = FontStyle.Bold };
  75. sectionHeader = new GUIStyle(EditorStyles.label) { fixedHeight = 22, richText = true, border = new RectOffset(9, 9, 0, 0), overflow = new RectOffset(9, 0, 0, 0), padding = new RectOffset(0, 0, 4, 0) };
  76. sectionHeader.normal.background = sectionHeaderTexture;
  77. centeredLabel = new GUIStyle(EditorStyles.label) { alignment = TextAnchor.MiddleCenter};
  78. rightLabel = new GUIStyle(EditorStyles.label) { alignment = TextAnchor.MiddleRight, richText = true };
  79. alignmentButtonLeft = new GUIStyle(EditorStyles.miniButtonLeft);
  80. alignmentButtonLeft.padding.left = 4;
  81. alignmentButtonLeft.padding.right = 4;
  82. alignmentButtonLeft.padding.top = 2;
  83. alignmentButtonLeft.padding.bottom = 2;
  84. alignmentButtonMid = new GUIStyle(EditorStyles.miniButtonMid);
  85. alignmentButtonMid.padding.left = 4;
  86. alignmentButtonMid.padding.right = 4;
  87. alignmentButtonLeft.padding.top = 2;
  88. alignmentButtonLeft.padding.bottom = 2;
  89. alignmentButtonRight = new GUIStyle(EditorStyles.miniButtonRight);
  90. alignmentButtonRight.padding.left = 4;
  91. alignmentButtonRight.padding.right = 4;
  92. alignmentButtonLeft.padding.top = 2;
  93. alignmentButtonLeft.padding.bottom = 2;
  94. wrappingTextArea = new GUIStyle(EditorStyles.textArea);
  95. wrappingTextArea.wordWrap = true;
  96. alignContentA = new []
  97. {
  98. new GUIContent(alignLeft, "Left"),
  99. new GUIContent(alignCenter, "Center"),
  100. new GUIContent(alignRight, "Right"),
  101. new GUIContent(alignJustified, "Justified"),
  102. new GUIContent(alignFlush, "Flush"),
  103. new GUIContent(alignGeoCenter, "Geometry Center")
  104. };
  105. alignContentB = new []
  106. {
  107. new GUIContent(alignTop, "Top"),
  108. new GUIContent(alignMiddle, "Middle"),
  109. new GUIContent(alignBottom, "Bottom"),
  110. new GUIContent(alignBaseline, "Baseline"),
  111. new GUIContent(alignMidline, "Midline"),
  112. new GUIContent(alignCapline, "Capline")
  113. };
  114. }
  115. }
  116. }