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.

292 lines
16 KiB

  1. using UnityEngine;
  2. using UnityEditor;
  3. using UnityEditorInternal;
  4. #pragma warning disable 0414 // Disabled a few warnings for not yet implemented features.
  5. namespace TMPro.EditorUtilities
  6. {
  7. [CustomEditor(typeof(TMP_Settings))]
  8. public class TMP_SettingsEditor : Editor
  9. {
  10. class Styles
  11. {
  12. public static readonly GUIContent defaultFontAssetLabel = new GUIContent("Default Font Asset", "The Font Asset that will be assigned by default to newly created text objects when no Font Asset is specified.");
  13. public static readonly GUIContent defaultFontAssetPathLabel = new GUIContent("Path: Resources/", "The relative path to a Resources folder where the Font Assets and Material Presets are located.\nExample \"Fonts & Materials/\"");
  14. public static readonly GUIContent fallbackFontAssetsLabel = new GUIContent("Fallback Font Assets", "The Font Assets that will be searched to locate and replace missing characters from a given Font Asset.");
  15. public static readonly GUIContent fallbackFontAssetsListLabel = new GUIContent("Fallback Font Assets List", "The Font Assets that will be searched to locate and replace missing characters from a given Font Asset.");
  16. public static readonly GUIContent fallbackMaterialSettingsLabel = new GUIContent("Fallback Material Settings");
  17. public static readonly GUIContent matchMaterialPresetLabel = new GUIContent("Match Material Presets");
  18. public static readonly GUIContent containerDefaultSettingsLabel = new GUIContent("Text Container Default Settings");
  19. public static readonly GUIContent textMeshProLabel = new GUIContent("TextMeshPro");
  20. public static readonly GUIContent textMeshProUiLabel = new GUIContent("TextMeshPro UI");
  21. public static readonly GUIContent autoSizeContainerLabel = new GUIContent("Auto Size Text Container", "Set the size of the text container to match the text.");
  22. public static readonly GUIContent textComponentDefaultSettingsLabel = new GUIContent("Text Component Default Settings");
  23. public static readonly GUIContent defaultFontSize = new GUIContent("Default Font Size");
  24. public static readonly GUIContent autoSizeRatioLabel = new GUIContent("Text Auto Size Ratios");
  25. public static readonly GUIContent minLabel = new GUIContent("Min");
  26. public static readonly GUIContent maxLabel = new GUIContent("Max");
  27. public static readonly GUIContent wordWrappingLabel = new GUIContent("Word Wrapping");
  28. public static readonly GUIContent kerningLabel = new GUIContent("Kerning");
  29. public static readonly GUIContent extraPaddingLabel = new GUIContent("Extra Padding");
  30. public static readonly GUIContent tintAllSpritesLabel = new GUIContent("Tint All Sprites");
  31. public static readonly GUIContent parseEscapeCharactersLabel = new GUIContent("Parse Escape Sequence");
  32. public static readonly GUIContent missingGlyphsTitleLabel = new GUIContent("Missing glyphs");
  33. public static readonly GUIContent missingGlyphLabel = new GUIContent("Replacement", "The glyph to be used as a replacement when a glyph can't be found in a font asset.");
  34. public static readonly GUIContent disableWarningsLabel = new GUIContent("Disable warnings");
  35. public static readonly GUIContent defaultSpriteAssetLabel = new GUIContent("Default Sprite Asset", "The Sprite Asset that will be assigned by default when using the <sprite> tag when no Sprite Asset is specified.");
  36. public static readonly GUIContent enableEmojiSupportLabel = new GUIContent("iOS Emoji Support", "Enables Emoji support for Touch Screen Keyboards on target devices.");
  37. public static readonly GUIContent spriteAssetsPathLabel = new GUIContent("Path: Resources/", "The relative path to a Resources folder where the Sprite Assets are located.\nExample \"Sprite Assets/\"");
  38. public static readonly GUIContent defaultStyleSheetLabel = new GUIContent("Default Style Sheet", "The Style Sheet that will be used for all text objects in this project.");
  39. public static readonly GUIContent colorGradientPresetsLabel = new GUIContent("Color Gradient Presets", "The relative path to a Resources folder where the Color Gradient Presets are located.\nExample \"Color Gradient Presets/\"");
  40. public static readonly GUIContent colorGradientsPathLabel = new GUIContent("Path: Resources/", "The relative path to a Resources folder where the Color Gradient Presets are located.\nExample \"Color Gradient Presets/\"");
  41. public static readonly GUIContent lineBreakingLabel = new GUIContent("Line Breaking for Asian languages", "The text assets that contain the Leading and Following characters which define the rules for line breaking with Asian languages.");
  42. }
  43. SerializedProperty m_PropFontAsset;
  44. SerializedProperty m_PropDefaultFontAssetPath;
  45. SerializedProperty m_PropDefaultFontSize;
  46. SerializedProperty m_PropDefaultAutoSizeMinRatio;
  47. SerializedProperty m_PropDefaultAutoSizeMaxRatio;
  48. SerializedProperty m_PropDefaultTextMeshProTextContainerSize;
  49. SerializedProperty m_PropDefaultTextMeshProUITextContainerSize;
  50. SerializedProperty m_PropAutoSizeTextContainer;
  51. SerializedProperty m_PropSpriteAsset;
  52. SerializedProperty m_PropSpriteAssetPath;
  53. SerializedProperty m_PropEnableEmojiSupport;
  54. SerializedProperty m_PropStyleSheet;
  55. ReorderableList m_List;
  56. SerializedProperty m_PropColorGradientPresetsPath;
  57. SerializedProperty m_PropMatchMaterialPreset;
  58. SerializedProperty m_PropWordWrapping;
  59. SerializedProperty m_PropKerning;
  60. SerializedProperty m_PropExtraPadding;
  61. SerializedProperty m_PropTintAllSprites;
  62. SerializedProperty m_PropParseEscapeCharacters;
  63. SerializedProperty m_PropMissingGlyphCharacter;
  64. SerializedProperty m_PropWarningsDisabled;
  65. SerializedProperty m_PropLeadingCharacters;
  66. SerializedProperty m_PropFollowingCharacters;
  67. public void OnEnable()
  68. {
  69. if (target == null)
  70. return;
  71. m_PropFontAsset = serializedObject.FindProperty("m_defaultFontAsset");
  72. m_PropDefaultFontAssetPath = serializedObject.FindProperty("m_defaultFontAssetPath");
  73. m_PropDefaultFontSize = serializedObject.FindProperty("m_defaultFontSize");
  74. m_PropDefaultAutoSizeMinRatio = serializedObject.FindProperty("m_defaultAutoSizeMinRatio");
  75. m_PropDefaultAutoSizeMaxRatio = serializedObject.FindProperty("m_defaultAutoSizeMaxRatio");
  76. m_PropDefaultTextMeshProTextContainerSize = serializedObject.FindProperty("m_defaultTextMeshProTextContainerSize");
  77. m_PropDefaultTextMeshProUITextContainerSize = serializedObject.FindProperty("m_defaultTextMeshProUITextContainerSize");
  78. m_PropAutoSizeTextContainer = serializedObject.FindProperty("m_autoSizeTextContainer");
  79. m_PropSpriteAsset = serializedObject.FindProperty("m_defaultSpriteAsset");
  80. m_PropSpriteAssetPath = serializedObject.FindProperty("m_defaultSpriteAssetPath");
  81. m_PropEnableEmojiSupport = serializedObject.FindProperty("m_enableEmojiSupport");
  82. m_PropStyleSheet = serializedObject.FindProperty("m_defaultStyleSheet");
  83. m_PropColorGradientPresetsPath = serializedObject.FindProperty("m_defaultColorGradientPresetsPath");
  84. m_List = new ReorderableList(serializedObject, serializedObject.FindProperty("m_fallbackFontAssets"), true, true, true, true);
  85. m_List.drawElementCallback = (rect, index, isActive, isFocused) =>
  86. {
  87. var element = m_List.serializedProperty.GetArrayElementAtIndex(index);
  88. rect.y += 2;
  89. EditorGUI.PropertyField(new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight), element, GUIContent.none);
  90. };
  91. m_List.drawHeaderCallback = rect =>
  92. {
  93. EditorGUI.LabelField(rect, Styles.fallbackFontAssetsListLabel);
  94. };
  95. m_PropMatchMaterialPreset = serializedObject.FindProperty("m_matchMaterialPreset");
  96. m_PropWordWrapping = serializedObject.FindProperty("m_enableWordWrapping");
  97. m_PropKerning = serializedObject.FindProperty("m_enableKerning");
  98. m_PropExtraPadding = serializedObject.FindProperty("m_enableExtraPadding");
  99. m_PropTintAllSprites = serializedObject.FindProperty("m_enableTintAllSprites");
  100. m_PropParseEscapeCharacters = serializedObject.FindProperty("m_enableParseEscapeCharacters");
  101. m_PropMissingGlyphCharacter = serializedObject.FindProperty("m_missingGlyphCharacter");
  102. m_PropWarningsDisabled = serializedObject.FindProperty("m_warningsDisabled");
  103. m_PropLeadingCharacters = serializedObject.FindProperty("m_leadingCharacters");
  104. m_PropFollowingCharacters = serializedObject.FindProperty("m_followingCharacters");
  105. }
  106. public override void OnInspectorGUI()
  107. {
  108. serializedObject.Update();
  109. float labelWidth = EditorGUIUtility.labelWidth;
  110. float fieldWidth = EditorGUIUtility.fieldWidth;
  111. // TextMeshPro Font Info Panel
  112. EditorGUI.indentLevel = 0;
  113. // FONT ASSET
  114. EditorGUILayout.BeginVertical(EditorStyles.helpBox);
  115. GUILayout.Label(Styles.defaultFontAssetLabel, EditorStyles.boldLabel);
  116. EditorGUI.indentLevel = 1;
  117. EditorGUILayout.PropertyField(m_PropFontAsset, Styles.defaultFontAssetLabel);
  118. EditorGUILayout.PropertyField(m_PropDefaultFontAssetPath, Styles.defaultFontAssetPathLabel);
  119. EditorGUI.indentLevel = 0;
  120. EditorGUILayout.Space();
  121. EditorGUILayout.EndVertical();
  122. // FALLBACK FONT ASSETs
  123. EditorGUILayout.BeginVertical(EditorStyles.helpBox);
  124. GUILayout.Label(Styles.fallbackFontAssetsLabel, EditorStyles.boldLabel);
  125. m_List.DoLayoutList();
  126. GUILayout.Label(Styles.fallbackMaterialSettingsLabel, EditorStyles.boldLabel);
  127. EditorGUI.indentLevel = 1;
  128. EditorGUILayout.PropertyField(m_PropMatchMaterialPreset, Styles.matchMaterialPresetLabel);
  129. EditorGUI.indentLevel = 0;
  130. EditorGUILayout.Space();
  131. EditorGUILayout.EndVertical();
  132. // MISSING GLYPHS
  133. EditorGUILayout.BeginVertical(EditorStyles.helpBox);
  134. GUILayout.Label(Styles.missingGlyphsTitleLabel, EditorStyles.boldLabel);
  135. EditorGUI.indentLevel = 1;
  136. EditorGUILayout.PropertyField(m_PropMissingGlyphCharacter, Styles.missingGlyphLabel);
  137. EditorGUILayout.PropertyField(m_PropWarningsDisabled, Styles.disableWarningsLabel);
  138. EditorGUI.indentLevel = 0;
  139. EditorGUILayout.Space();
  140. EditorGUILayout.EndVertical();
  141. // TEXT OBJECT DEFAULT PROPERTIES
  142. EditorGUILayout.BeginVertical(EditorStyles.helpBox);
  143. GUILayout.Label(Styles.containerDefaultSettingsLabel, EditorStyles.boldLabel);
  144. EditorGUI.indentLevel = 1;
  145. EditorGUILayout.PropertyField(m_PropDefaultTextMeshProTextContainerSize, Styles.textMeshProLabel);
  146. EditorGUILayout.PropertyField(m_PropDefaultTextMeshProUITextContainerSize, Styles.textMeshProUiLabel);
  147. EditorGUILayout.PropertyField(m_PropAutoSizeTextContainer, Styles.autoSizeContainerLabel);
  148. EditorGUI.indentLevel = 0;
  149. EditorGUILayout.Space();
  150. GUILayout.Label(Styles.textComponentDefaultSettingsLabel, EditorStyles.boldLabel);
  151. EditorGUI.indentLevel = 1;
  152. EditorGUILayout.PropertyField(m_PropDefaultFontSize, Styles.defaultFontSize);
  153. EditorGUILayout.BeginHorizontal();
  154. {
  155. EditorGUILayout.PrefixLabel(Styles.autoSizeRatioLabel);
  156. EditorGUIUtility.labelWidth = 32;
  157. EditorGUIUtility.fieldWidth = 10;
  158. EditorGUI.indentLevel = 0;
  159. EditorGUILayout.PropertyField(m_PropDefaultAutoSizeMinRatio, Styles.minLabel);
  160. EditorGUILayout.PropertyField(m_PropDefaultAutoSizeMaxRatio, Styles.maxLabel);
  161. EditorGUI.indentLevel = 1;
  162. }
  163. EditorGUILayout.EndHorizontal();
  164. EditorGUIUtility.labelWidth = labelWidth;
  165. EditorGUIUtility.fieldWidth = fieldWidth;
  166. EditorGUILayout.PropertyField(m_PropWordWrapping, Styles.wordWrappingLabel);
  167. EditorGUILayout.PropertyField(m_PropKerning, Styles.kerningLabel);
  168. EditorGUILayout.PropertyField(m_PropExtraPadding, Styles.extraPaddingLabel);
  169. EditorGUILayout.PropertyField(m_PropTintAllSprites, Styles.tintAllSpritesLabel);
  170. EditorGUILayout.PropertyField(m_PropParseEscapeCharacters, Styles.parseEscapeCharactersLabel);
  171. EditorGUI.indentLevel = 0;
  172. EditorGUILayout.Space();
  173. EditorGUILayout.EndVertical();
  174. // SPRITE ASSET
  175. EditorGUILayout.BeginVertical(EditorStyles.helpBox);
  176. GUILayout.Label(Styles.defaultSpriteAssetLabel, EditorStyles.boldLabel);
  177. EditorGUI.indentLevel = 1;
  178. EditorGUILayout.PropertyField(m_PropSpriteAsset, Styles.defaultSpriteAssetLabel);
  179. EditorGUILayout.PropertyField(m_PropEnableEmojiSupport, Styles.enableEmojiSupportLabel);
  180. EditorGUILayout.PropertyField(m_PropSpriteAssetPath, Styles.spriteAssetsPathLabel);
  181. EditorGUI.indentLevel = 0;
  182. EditorGUILayout.Space();
  183. EditorGUILayout.EndVertical();
  184. // STYLE SHEET
  185. EditorGUILayout.BeginVertical(EditorStyles.helpBox);
  186. GUILayout.Label(Styles.defaultStyleSheetLabel, EditorStyles.boldLabel);
  187. EditorGUI.indentLevel = 1;
  188. EditorGUI.BeginChangeCheck();
  189. EditorGUILayout.PropertyField(m_PropStyleSheet, Styles.defaultStyleSheetLabel);
  190. if (EditorGUI.EndChangeCheck())
  191. {
  192. serializedObject.ApplyModifiedProperties();
  193. TMP_StyleSheet.UpdateStyleSheet();
  194. }
  195. EditorGUI.indentLevel = 0;
  196. EditorGUILayout.Space();
  197. EditorGUILayout.EndVertical();
  198. // COLOR GRADIENT PRESETS
  199. EditorGUILayout.BeginVertical(EditorStyles.helpBox);
  200. GUILayout.Label(Styles.colorGradientPresetsLabel, EditorStyles.boldLabel);
  201. EditorGUI.indentLevel = 1;
  202. EditorGUILayout.PropertyField(m_PropColorGradientPresetsPath, Styles.colorGradientsPathLabel);
  203. EditorGUI.indentLevel = 0;
  204. EditorGUILayout.Space();
  205. EditorGUILayout.EndVertical();
  206. // LINE BREAKING RULE
  207. EditorGUILayout.BeginVertical(EditorStyles.helpBox);
  208. GUILayout.Label(Styles.lineBreakingLabel, EditorStyles.boldLabel);
  209. EditorGUI.indentLevel = 1;
  210. EditorGUILayout.PropertyField(m_PropLeadingCharacters);
  211. EditorGUILayout.PropertyField(m_PropFollowingCharacters);
  212. EditorGUI.indentLevel = 0;
  213. EditorGUILayout.Space();
  214. EditorGUILayout.EndVertical();
  215. if (serializedObject.ApplyModifiedProperties())
  216. {
  217. EditorUtility.SetDirty(target);
  218. TMPro_EventManager.ON_TMP_SETTINGS_CHANGED();
  219. }
  220. }
  221. #if UNITY_2018_3_OR_NEWER
  222. [SettingsProvider]
  223. static SettingsProvider CreateTMPSettingsProvider()
  224. {
  225. var provider = new AssetSettingsProvider("Project/TextMesh Pro", () => TMP_Settings.instance);
  226. provider.PopulateSearchKeywordsFromGUIContentProperties<Styles>();
  227. return provider;
  228. }
  229. #endif
  230. }
  231. }