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.

1122 lines
50 KiB

  1. using UnityEngine;
  2. using UnityEditor;
  3. namespace TMPro.EditorUtilities
  4. {
  5. public abstract class TMP_BaseEditorPanel : Editor
  6. {
  7. //Labels and Tooltips
  8. static readonly GUIContent k_RtlToggleLabel = new GUIContent("Enable RTL Editor", "Reverses text direction and allows right to left editing.");
  9. static readonly GUIContent k_MainSettingsLabel = new GUIContent("Main Settings");
  10. static readonly GUIContent k_FontAssetLabel = new GUIContent("Font Asset", "The Font Asset containing the glyphs that can be rendered for this text.");
  11. static readonly GUIContent k_MaterialPresetLabel = new GUIContent("Material Preset", "The material used for rendering. Only materials created from the Font Asset can be used.");
  12. static readonly GUIContent k_AutoSizeLabel = new GUIContent("Auto Size", "Auto sizes the text to fit the available space.");
  13. static readonly GUIContent k_FontSizeLabel = new GUIContent("Font Size", "The size the text will be rendered at in points.");
  14. static readonly GUIContent k_AutoSizeOptionsLabel = new GUIContent("Auto Size Options");
  15. static readonly GUIContent k_MinLabel = new GUIContent("Min", "The minimum font size.");
  16. static readonly GUIContent k_MaxLabel = new GUIContent("Max", "The maximum font size.");
  17. static readonly GUIContent k_WdLabel = new GUIContent("WD%", "Compresses character width up to this value before reducing font size.");
  18. static readonly GUIContent k_LineLabel = new GUIContent("Line", "Negative value only. Compresses line height down to this value before reducing font size.");
  19. static readonly GUIContent k_FontStyleLabel = new GUIContent("Font Style", "Styles to apply to the text such as Bold or Italic.");
  20. static readonly GUIContent k_BoldLabel = new GUIContent("B", "Bold");
  21. static readonly GUIContent k_ItalicLabel = new GUIContent("I", "Italic");
  22. static readonly GUIContent k_UnderlineLabel = new GUIContent("U", "Underline");
  23. static readonly GUIContent k_StrikethroughLabel = new GUIContent("S", "Strikethrough");
  24. static readonly GUIContent k_LowercaseLabel = new GUIContent("ab", "Lowercase");
  25. static readonly GUIContent k_UppercaseLabel = new GUIContent("AB", "Uppercase");
  26. static readonly GUIContent k_SmallcapsLabel = new GUIContent("SC", "Smallcaps");
  27. static readonly GUIContent k_ColorModeLabel = new GUIContent("Color Mode", "The type of gradient to use.");
  28. static readonly GUIContent k_BaseColorLabel = new GUIContent("Vertex Color", "The base color of the text vertices.");
  29. static readonly GUIContent k_ColorPresetLabel = new GUIContent("Color Preset", "A Color Preset which override the local color settings.");
  30. static readonly GUIContent k_ColorGradientLabel = new GUIContent("Color Gradient", "The gradient color applied over the Vertex Color. Can be locally set or driven by a Gradient Asset.");
  31. static readonly GUIContent k_CorenerColorsLabel = new GUIContent("Colors", "The color composition of the gradient.");
  32. static readonly GUIContent k_OverrideTagsLabel = new GUIContent("Override Tags", "Whether the color settings override the <color> tag.");
  33. static readonly GUIContent k_SpacingOptionsLabel = new GUIContent("Spacing Options", "Spacing adjustments between different elements of the text.");
  34. static readonly GUIContent k_CharacterSpacingLabel = new GUIContent("Character");
  35. static readonly GUIContent k_WordSpacingLabel = new GUIContent("Word");
  36. static readonly GUIContent k_LineSpacingLabel = new GUIContent("Line");
  37. static readonly GUIContent k_ParagraphSpacingLabel = new GUIContent("Paragraph");
  38. static readonly GUIContent k_AlignmentLabel = new GUIContent("Alignment", "Horizontal and vertical aligment of the text within its container.");
  39. static readonly GUIContent k_WrapMixLabel = new GUIContent("Wrap Mix (W <-> C)", "How much to favor words versus characters when distributing the text.");
  40. static readonly GUIContent k_WrappingLabel = new GUIContent("Wrapping", "Wraps text to the next line when reaching the edge of the container.");
  41. static readonly GUIContent[] k_WrappingOptions = { new GUIContent("Disabled"), new GUIContent("Enabled") };
  42. static readonly GUIContent k_OverflowLabel = new GUIContent("Overflow", "How to display text which goes past the edge of the container.");
  43. static readonly GUIContent k_MarginsLabel = new GUIContent("Margins", "The space between the text and the edge of its container.");
  44. static readonly GUIContent k_GeometrySortingLabel = new GUIContent("Geometry Sorting", "The order in which text geometry is sorted. Used to adjust the way overlapping characters are displayed.");
  45. static readonly GUIContent k_RichTextLabel = new GUIContent("Rich Text", "Enables the use of rich text tags such as <color> and <font>.");
  46. static readonly GUIContent k_EscapeCharactersLabel = new GUIContent("Parse Escape Characters", "Whether to display strings such as \"\\n\" as is or replace them by the character they represent.");
  47. static readonly GUIContent k_VisibleDescenderLabel = new GUIContent("Visible Descender", "Compute descender values from visible characters only. Used to adjust layout behavior when hiding and revealing characters dynamically.");
  48. static readonly GUIContent k_SpriteAssetLabel = new GUIContent("Sprite Asset", "The Sprite Asset used when NOT specifically referencing one using <sprite=\"Sprite Asset Name\">.");
  49. static readonly GUIContent k_HorizontalMappingLabel = new GUIContent("Horizontal Mapping", "Horizontal UV mapping when using a shader with a texture face option.");
  50. static readonly GUIContent k_VerticalMappingLabel = new GUIContent("Vertical Mapping", "Vertical UV mapping when using a shader with a texture face option.");
  51. static readonly GUIContent k_LineOffsetLabel = new GUIContent("Line Offset", "Adds an horizontal offset to each successive line. Used for slanted texturing.");
  52. static readonly GUIContent k_KerningLabel = new GUIContent("Kerning", "Enables character specific spacing between pairs of characters.");
  53. static readonly GUIContent k_PaddingLabel = new GUIContent("Extra Padding", "Adds some padding between the characters and the edge of the text mesh. Can reduce graphical errors when displaying small text.");
  54. static readonly GUIContent k_LeftLabel = new GUIContent("Left");
  55. static readonly GUIContent k_TopLabel = new GUIContent("Top");
  56. static readonly GUIContent k_RightLabel = new GUIContent("Right");
  57. static readonly GUIContent k_BottomLabel = new GUIContent("Bottom");
  58. protected static readonly GUIContent k_ExtraSettingsLabel = new GUIContent("Extra Settings");
  59. protected struct Foldout
  60. {
  61. // Track Inspector foldout panel states, globally.
  62. public static bool extraSettings = false;
  63. public static bool materialInspector = true;
  64. }
  65. protected static int s_EventId;
  66. public int selAlignGridA;
  67. public int selAlignGridB;
  68. protected SerializedProperty m_TextProp;
  69. protected SerializedProperty m_IsRightToLeftProp;
  70. protected string m_RtlText;
  71. protected SerializedProperty m_FontAssetProp;
  72. protected SerializedProperty m_FontSharedMaterialProp;
  73. protected Material[] m_MaterialPresets;
  74. protected GUIContent[] m_MaterialPresetNames;
  75. protected int m_MaterialPresetSelectionIndex;
  76. protected bool m_IsPresetListDirty;
  77. protected SerializedProperty m_FontStyleProp;
  78. protected SerializedProperty m_FontColorProp;
  79. protected SerializedProperty m_EnableVertexGradientProp;
  80. protected SerializedProperty m_FontColorGradientProp;
  81. protected SerializedProperty m_FontColorGradientPresetProp;
  82. protected SerializedProperty m_OverrideHtmlColorProp;
  83. protected SerializedProperty m_FontSizeProp;
  84. protected SerializedProperty m_FontSizeBaseProp;
  85. protected SerializedProperty m_AutoSizingProp;
  86. protected SerializedProperty m_FontSizeMinProp;
  87. protected SerializedProperty m_FontSizeMaxProp;
  88. protected SerializedProperty m_LineSpacingMaxProp;
  89. protected SerializedProperty m_CharWidthMaxAdjProp;
  90. protected SerializedProperty m_CharacterSpacingProp;
  91. protected SerializedProperty m_WordSpacingProp;
  92. protected SerializedProperty m_LineSpacingProp;
  93. protected SerializedProperty m_ParagraphSpacingProp;
  94. protected SerializedProperty m_TextAlignmentProp;
  95. protected SerializedProperty m_HorizontalMappingProp;
  96. protected SerializedProperty m_VerticalMappingProp;
  97. protected SerializedProperty m_UvLineOffsetProp;
  98. protected SerializedProperty m_EnableWordWrappingProp;
  99. protected SerializedProperty m_WordWrappingRatiosProp;
  100. protected SerializedProperty m_TextOverflowModeProp;
  101. protected SerializedProperty m_PageToDisplayProp;
  102. protected SerializedProperty m_LinkedTextComponentProp;
  103. protected SerializedProperty m_IsLinkedTextComponentProp;
  104. protected SerializedProperty m_EnableKerningProp;
  105. protected SerializedProperty m_InputSourceProp;
  106. protected SerializedProperty m_HavePropertiesChangedProp;
  107. protected SerializedProperty m_IsInputPasingRequiredProp;
  108. protected SerializedProperty m_IsRichTextProp;
  109. protected SerializedProperty m_HasFontAssetChangedProp;
  110. protected SerializedProperty m_EnableExtraPaddingProp;
  111. protected SerializedProperty m_CheckPaddingRequiredProp;
  112. protected SerializedProperty m_EnableEscapeCharacterParsingProp;
  113. protected SerializedProperty m_UseMaxVisibleDescenderProp;
  114. protected SerializedProperty m_GeometrySortingOrderProp;
  115. protected SerializedProperty m_SpriteAssetProp;
  116. protected SerializedProperty m_MarginProp;
  117. protected SerializedProperty m_ColorModeProp;
  118. protected bool m_HavePropertiesChanged;
  119. protected TMP_Text m_TextComponent;
  120. protected RectTransform m_RectTransform;
  121. protected Material m_TargetMaterial;
  122. protected Vector3[] m_RectCorners = new Vector3[4];
  123. protected Vector3[] m_HandlePoints = new Vector3[4];
  124. protected virtual void OnEnable()
  125. {
  126. m_TextProp = serializedObject.FindProperty("m_text");
  127. m_IsRightToLeftProp = serializedObject.FindProperty("m_isRightToLeft");
  128. m_FontAssetProp = serializedObject.FindProperty("m_fontAsset");
  129. m_FontSharedMaterialProp = serializedObject.FindProperty("m_sharedMaterial");
  130. m_FontStyleProp = serializedObject.FindProperty("m_fontStyle");
  131. m_FontSizeProp = serializedObject.FindProperty("m_fontSize");
  132. m_FontSizeBaseProp = serializedObject.FindProperty("m_fontSizeBase");
  133. m_AutoSizingProp = serializedObject.FindProperty("m_enableAutoSizing");
  134. m_FontSizeMinProp = serializedObject.FindProperty("m_fontSizeMin");
  135. m_FontSizeMaxProp = serializedObject.FindProperty("m_fontSizeMax");
  136. m_LineSpacingMaxProp = serializedObject.FindProperty("m_lineSpacingMax");
  137. m_CharWidthMaxAdjProp = serializedObject.FindProperty("m_charWidthMaxAdj");
  138. // Colors & Gradient
  139. m_FontColorProp = serializedObject.FindProperty("m_fontColor");
  140. m_EnableVertexGradientProp = serializedObject.FindProperty("m_enableVertexGradient");
  141. m_FontColorGradientProp = serializedObject.FindProperty("m_fontColorGradient");
  142. m_FontColorGradientPresetProp = serializedObject.FindProperty("m_fontColorGradientPreset");
  143. m_OverrideHtmlColorProp = serializedObject.FindProperty("m_overrideHtmlColors");
  144. m_CharacterSpacingProp = serializedObject.FindProperty("m_characterSpacing");
  145. m_WordSpacingProp = serializedObject.FindProperty("m_wordSpacing");
  146. m_LineSpacingProp = serializedObject.FindProperty("m_lineSpacing");
  147. m_ParagraphSpacingProp = serializedObject.FindProperty("m_paragraphSpacing");
  148. m_TextAlignmentProp = serializedObject.FindProperty("m_textAlignment");
  149. m_HorizontalMappingProp = serializedObject.FindProperty("m_horizontalMapping");
  150. m_VerticalMappingProp = serializedObject.FindProperty("m_verticalMapping");
  151. m_UvLineOffsetProp = serializedObject.FindProperty("m_uvLineOffset");
  152. m_EnableWordWrappingProp = serializedObject.FindProperty("m_enableWordWrapping");
  153. m_WordWrappingRatiosProp = serializedObject.FindProperty("m_wordWrappingRatios");
  154. m_TextOverflowModeProp = serializedObject.FindProperty("m_overflowMode");
  155. m_PageToDisplayProp = serializedObject.FindProperty("m_pageToDisplay");
  156. m_LinkedTextComponentProp = serializedObject.FindProperty("m_linkedTextComponent");
  157. m_IsLinkedTextComponentProp = serializedObject.FindProperty("m_isLinkedTextComponent");
  158. m_EnableKerningProp = serializedObject.FindProperty("m_enableKerning");
  159. m_HavePropertiesChangedProp = serializedObject.FindProperty("m_havePropertiesChanged");
  160. m_InputSourceProp = serializedObject.FindProperty("m_inputSource");
  161. m_IsInputPasingRequiredProp = serializedObject.FindProperty("m_isInputParsingRequired");
  162. m_EnableExtraPaddingProp = serializedObject.FindProperty("m_enableExtraPadding");
  163. m_IsRichTextProp = serializedObject.FindProperty("m_isRichText");
  164. m_CheckPaddingRequiredProp = serializedObject.FindProperty("checkPaddingRequired");
  165. m_EnableEscapeCharacterParsingProp = serializedObject.FindProperty("m_parseCtrlCharacters");
  166. m_UseMaxVisibleDescenderProp = serializedObject.FindProperty("m_useMaxVisibleDescender");
  167. m_GeometrySortingOrderProp = serializedObject.FindProperty("m_geometrySortingOrder");
  168. m_SpriteAssetProp = serializedObject.FindProperty("m_spriteAsset");
  169. m_MarginProp = serializedObject.FindProperty("m_margin");
  170. m_HasFontAssetChangedProp = serializedObject.FindProperty("m_hasFontAssetChanged");
  171. m_ColorModeProp = serializedObject.FindProperty("m_colorMode");
  172. m_TextComponent = (TMP_Text)target;
  173. m_RectTransform = m_TextComponent.rectTransform;
  174. // Create new Material Editor if one does not exists
  175. m_TargetMaterial = m_TextComponent.fontSharedMaterial;
  176. // Set material inspector visibility
  177. if (m_TargetMaterial != null)
  178. UnityEditorInternal.InternalEditorUtility.SetIsInspectorExpanded(m_TargetMaterial, Foldout.materialInspector);
  179. // Find all Material Presets matching the current Font Asset Material
  180. m_MaterialPresetNames = GetMaterialPresets();
  181. // Initialize the Event Listener for Undo Events.
  182. Undo.undoRedoPerformed += OnUndoRedo;
  183. }
  184. protected virtual void OnDisable()
  185. {
  186. // Set material inspector visibility
  187. if (m_TargetMaterial != null)
  188. Foldout.materialInspector = UnityEditorInternal.InternalEditorUtility.GetIsInspectorExpanded(m_TargetMaterial);
  189. if (Undo.undoRedoPerformed != null)
  190. Undo.undoRedoPerformed -= OnUndoRedo;
  191. }
  192. public override void OnInspectorGUI()
  193. {
  194. // Make sure Multi selection only includes TMP Text objects.
  195. if (IsMixSelectionTypes()) return;
  196. serializedObject.Update();
  197. DrawTextInput();
  198. DrawMainSettings();
  199. DrawExtraSettings();
  200. EditorGUILayout.Space();
  201. if (m_HavePropertiesChanged)
  202. {
  203. m_HavePropertiesChangedProp.boolValue = true;
  204. m_HavePropertiesChanged = false;
  205. m_TextComponent.ComputeMarginSize();
  206. EditorUtility.SetDirty(target);
  207. }
  208. serializedObject.ApplyModifiedProperties();
  209. }
  210. public void OnSceneGUI()
  211. {
  212. if (IsMixSelectionTypes()) return;
  213. // Margin Frame & Handles
  214. m_RectTransform.GetWorldCorners(m_RectCorners);
  215. Vector4 marginOffset = m_TextComponent.margin;
  216. Vector3 lossyScale = m_RectTransform.lossyScale;
  217. m_HandlePoints[0] = m_RectCorners[0] + m_RectTransform.TransformDirection(new Vector3(marginOffset.x * lossyScale.x, marginOffset.w * lossyScale.y, 0));
  218. m_HandlePoints[1] = m_RectCorners[1] + m_RectTransform.TransformDirection(new Vector3(marginOffset.x * lossyScale.x, -marginOffset.y * lossyScale.y, 0));
  219. m_HandlePoints[2] = m_RectCorners[2] + m_RectTransform.TransformDirection(new Vector3(-marginOffset.z * lossyScale.x, -marginOffset.y * lossyScale.y, 0));
  220. m_HandlePoints[3] = m_RectCorners[3] + m_RectTransform.TransformDirection(new Vector3(-marginOffset.z * lossyScale.x, marginOffset.w * lossyScale.y, 0));
  221. Handles.DrawSolidRectangleWithOutline(m_HandlePoints, new Color32(255, 255, 255, 0), new Color32(255, 255, 0, 255));
  222. // Draw & process FreeMoveHandles
  223. // LEFT HANDLE
  224. Vector3 oldLeft = (m_HandlePoints[0] + m_HandlePoints[1]) * 0.5f;
  225. Vector3 newLeft = Handles.FreeMoveHandle(oldLeft, Quaternion.identity, HandleUtility.GetHandleSize(m_RectTransform.position) * 0.05f, Vector3.zero, Handles.DotHandleCap);
  226. bool hasChanged = false;
  227. if (oldLeft != newLeft)
  228. {
  229. float delta = oldLeft.x - newLeft.x;
  230. marginOffset.x += -delta / lossyScale.x;
  231. //Debug.Log("Left Margin H0:" + handlePoints[0] + " H1:" + handlePoints[1]);
  232. hasChanged = true;
  233. }
  234. // TOP HANDLE
  235. Vector3 oldTop = (m_HandlePoints[1] + m_HandlePoints[2]) * 0.5f;
  236. Vector3 newTop = Handles.FreeMoveHandle(oldTop, Quaternion.identity, HandleUtility.GetHandleSize(m_RectTransform.position) * 0.05f, Vector3.zero, Handles.DotHandleCap);
  237. if (oldTop != newTop)
  238. {
  239. float delta = oldTop.y - newTop.y;
  240. marginOffset.y += delta / lossyScale.y;
  241. //Debug.Log("Top Margin H1:" + handlePoints[1] + " H2:" + handlePoints[2]);
  242. hasChanged = true;
  243. }
  244. // RIGHT HANDLE
  245. Vector3 oldRight = (m_HandlePoints[2] + m_HandlePoints[3]) * 0.5f;
  246. Vector3 newRight = Handles.FreeMoveHandle(oldRight, Quaternion.identity, HandleUtility.GetHandleSize(m_RectTransform.position) * 0.05f, Vector3.zero, Handles.DotHandleCap);
  247. if (oldRight != newRight)
  248. {
  249. float delta = oldRight.x - newRight.x;
  250. marginOffset.z += delta / lossyScale.x;
  251. hasChanged = true;
  252. //Debug.Log("Right Margin H2:" + handlePoints[2] + " H3:" + handlePoints[3]);
  253. }
  254. // BOTTOM HANDLE
  255. Vector3 oldBottom = (m_HandlePoints[3] + m_HandlePoints[0]) * 0.5f;
  256. Vector3 newBottom = Handles.FreeMoveHandle(oldBottom, Quaternion.identity, HandleUtility.GetHandleSize(m_RectTransform.position) * 0.05f, Vector3.zero, Handles.DotHandleCap);
  257. if (oldBottom != newBottom)
  258. {
  259. float delta = oldBottom.y - newBottom.y;
  260. marginOffset.w += -delta / lossyScale.y;
  261. hasChanged = true;
  262. //Debug.Log("Bottom Margin H0:" + handlePoints[0] + " H3:" + handlePoints[3]);
  263. }
  264. if (hasChanged)
  265. {
  266. Undo.RecordObjects(new Object[] {m_RectTransform, m_TextComponent }, "Margin Changes");
  267. m_TextComponent.margin = marginOffset;
  268. EditorUtility.SetDirty(target);
  269. }
  270. }
  271. protected void DrawTextInput()
  272. {
  273. EditorGUILayout.Space();
  274. // If the text component is linked, disable the text input box.
  275. if (m_IsLinkedTextComponentProp.boolValue)
  276. {
  277. EditorGUILayout.HelpBox("The Text Input Box is disabled due to this text component being linked to another.", MessageType.Info);
  278. }
  279. else
  280. {
  281. EditorGUI.BeginChangeCheck();
  282. EditorGUILayout.PropertyField(m_TextProp);
  283. if (EditorGUI.EndChangeCheck() || (m_IsRightToLeftProp.boolValue && string.IsNullOrEmpty(m_RtlText)))
  284. {
  285. m_InputSourceProp.enumValueIndex = 0;
  286. m_IsInputPasingRequiredProp.boolValue = true;
  287. m_HavePropertiesChanged = true;
  288. // Handle Left to Right or Right to Left Editor
  289. if (m_IsRightToLeftProp.boolValue)
  290. {
  291. m_RtlText = string.Empty;
  292. string sourceText = m_TextProp.stringValue;
  293. // Reverse Text displayed in Text Input Box
  294. for (int i = 0; i < sourceText.Length; i++)
  295. {
  296. m_RtlText += sourceText[sourceText.Length - i - 1];
  297. }
  298. }
  299. }
  300. // Toggle showing Rich Tags
  301. m_IsRightToLeftProp.boolValue = EditorGUILayout.Toggle(k_RtlToggleLabel, m_IsRightToLeftProp.boolValue);
  302. if (m_IsRightToLeftProp.boolValue)
  303. {
  304. EditorGUI.BeginChangeCheck();
  305. m_RtlText = EditorGUILayout.TextArea(m_RtlText, TMP_UIStyleManager.wrappingTextArea, GUILayout.Height(EditorGUI.GetPropertyHeight(m_TextProp) - EditorGUIUtility.singleLineHeight), GUILayout.ExpandWidth(true));
  306. if (EditorGUI.EndChangeCheck())
  307. {
  308. // Convert RTL input
  309. string sourceText = string.Empty;
  310. // Reverse Text displayed in Text Input Box
  311. for (int i = 0; i < m_RtlText.Length; i++)
  312. {
  313. sourceText += m_RtlText[m_RtlText.Length - i - 1];
  314. }
  315. m_TextProp.stringValue = sourceText;
  316. }
  317. }
  318. }
  319. }
  320. protected void DrawMainSettings()
  321. {
  322. // MAIN SETTINGS SECTION
  323. GUILayout.Label(k_MainSettingsLabel, EditorStyles.boldLabel);
  324. EditorGUI.indentLevel += 1;
  325. DrawFont();
  326. DrawColor();
  327. DrawSpacing();
  328. DrawAlignment();
  329. DrawWrappingOverflow();
  330. DrawTextureMapping();
  331. EditorGUI.indentLevel -= 1;
  332. }
  333. void DrawFont()
  334. {
  335. // Update list of material presets if needed.
  336. if (m_IsPresetListDirty)
  337. m_MaterialPresetNames = GetMaterialPresets();
  338. // FONT ASSET
  339. EditorGUI.BeginChangeCheck();
  340. EditorGUILayout.PropertyField(m_FontAssetProp, k_FontAssetLabel);
  341. if (EditorGUI.EndChangeCheck())
  342. {
  343. m_HavePropertiesChanged = true;
  344. m_HasFontAssetChangedProp.boolValue = true;
  345. m_IsPresetListDirty = true;
  346. m_MaterialPresetSelectionIndex = 0;
  347. }
  348. Rect rect;
  349. // MATERIAL PRESET
  350. if (m_MaterialPresetNames != null)
  351. {
  352. EditorGUI.BeginChangeCheck();
  353. rect = EditorGUILayout.GetControlRect(false, 17);
  354. float oldHeight = EditorStyles.popup.fixedHeight;
  355. EditorStyles.popup.fixedHeight = rect.height;
  356. int oldSize = EditorStyles.popup.fontSize;
  357. EditorStyles.popup.fontSize = 11;
  358. m_MaterialPresetSelectionIndex = EditorGUI.Popup(rect, k_MaterialPresetLabel, m_MaterialPresetSelectionIndex, m_MaterialPresetNames);
  359. if (EditorGUI.EndChangeCheck())
  360. {
  361. m_FontSharedMaterialProp.objectReferenceValue = m_MaterialPresets[m_MaterialPresetSelectionIndex];
  362. m_HavePropertiesChanged = true;
  363. }
  364. //Make sure material preset selection index matches the selection
  365. if (m_MaterialPresetSelectionIndex < m_MaterialPresetNames.Length && m_TargetMaterial != m_MaterialPresets[m_MaterialPresetSelectionIndex] && !m_HavePropertiesChanged)
  366. m_IsPresetListDirty = true;
  367. EditorStyles.popup.fixedHeight = oldHeight;
  368. EditorStyles.popup.fontSize = oldSize;
  369. }
  370. // FONT STYLE
  371. EditorGUI.BeginChangeCheck();
  372. int v1, v2, v3, v4, v5, v6, v7;
  373. if (EditorGUIUtility.wideMode)
  374. {
  375. rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight + 2f);
  376. EditorGUI.PrefixLabel(rect, k_FontStyleLabel);
  377. int styleValue = m_FontStyleProp.intValue;
  378. rect.x += EditorGUIUtility.labelWidth;
  379. rect.width -= EditorGUIUtility.labelWidth;
  380. rect.width = Mathf.Max(25f, rect.width / 7f);
  381. v1 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 1) == 1, k_BoldLabel, TMP_UIStyleManager.alignmentButtonLeft) ? 1 : 0; // Bold
  382. rect.x += rect.width;
  383. v2 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 2) == 2, k_ItalicLabel, TMP_UIStyleManager.alignmentButtonMid) ? 2 : 0; // Italics
  384. rect.x += rect.width;
  385. v3 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 4) == 4, k_UnderlineLabel, TMP_UIStyleManager.alignmentButtonMid) ? 4 : 0; // Underline
  386. rect.x += rect.width;
  387. v7 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 64) == 64, k_StrikethroughLabel, TMP_UIStyleManager.alignmentButtonRight) ? 64 : 0; // Strikethrough
  388. rect.x += rect.width;
  389. int selected = 0;
  390. EditorGUI.BeginChangeCheck();
  391. v4 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 8) == 8, k_LowercaseLabel, TMP_UIStyleManager.alignmentButtonLeft) ? 8 : 0; // Lowercase
  392. if (EditorGUI.EndChangeCheck() && v4 > 0)
  393. {
  394. selected = v4;
  395. }
  396. rect.x += rect.width;
  397. EditorGUI.BeginChangeCheck();
  398. v5 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 16) == 16, k_UppercaseLabel, TMP_UIStyleManager.alignmentButtonMid) ? 16 : 0; // Uppercase
  399. if (EditorGUI.EndChangeCheck() && v5 > 0)
  400. {
  401. selected = v5;
  402. }
  403. rect.x += rect.width;
  404. EditorGUI.BeginChangeCheck();
  405. v6 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 32) == 32, k_SmallcapsLabel, TMP_UIStyleManager.alignmentButtonRight) ? 32 : 0; // Smallcaps
  406. if (EditorGUI.EndChangeCheck() && v6 > 0)
  407. {
  408. selected = v6;
  409. }
  410. if (selected > 0)
  411. {
  412. v4 = selected == 8 ? 8 : 0;
  413. v5 = selected == 16 ? 16 : 0;
  414. v6 = selected == 32 ? 32 : 0;
  415. }
  416. }
  417. else
  418. {
  419. rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight + 2f);
  420. EditorGUI.PrefixLabel(rect, k_FontStyleLabel);
  421. int styleValue = m_FontStyleProp.intValue;
  422. rect.x += EditorGUIUtility.labelWidth;
  423. rect.width -= EditorGUIUtility.labelWidth;
  424. rect.width = Mathf.Max(25f, rect.width / 4f);
  425. v1 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 1) == 1, k_BoldLabel, TMP_UIStyleManager.alignmentButtonLeft) ? 1 : 0; // Bold
  426. rect.x += rect.width;
  427. v2 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 2) == 2, k_ItalicLabel, TMP_UIStyleManager.alignmentButtonMid) ? 2 : 0; // Italics
  428. rect.x += rect.width;
  429. v3 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 4) == 4, k_UnderlineLabel, TMP_UIStyleManager.alignmentButtonMid) ? 4 : 0; // Underline
  430. rect.x += rect.width;
  431. v7 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 64) == 64, k_StrikethroughLabel, TMP_UIStyleManager.alignmentButtonRight) ? 64 : 0; // Strikethrough
  432. rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight + 2f);
  433. rect.x += EditorGUIUtility.labelWidth;
  434. rect.width -= EditorGUIUtility.labelWidth;
  435. rect.width = Mathf.Max(25f, rect.width / 4f);
  436. int selected = 0;
  437. EditorGUI.BeginChangeCheck();
  438. v4 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 8) == 8, k_LowercaseLabel, TMP_UIStyleManager.alignmentButtonLeft) ? 8 : 0; // Lowercase
  439. if (EditorGUI.EndChangeCheck() && v4 > 0)
  440. {
  441. selected = v4;
  442. }
  443. rect.x += rect.width;
  444. EditorGUI.BeginChangeCheck();
  445. v5 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 16) == 16, k_UppercaseLabel, TMP_UIStyleManager.alignmentButtonMid) ? 16 : 0; // Uppercase
  446. if (EditorGUI.EndChangeCheck() && v5 > 0)
  447. {
  448. selected = v5;
  449. }
  450. rect.x += rect.width;
  451. EditorGUI.BeginChangeCheck();
  452. v6 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 32) == 32, k_SmallcapsLabel, TMP_UIStyleManager.alignmentButtonRight) ? 32 : 0; // Smallcaps
  453. if (EditorGUI.EndChangeCheck() && v6 > 0)
  454. {
  455. selected = v6;
  456. }
  457. if (selected > 0)
  458. {
  459. v4 = selected == 8 ? 8 : 0;
  460. v5 = selected == 16 ? 16 : 0;
  461. v6 = selected == 32 ? 32 : 0;
  462. }
  463. }
  464. if (EditorGUI.EndChangeCheck())
  465. {
  466. m_FontStyleProp.intValue = v1 + v2 + v3 + v4 + v5 + v6 + v7;
  467. m_HavePropertiesChanged = true;
  468. }
  469. // FONT SIZE
  470. EditorGUI.BeginChangeCheck();
  471. EditorGUI.BeginDisabledGroup(m_AutoSizingProp.boolValue);
  472. EditorGUILayout.PropertyField(m_FontSizeProp, k_FontSizeLabel, GUILayout.MaxWidth(EditorGUIUtility.labelWidth + 50f));
  473. EditorGUI.EndDisabledGroup();
  474. if (EditorGUI.EndChangeCheck())
  475. {
  476. m_FontSizeBaseProp.floatValue = m_FontSizeProp.floatValue;
  477. m_HavePropertiesChanged = true;
  478. }
  479. EditorGUI.indentLevel += 1;
  480. EditorGUI.BeginChangeCheck();
  481. EditorGUILayout.PropertyField(m_AutoSizingProp, k_AutoSizeLabel);
  482. if (EditorGUI.EndChangeCheck())
  483. {
  484. if (m_AutoSizingProp.boolValue == false)
  485. m_FontSizeProp.floatValue = m_FontSizeBaseProp.floatValue;
  486. m_HavePropertiesChanged = true;
  487. }
  488. // Show auto sizing options
  489. if (m_AutoSizingProp.boolValue)
  490. {
  491. rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight);
  492. EditorGUI.PrefixLabel(rect, k_AutoSizeOptionsLabel);
  493. int previousIndent = EditorGUI.indentLevel;
  494. EditorGUI.indentLevel = 0;
  495. rect.width = (rect.width - EditorGUIUtility.labelWidth) / 4f;
  496. rect.x += EditorGUIUtility.labelWidth;
  497. EditorGUIUtility.labelWidth = 24;
  498. EditorGUI.BeginChangeCheck();
  499. EditorGUI.PropertyField(rect, m_FontSizeMinProp, k_MinLabel);
  500. if (EditorGUI.EndChangeCheck())
  501. {
  502. m_FontSizeMinProp.floatValue = Mathf.Min(m_FontSizeMinProp.floatValue, m_FontSizeMaxProp.floatValue);
  503. m_HavePropertiesChanged = true;
  504. }
  505. rect.x += rect.width;
  506. EditorGUIUtility.labelWidth = 27;
  507. EditorGUI.BeginChangeCheck();
  508. EditorGUI.PropertyField(rect, m_FontSizeMaxProp, k_MaxLabel);
  509. if (EditorGUI.EndChangeCheck())
  510. {
  511. m_FontSizeMaxProp.floatValue = Mathf.Max(m_FontSizeMinProp.floatValue, m_FontSizeMaxProp.floatValue);
  512. m_HavePropertiesChanged = true;
  513. }
  514. rect.x += rect.width;
  515. EditorGUI.BeginChangeCheck();
  516. EditorGUIUtility.labelWidth = 36;
  517. EditorGUI.PropertyField(rect, m_CharWidthMaxAdjProp, k_WdLabel);
  518. rect.x += rect.width;
  519. EditorGUIUtility.labelWidth = 28;
  520. EditorGUI.PropertyField(rect, m_LineSpacingMaxProp, k_LineLabel);
  521. EditorGUIUtility.labelWidth = 0;
  522. if (EditorGUI.EndChangeCheck())
  523. {
  524. m_CharWidthMaxAdjProp.floatValue = Mathf.Clamp(m_CharWidthMaxAdjProp.floatValue, 0, 50);
  525. m_LineSpacingMaxProp.floatValue = Mathf.Min(0, m_LineSpacingMaxProp.floatValue);
  526. m_HavePropertiesChanged = true;
  527. }
  528. EditorGUI.indentLevel = previousIndent;
  529. }
  530. EditorGUI.indentLevel -= 1;
  531. EditorGUILayout.Space();
  532. }
  533. void DrawColor()
  534. {
  535. // FACE VERTEX COLOR
  536. EditorGUI.BeginChangeCheck();
  537. EditorGUILayout.PropertyField(m_FontColorProp, k_BaseColorLabel);
  538. EditorGUILayout.PropertyField(m_EnableVertexGradientProp, k_ColorGradientLabel);
  539. if (EditorGUI.EndChangeCheck())
  540. {
  541. m_HavePropertiesChanged = true;
  542. }
  543. EditorGUIUtility.fieldWidth = 0;
  544. if (m_EnableVertexGradientProp.boolValue)
  545. {
  546. EditorGUI.indentLevel += 1;
  547. EditorGUI.BeginChangeCheck();
  548. EditorGUILayout.PropertyField(m_FontColorGradientPresetProp, k_ColorPresetLabel);
  549. SerializedObject obj = null;
  550. SerializedProperty colorMode;
  551. SerializedProperty topLeft;
  552. SerializedProperty topRight;
  553. SerializedProperty bottomLeft;
  554. SerializedProperty bottomRight;
  555. if (m_FontColorGradientPresetProp.objectReferenceValue == null)
  556. {
  557. colorMode = m_ColorModeProp;
  558. topLeft = m_FontColorGradientProp.FindPropertyRelative("topLeft");
  559. topRight = m_FontColorGradientProp.FindPropertyRelative("topRight");
  560. bottomLeft = m_FontColorGradientProp.FindPropertyRelative("bottomLeft");
  561. bottomRight = m_FontColorGradientProp.FindPropertyRelative("bottomRight");
  562. }
  563. else
  564. {
  565. obj = new SerializedObject(m_FontColorGradientPresetProp.objectReferenceValue);
  566. colorMode = obj.FindProperty("colorMode");
  567. topLeft = obj.FindProperty("topLeft");
  568. topRight = obj.FindProperty("topRight");
  569. bottomLeft = obj.FindProperty("bottomLeft");
  570. bottomRight = obj.FindProperty("bottomRight");
  571. }
  572. EditorGUILayout.PropertyField(colorMode, k_ColorModeLabel);
  573. var rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2));
  574. EditorGUI.PrefixLabel(rect, k_CorenerColorsLabel);
  575. rect.x += EditorGUIUtility.labelWidth;
  576. rect.width = rect.width - EditorGUIUtility.labelWidth;
  577. switch ((ColorMode)colorMode.enumValueIndex)
  578. {
  579. case ColorMode.Single:
  580. TMP_EditorUtility.DrawColorProperty(rect, topLeft);
  581. topRight.colorValue = topLeft.colorValue;
  582. bottomLeft.colorValue = topLeft.colorValue;
  583. bottomRight.colorValue = topLeft.colorValue;
  584. break;
  585. case ColorMode.HorizontalGradient:
  586. rect.width /= 2f;
  587. TMP_EditorUtility.DrawColorProperty(rect, topLeft);
  588. rect.x += rect.width;
  589. TMP_EditorUtility.DrawColorProperty(rect, topRight);
  590. bottomLeft.colorValue = topLeft.colorValue;
  591. bottomRight.colorValue = topRight.colorValue;
  592. break;
  593. case ColorMode.VerticalGradient:
  594. TMP_EditorUtility.DrawColorProperty(rect, topLeft);
  595. rect = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2));
  596. rect.x += EditorGUIUtility.labelWidth;
  597. TMP_EditorUtility.DrawColorProperty(rect, bottomLeft);
  598. topRight.colorValue = topLeft.colorValue;
  599. bottomRight.colorValue = bottomLeft.colorValue;
  600. break;
  601. case ColorMode.FourCornersGradient:
  602. rect.width /= 2f;
  603. TMP_EditorUtility.DrawColorProperty(rect, topLeft);
  604. rect.x += rect.width;
  605. TMP_EditorUtility.DrawColorProperty(rect, topRight);
  606. rect = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2));
  607. rect.x += EditorGUIUtility.labelWidth;
  608. rect.width = (rect.width - EditorGUIUtility.labelWidth) / 2f;
  609. TMP_EditorUtility.DrawColorProperty(rect, bottomLeft);
  610. rect.x += rect.width;
  611. TMP_EditorUtility.DrawColorProperty(rect, bottomRight);
  612. break;
  613. }
  614. if (EditorGUI.EndChangeCheck())
  615. {
  616. m_HavePropertiesChanged = true;
  617. if (obj != null)
  618. {
  619. obj.ApplyModifiedProperties();
  620. TMPro_EventManager.ON_COLOR_GRAIDENT_PROPERTY_CHANGED(m_FontColorGradientPresetProp.objectReferenceValue as TMP_ColorGradient);
  621. }
  622. }
  623. EditorGUI.indentLevel -= 1;
  624. }
  625. EditorGUILayout.PropertyField(m_OverrideHtmlColorProp, k_OverrideTagsLabel);
  626. EditorGUILayout.Space();
  627. }
  628. void DrawSpacing()
  629. {
  630. // CHARACTER, LINE & PARAGRAPH SPACING
  631. EditorGUI.BeginChangeCheck();
  632. Rect rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight);
  633. EditorGUI.PrefixLabel(rect, k_SpacingOptionsLabel);
  634. int oldIndent = EditorGUI.indentLevel;
  635. EditorGUI.indentLevel = 0;
  636. rect.x += EditorGUIUtility.labelWidth;
  637. rect.width = (rect.width - EditorGUIUtility.labelWidth - 3f) / 2f;
  638. EditorGUIUtility.labelWidth = Mathf.Min(rect.width * 0.55f, 80f);
  639. EditorGUI.PropertyField(rect, m_CharacterSpacingProp, k_CharacterSpacingLabel);
  640. rect.x += rect.width + 3f;
  641. EditorGUI.PropertyField(rect, m_WordSpacingProp, k_WordSpacingLabel);
  642. rect = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight);
  643. EditorGUIUtility.labelWidth = 0;
  644. rect.x += EditorGUIUtility.labelWidth;
  645. rect.width = (rect.width - EditorGUIUtility.labelWidth -3f) / 2f;
  646. EditorGUIUtility.labelWidth = Mathf.Min(rect.width * 0.55f, 80f);
  647. EditorGUI.PropertyField(rect, m_LineSpacingProp, k_LineSpacingLabel);
  648. rect.x += rect.width + 3f;
  649. EditorGUI.PropertyField(rect, m_ParagraphSpacingProp, k_ParagraphSpacingLabel);
  650. EditorGUIUtility.labelWidth = 0;
  651. EditorGUI.indentLevel = oldIndent;
  652. if (EditorGUI.EndChangeCheck())
  653. {
  654. m_HavePropertiesChanged = true;
  655. }
  656. }
  657. void DrawAlignment()
  658. {
  659. // TEXT ALIGNMENT
  660. EditorGUI.BeginChangeCheck();
  661. EditorGUILayout.PropertyField(m_TextAlignmentProp, k_AlignmentLabel);
  662. // WRAPPING RATIOS shown if Justified mode is selected.
  663. if (((_HorizontalAlignmentOptions)m_TextAlignmentProp.intValue & _HorizontalAlignmentOptions.Justified) == _HorizontalAlignmentOptions.Justified || ((_HorizontalAlignmentOptions)m_TextAlignmentProp.intValue & _HorizontalAlignmentOptions.Flush) == _HorizontalAlignmentOptions.Flush)
  664. DrawPropertySlider(k_WrapMixLabel, m_WordWrappingRatiosProp);
  665. if (EditorGUI.EndChangeCheck())
  666. m_HavePropertiesChanged = true;
  667. EditorGUILayout.Space();
  668. }
  669. void DrawWrappingOverflow()
  670. {
  671. // TEXT WRAPPING
  672. EditorGUI.BeginChangeCheck();
  673. int wrapSelection = EditorGUILayout.Popup(k_WrappingLabel, m_EnableWordWrappingProp.boolValue ? 1 : 0, k_WrappingOptions);
  674. if (EditorGUI.EndChangeCheck())
  675. {
  676. m_EnableWordWrappingProp.boolValue = wrapSelection == 1;
  677. m_HavePropertiesChanged = true;
  678. m_IsInputPasingRequiredProp.boolValue = true;
  679. }
  680. // TEXT OVERFLOW
  681. EditorGUI.BeginChangeCheck();
  682. // Cache Reference to Linked Text Component
  683. TMP_Text oldLinkedComponent = m_LinkedTextComponentProp.objectReferenceValue as TMP_Text;
  684. if ((TextOverflowModes)m_TextOverflowModeProp.enumValueIndex == TextOverflowModes.Linked)
  685. {
  686. EditorGUILayout.BeginHorizontal();
  687. EditorGUILayout.PropertyField(m_TextOverflowModeProp, k_OverflowLabel);
  688. EditorGUILayout.PropertyField(m_LinkedTextComponentProp, GUIContent.none);
  689. EditorGUILayout.EndHorizontal();
  690. if (GUI.changed)
  691. {
  692. TMP_Text linkedComponent = m_LinkedTextComponentProp.objectReferenceValue as TMP_Text;
  693. if (linkedComponent)
  694. m_TextComponent.linkedTextComponent = linkedComponent;
  695. }
  696. }
  697. else if ((TextOverflowModes)m_TextOverflowModeProp.enumValueIndex == TextOverflowModes.Page)
  698. {
  699. EditorGUILayout.BeginHorizontal();
  700. EditorGUILayout.PropertyField(m_TextOverflowModeProp, k_OverflowLabel);
  701. EditorGUILayout.PropertyField(m_PageToDisplayProp, GUIContent.none);
  702. EditorGUILayout.EndHorizontal();
  703. if (oldLinkedComponent)
  704. m_TextComponent.linkedTextComponent = null;
  705. }
  706. else
  707. {
  708. EditorGUILayout.PropertyField(m_TextOverflowModeProp, k_OverflowLabel);
  709. if (oldLinkedComponent)
  710. m_TextComponent.linkedTextComponent = null;
  711. }
  712. if (EditorGUI.EndChangeCheck())
  713. {
  714. m_HavePropertiesChanged = true;
  715. m_IsInputPasingRequiredProp.boolValue = true;
  716. }
  717. EditorGUILayout.Space();
  718. }
  719. protected abstract void DrawExtraSettings();
  720. protected void DrawMargins()
  721. {
  722. EditorGUI.BeginChangeCheck();
  723. DrawMarginProperty(m_MarginProp, k_MarginsLabel);
  724. if (EditorGUI.EndChangeCheck())
  725. {
  726. m_HavePropertiesChanged = true;
  727. }
  728. EditorGUILayout.Space();
  729. }
  730. protected void DrawGeometrySorting()
  731. {
  732. EditorGUI.BeginChangeCheck();
  733. EditorGUILayout.PropertyField(m_GeometrySortingOrderProp, k_GeometrySortingLabel);
  734. if (EditorGUI.EndChangeCheck())
  735. m_HavePropertiesChanged = true;
  736. EditorGUILayout.Space();
  737. }
  738. protected void DrawRichText()
  739. {
  740. EditorGUI.BeginChangeCheck();
  741. EditorGUILayout.PropertyField(m_IsRichTextProp, k_RichTextLabel);
  742. if (EditorGUI.EndChangeCheck())
  743. m_HavePropertiesChanged = true;
  744. }
  745. protected void DrawParsing()
  746. {
  747. EditorGUI.BeginChangeCheck();
  748. EditorGUILayout.PropertyField(m_EnableEscapeCharacterParsingProp, k_EscapeCharactersLabel);
  749. EditorGUILayout.PropertyField(m_UseMaxVisibleDescenderProp, k_VisibleDescenderLabel);
  750. EditorGUILayout.Space();
  751. EditorGUILayout.PropertyField(m_SpriteAssetProp, k_SpriteAssetLabel, true);
  752. if (EditorGUI.EndChangeCheck())
  753. m_HavePropertiesChanged = true;
  754. EditorGUILayout.Space();
  755. }
  756. protected void DrawTextureMapping()
  757. {
  758. // TEXTURE MAPPING OPTIONS
  759. EditorGUI.BeginChangeCheck();
  760. EditorGUILayout.PropertyField(m_HorizontalMappingProp, k_HorizontalMappingLabel);
  761. EditorGUILayout.PropertyField(m_VerticalMappingProp, k_VerticalMappingLabel);
  762. if (EditorGUI.EndChangeCheck())
  763. {
  764. m_HavePropertiesChanged = true;
  765. }
  766. // UV OPTIONS
  767. if (m_HorizontalMappingProp.enumValueIndex > 0)
  768. {
  769. EditorGUI.BeginChangeCheck();
  770. EditorGUILayout.PropertyField(m_UvLineOffsetProp, k_LineOffsetLabel, GUILayout.MinWidth(70f));
  771. if (EditorGUI.EndChangeCheck())
  772. {
  773. m_HavePropertiesChanged = true;
  774. }
  775. }
  776. EditorGUILayout.Space();
  777. }
  778. protected void DrawKerning()
  779. {
  780. // KERNING
  781. EditorGUI.BeginChangeCheck();
  782. EditorGUILayout.PropertyField(m_EnableKerningProp, k_KerningLabel);
  783. if (EditorGUI.EndChangeCheck())
  784. {
  785. m_HavePropertiesChanged = true;
  786. }
  787. }
  788. protected void DrawPadding()
  789. {
  790. // EXTRA PADDING
  791. EditorGUI.BeginChangeCheck();
  792. EditorGUILayout.PropertyField(m_EnableExtraPaddingProp, k_PaddingLabel);
  793. if (EditorGUI.EndChangeCheck())
  794. {
  795. m_HavePropertiesChanged = true;
  796. m_CheckPaddingRequiredProp.boolValue = true;
  797. }
  798. }
  799. /// <summary>
  800. /// Method to retrieve the material presets that match the currently selected font asset.
  801. /// </summary>
  802. protected GUIContent[] GetMaterialPresets()
  803. {
  804. TMP_FontAsset fontAsset = m_FontAssetProp.objectReferenceValue as TMP_FontAsset;
  805. if (fontAsset == null) return null;
  806. m_MaterialPresets = TMP_EditorUtility.FindMaterialReferences(fontAsset);
  807. m_MaterialPresetNames = new GUIContent[m_MaterialPresets.Length];
  808. for (int i = 0; i < m_MaterialPresetNames.Length; i++)
  809. {
  810. m_MaterialPresetNames[i] = new GUIContent(m_MaterialPresets[i].name);
  811. if (m_TargetMaterial.GetInstanceID() == m_MaterialPresets[i].GetInstanceID())
  812. m_MaterialPresetSelectionIndex = i;
  813. }
  814. m_IsPresetListDirty = false;
  815. return m_MaterialPresetNames;
  816. }
  817. // DRAW MARGIN PROPERTY
  818. protected void DrawMarginProperty(SerializedProperty property, GUIContent label)
  819. {
  820. Rect rect = EditorGUILayout.GetControlRect(false, 2 * 18);
  821. EditorGUI.BeginProperty(rect, label, property);
  822. Rect pos0 = new Rect(rect.x + 15, rect.y + 2, rect.width - 15, 18);
  823. float width = rect.width + 3;
  824. pos0.width = EditorGUIUtility.labelWidth;
  825. GUI.Label(pos0, label);
  826. var vec = property.vector4Value;
  827. float widthB = width - EditorGUIUtility.labelWidth;
  828. float fieldWidth = widthB / 4;
  829. pos0.width = Mathf.Max(fieldWidth - 5, 45f);
  830. // Labels
  831. pos0.x = EditorGUIUtility.labelWidth + 15;
  832. GUI.Label(pos0, k_LeftLabel);
  833. pos0.x += fieldWidth;
  834. GUI.Label(pos0, k_TopLabel);
  835. pos0.x += fieldWidth;
  836. GUI.Label(pos0, k_RightLabel);
  837. pos0.x += fieldWidth;
  838. GUI.Label(pos0, k_BottomLabel);
  839. pos0.y += 18;
  840. pos0.x = EditorGUIUtility.labelWidth;
  841. vec.x = EditorGUI.FloatField(pos0, GUIContent.none, vec.x);
  842. pos0.x += fieldWidth;
  843. vec.y = EditorGUI.FloatField(pos0, GUIContent.none, vec.y);
  844. pos0.x += fieldWidth;
  845. vec.z = EditorGUI.FloatField(pos0, GUIContent.none, vec.z);
  846. pos0.x += fieldWidth;
  847. vec.w = EditorGUI.FloatField(pos0, GUIContent.none, vec.w);
  848. property.vector4Value = vec;
  849. EditorGUI.EndProperty();
  850. }
  851. protected void DrawPropertySlider(GUIContent label, SerializedProperty property)
  852. {
  853. Rect rect = EditorGUILayout.GetControlRect(false, 17);
  854. GUIContent content = label ?? GUIContent.none;
  855. EditorGUI.Slider(new Rect(rect.x, rect.y, rect.width, rect.height), property, 0.0f, 1.0f, content);
  856. }
  857. protected abstract bool IsMixSelectionTypes();
  858. // Special Handling of Undo / Redo Events.
  859. protected abstract void OnUndoRedo();
  860. }
  861. }