TMP_BaseEditorPanel.cs 58 KB

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