TMP_BaseEditorPanel.cs 49 KB

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