暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TMP_BaseEditorPanel.cs 60KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375
  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 (TMP_Settings.instance != null)
  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. Matrix4x4 matrix = m_RectTransform.worldToLocalMatrix;
  252. // Draw & process FreeMoveHandles
  253. // LEFT HANDLE
  254. Vector3 oldLeft = (m_HandlePoints[0] + m_HandlePoints[1]) * 0.5f;
  255. Vector3 newLeft = Handles.FreeMoveHandle(oldLeft, Quaternion.identity, HandleUtility.GetHandleSize(m_RectTransform.position) * 0.05f, Vector3.zero, Handles.DotHandleCap);
  256. bool hasChanged = false;
  257. if (oldLeft != newLeft)
  258. {
  259. oldLeft = matrix.MultiplyPoint(oldLeft);
  260. newLeft = matrix.MultiplyPoint(newLeft);
  261. float delta = (oldLeft.x - newLeft.x) * lossyScale.x;
  262. marginOffset.x += -delta / lossyScale.x;
  263. //Debug.Log("Left Margin H0:" + handlePoints[0] + " H1:" + handlePoints[1]);
  264. hasChanged = true;
  265. }
  266. // TOP HANDLE
  267. Vector3 oldTop = (m_HandlePoints[1] + m_HandlePoints[2]) * 0.5f;
  268. Vector3 newTop = Handles.FreeMoveHandle(oldTop, Quaternion.identity, HandleUtility.GetHandleSize(m_RectTransform.position) * 0.05f, Vector3.zero, Handles.DotHandleCap);
  269. if (oldTop != newTop)
  270. {
  271. oldTop = matrix.MultiplyPoint(oldTop);
  272. newTop = matrix.MultiplyPoint(newTop);
  273. float delta = (oldTop.y - newTop.y) * lossyScale.y;
  274. marginOffset.y += delta / lossyScale.y;
  275. //Debug.Log("Top Margin H1:" + handlePoints[1] + " H2:" + handlePoints[2]);
  276. hasChanged = true;
  277. }
  278. // RIGHT HANDLE
  279. Vector3 oldRight = (m_HandlePoints[2] + m_HandlePoints[3]) * 0.5f;
  280. Vector3 newRight = Handles.FreeMoveHandle(oldRight, Quaternion.identity, HandleUtility.GetHandleSize(m_RectTransform.position) * 0.05f, Vector3.zero, Handles.DotHandleCap);
  281. if (oldRight != newRight)
  282. {
  283. oldRight = matrix.MultiplyPoint(oldRight);
  284. newRight = matrix.MultiplyPoint(newRight);
  285. float delta = (oldRight.x - newRight.x) * lossyScale.x;
  286. marginOffset.z += delta / lossyScale.x;
  287. hasChanged = true;
  288. //Debug.Log("Right Margin H2:" + handlePoints[2] + " H3:" + handlePoints[3]);
  289. }
  290. // BOTTOM HANDLE
  291. Vector3 oldBottom = (m_HandlePoints[3] + m_HandlePoints[0]) * 0.5f;
  292. Vector3 newBottom = Handles.FreeMoveHandle(oldBottom, Quaternion.identity, HandleUtility.GetHandleSize(m_RectTransform.position) * 0.05f, Vector3.zero, Handles.DotHandleCap);
  293. if (oldBottom != newBottom)
  294. {
  295. oldBottom = matrix.MultiplyPoint(oldBottom);
  296. newBottom = matrix.MultiplyPoint(newBottom);
  297. float delta = (oldBottom.y - newBottom.y) * lossyScale.y;
  298. marginOffset.w += -delta / lossyScale.y;
  299. hasChanged = true;
  300. //Debug.Log("Bottom Margin H0:" + handlePoints[0] + " H3:" + handlePoints[3]);
  301. }
  302. if (hasChanged)
  303. {
  304. Undo.RecordObjects(new Object[] {m_RectTransform, m_TextComponent }, "Margin Changes");
  305. m_TextComponent.margin = marginOffset;
  306. EditorUtility.SetDirty(target);
  307. }
  308. }
  309. protected void DrawTextInput()
  310. {
  311. EditorGUILayout.Space();
  312. Rect rect = EditorGUILayout.GetControlRect(false, 22);
  313. GUI.Label(rect, new GUIContent("<b>Text Input</b>"), TMP_UIStyleManager.sectionHeader);
  314. EditorGUI.indentLevel = 0;
  315. // If the text component is linked, disable the text input box.
  316. if (m_ParentLinkedTextComponentProp.objectReferenceValue != null)
  317. {
  318. EditorGUILayout.HelpBox("The Text Input Box is disabled due to this text component being linked to another.", MessageType.Info);
  319. }
  320. else
  321. {
  322. // Display RTL Toggle
  323. float labelWidth = EditorGUIUtility.labelWidth;
  324. EditorGUIUtility.labelWidth = 110f;
  325. m_IsRightToLeftProp.boolValue = EditorGUI.Toggle(new Rect(rect.width - 120, rect.y + 3, 130, 20), k_RtlToggleLabel, m_IsRightToLeftProp.boolValue);
  326. EditorGUIUtility.labelWidth = labelWidth;
  327. EditorGUI.BeginChangeCheck();
  328. EditorGUILayout.PropertyField(m_TextProp, GUIContent.none);
  329. // Need to also compare string content due to issue related to scroll bar drag handle
  330. if (EditorGUI.EndChangeCheck() && m_TextProp.stringValue != m_TextComponent.text)
  331. {
  332. m_TextComponent.m_inputSource = TMP_Text.TextInputSources.TextInputBox;
  333. m_HavePropertiesChanged = true;
  334. }
  335. if (m_IsRightToLeftProp.boolValue)
  336. {
  337. // Copy source text to RTL string
  338. m_RtlText = string.Empty;
  339. string sourceText = m_TextProp.stringValue;
  340. // Reverse Text displayed in Text Input Box
  341. for (int i = 0; i < sourceText.Length; i++)
  342. m_RtlText += sourceText[sourceText.Length - i - 1];
  343. GUILayout.Label("RTL Text Input");
  344. EditorGUI.BeginChangeCheck();
  345. m_RtlText = EditorGUILayout.TextArea(m_RtlText, TMP_UIStyleManager.wrappingTextArea, GUILayout.Height(EditorGUI.GetPropertyHeight(m_TextProp) - EditorGUIUtility.singleLineHeight), GUILayout.ExpandWidth(true));
  346. if (EditorGUI.EndChangeCheck())
  347. {
  348. // Convert RTL input
  349. sourceText = string.Empty;
  350. // Reverse Text displayed in Text Input Box
  351. for (int i = 0; i < m_RtlText.Length; i++)
  352. sourceText += m_RtlText[m_RtlText.Length - i - 1];
  353. m_TextProp.stringValue = sourceText;
  354. }
  355. }
  356. // TEXT STYLE
  357. if (m_StyleNames != null)
  358. {
  359. rect = EditorGUILayout.GetControlRect(false, 17);
  360. EditorGUI.BeginProperty(rect, k_StyleLabel, m_TextStyleHashCodeProp);
  361. m_TextStyleIndexLookup.TryGetValue(m_TextStyleHashCodeProp.intValue, out m_StyleSelectionIndex);
  362. EditorGUI.BeginChangeCheck();
  363. m_StyleSelectionIndex = EditorGUI.Popup(rect, k_StyleLabel, m_StyleSelectionIndex, m_StyleNames);
  364. if (EditorGUI.EndChangeCheck())
  365. {
  366. m_TextStyleHashCodeProp.intValue = m_Styles[m_StyleSelectionIndex].hashCode;
  367. m_TextComponent.m_TextStyle = m_Styles[m_StyleSelectionIndex];
  368. m_HavePropertiesChanged = true;
  369. }
  370. EditorGUI.EndProperty();
  371. }
  372. }
  373. }
  374. protected void DrawMainSettings()
  375. {
  376. // MAIN SETTINGS SECTION
  377. GUILayout.Label(new GUIContent("<b>Main Settings</b>"), TMP_UIStyleManager.sectionHeader);
  378. //EditorGUI.indentLevel += 1;
  379. DrawFont();
  380. DrawColor();
  381. DrawSpacing();
  382. DrawAlignment();
  383. DrawWrappingOverflow();
  384. DrawTextureMapping();
  385. //EditorGUI.indentLevel -= 1;
  386. }
  387. void DrawFont()
  388. {
  389. bool isFontAssetDirty = false;
  390. // FONT ASSET
  391. EditorGUI.BeginChangeCheck();
  392. EditorGUILayout.PropertyField(m_FontAssetProp, k_FontAssetLabel);
  393. if (EditorGUI.EndChangeCheck())
  394. {
  395. m_HavePropertiesChanged = true;
  396. m_HasFontAssetChangedProp.boolValue = true;
  397. // Get new Material Presets for the new font asset
  398. m_MaterialPresetNames = GetMaterialPresets();
  399. m_MaterialPresetSelectionIndex = 0;
  400. isFontAssetDirty = true;
  401. }
  402. Rect rect;
  403. // MATERIAL PRESET
  404. if (m_MaterialPresetNames != null && !isFontAssetDirty )
  405. {
  406. EditorGUI.BeginChangeCheck();
  407. rect = EditorGUILayout.GetControlRect(false, 17);
  408. EditorGUI.BeginProperty(rect, k_MaterialPresetLabel, m_FontSharedMaterialProp);
  409. float oldHeight = EditorStyles.popup.fixedHeight;
  410. EditorStyles.popup.fixedHeight = rect.height;
  411. int oldSize = EditorStyles.popup.fontSize;
  412. EditorStyles.popup.fontSize = 11;
  413. if (m_FontSharedMaterialProp.objectReferenceValue != null)
  414. m_MaterialPresetIndexLookup.TryGetValue(m_FontSharedMaterialProp.objectReferenceValue.GetInstanceID(), out m_MaterialPresetSelectionIndex);
  415. m_MaterialPresetSelectionIndex = EditorGUI.Popup(rect, k_MaterialPresetLabel, m_MaterialPresetSelectionIndex, m_MaterialPresetNames);
  416. EditorGUI.EndProperty();
  417. if (EditorGUI.EndChangeCheck())
  418. {
  419. m_FontSharedMaterialProp.objectReferenceValue = m_MaterialPresets[m_MaterialPresetSelectionIndex];
  420. m_HavePropertiesChanged = true;
  421. }
  422. EditorStyles.popup.fixedHeight = oldHeight;
  423. EditorStyles.popup.fontSize = oldSize;
  424. }
  425. // FONT STYLE
  426. EditorGUI.BeginChangeCheck();
  427. int v1, v2, v3, v4, v5, v6, v7;
  428. if (EditorGUIUtility.wideMode)
  429. {
  430. rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight + 2f);
  431. EditorGUI.BeginProperty(rect, k_FontStyleLabel, m_FontStyleProp);
  432. EditorGUI.PrefixLabel(rect, k_FontStyleLabel);
  433. int styleValue = m_FontStyleProp.intValue;
  434. rect.x += EditorGUIUtility.labelWidth;
  435. rect.width -= EditorGUIUtility.labelWidth;
  436. rect.width = Mathf.Max(25f, rect.width / 7f);
  437. v1 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 1) == 1, k_BoldLabel, TMP_UIStyleManager.alignmentButtonLeft) ? 1 : 0; // Bold
  438. rect.x += rect.width;
  439. v2 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 2) == 2, k_ItalicLabel, TMP_UIStyleManager.alignmentButtonMid) ? 2 : 0; // Italics
  440. rect.x += rect.width;
  441. v3 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 4) == 4, k_UnderlineLabel, TMP_UIStyleManager.alignmentButtonMid) ? 4 : 0; // Underline
  442. rect.x += rect.width;
  443. v7 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 64) == 64, k_StrikethroughLabel, TMP_UIStyleManager.alignmentButtonRight) ? 64 : 0; // Strikethrough
  444. rect.x += rect.width;
  445. int selected = 0;
  446. EditorGUI.BeginChangeCheck();
  447. v4 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 8) == 8, k_LowercaseLabel, TMP_UIStyleManager.alignmentButtonLeft) ? 8 : 0; // Lowercase
  448. if (EditorGUI.EndChangeCheck() && v4 > 0)
  449. {
  450. selected = v4;
  451. }
  452. rect.x += rect.width;
  453. EditorGUI.BeginChangeCheck();
  454. v5 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 16) == 16, k_UppercaseLabel, TMP_UIStyleManager.alignmentButtonMid) ? 16 : 0; // Uppercase
  455. if (EditorGUI.EndChangeCheck() && v5 > 0)
  456. {
  457. selected = v5;
  458. }
  459. rect.x += rect.width;
  460. EditorGUI.BeginChangeCheck();
  461. v6 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 32) == 32, k_SmallcapsLabel, TMP_UIStyleManager.alignmentButtonRight) ? 32 : 0; // Smallcaps
  462. if (EditorGUI.EndChangeCheck() && v6 > 0)
  463. {
  464. selected = v6;
  465. }
  466. if (selected > 0)
  467. {
  468. v4 = selected == 8 ? 8 : 0;
  469. v5 = selected == 16 ? 16 : 0;
  470. v6 = selected == 32 ? 32 : 0;
  471. }
  472. EditorGUI.EndProperty();
  473. }
  474. else
  475. {
  476. rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight + 2f);
  477. EditorGUI.BeginProperty(rect, k_FontStyleLabel, m_FontStyleProp);
  478. EditorGUI.PrefixLabel(rect, k_FontStyleLabel);
  479. int styleValue = m_FontStyleProp.intValue;
  480. rect.x += EditorGUIUtility.labelWidth;
  481. rect.width -= EditorGUIUtility.labelWidth;
  482. rect.width = Mathf.Max(25f, rect.width / 4f);
  483. v1 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 1) == 1, k_BoldLabel, TMP_UIStyleManager.alignmentButtonLeft) ? 1 : 0; // Bold
  484. rect.x += rect.width;
  485. v2 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 2) == 2, k_ItalicLabel, TMP_UIStyleManager.alignmentButtonMid) ? 2 : 0; // Italics
  486. rect.x += rect.width;
  487. v3 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 4) == 4, k_UnderlineLabel, TMP_UIStyleManager.alignmentButtonMid) ? 4 : 0; // Underline
  488. rect.x += rect.width;
  489. v7 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 64) == 64, k_StrikethroughLabel, TMP_UIStyleManager.alignmentButtonRight) ? 64 : 0; // Strikethrough
  490. rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight + 2f);
  491. rect.x += EditorGUIUtility.labelWidth;
  492. rect.width -= EditorGUIUtility.labelWidth;
  493. rect.width = Mathf.Max(25f, rect.width / 4f);
  494. int selected = 0;
  495. EditorGUI.BeginChangeCheck();
  496. v4 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 8) == 8, k_LowercaseLabel, TMP_UIStyleManager.alignmentButtonLeft) ? 8 : 0; // Lowercase
  497. if (EditorGUI.EndChangeCheck() && v4 > 0)
  498. {
  499. selected = v4;
  500. }
  501. rect.x += rect.width;
  502. EditorGUI.BeginChangeCheck();
  503. v5 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 16) == 16, k_UppercaseLabel, TMP_UIStyleManager.alignmentButtonMid) ? 16 : 0; // Uppercase
  504. if (EditorGUI.EndChangeCheck() && v5 > 0)
  505. {
  506. selected = v5;
  507. }
  508. rect.x += rect.width;
  509. EditorGUI.BeginChangeCheck();
  510. v6 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 32) == 32, k_SmallcapsLabel, TMP_UIStyleManager.alignmentButtonRight) ? 32 : 0; // Smallcaps
  511. if (EditorGUI.EndChangeCheck() && v6 > 0)
  512. {
  513. selected = v6;
  514. }
  515. if (selected > 0)
  516. {
  517. v4 = selected == 8 ? 8 : 0;
  518. v5 = selected == 16 ? 16 : 0;
  519. v6 = selected == 32 ? 32 : 0;
  520. }
  521. EditorGUI.EndProperty();
  522. }
  523. if (EditorGUI.EndChangeCheck())
  524. {
  525. m_FontStyleProp.intValue = v1 + v2 + v3 + v4 + v5 + v6 + v7;
  526. m_HavePropertiesChanged = true;
  527. }
  528. // FONT SIZE
  529. EditorGUI.BeginChangeCheck();
  530. EditorGUI.BeginDisabledGroup(m_AutoSizingProp.boolValue);
  531. EditorGUILayout.PropertyField(m_FontSizeProp, k_FontSizeLabel, GUILayout.MaxWidth(EditorGUIUtility.labelWidth + 50f));
  532. EditorGUI.EndDisabledGroup();
  533. if (EditorGUI.EndChangeCheck())
  534. {
  535. float fontSize = Mathf.Clamp(m_FontSizeProp.floatValue, 0, 32767);
  536. m_FontSizeProp.floatValue = fontSize;
  537. m_FontSizeBaseProp.floatValue = fontSize;
  538. m_HavePropertiesChanged = true;
  539. }
  540. EditorGUI.indentLevel += 1;
  541. EditorGUI.BeginChangeCheck();
  542. EditorGUILayout.PropertyField(m_AutoSizingProp, k_AutoSizeLabel);
  543. if (EditorGUI.EndChangeCheck())
  544. {
  545. if (m_AutoSizingProp.boolValue == false)
  546. m_FontSizeProp.floatValue = m_FontSizeBaseProp.floatValue;
  547. m_HavePropertiesChanged = true;
  548. }
  549. // Show auto sizing options
  550. if (m_AutoSizingProp.boolValue)
  551. {
  552. rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight);
  553. EditorGUI.PrefixLabel(rect, k_AutoSizeOptionsLabel);
  554. int previousIndent = EditorGUI.indentLevel;
  555. EditorGUI.indentLevel = 0;
  556. rect.width = (rect.width - EditorGUIUtility.labelWidth) / 4f;
  557. rect.x += EditorGUIUtility.labelWidth;
  558. EditorGUIUtility.labelWidth = 24;
  559. EditorGUI.BeginChangeCheck();
  560. EditorGUI.PropertyField(rect, m_FontSizeMinProp, k_MinLabel);
  561. if (EditorGUI.EndChangeCheck())
  562. {
  563. float minSize = m_FontSizeMinProp.floatValue;
  564. minSize = Mathf.Max(0, minSize);
  565. m_FontSizeMinProp.floatValue = Mathf.Min(minSize, m_FontSizeMaxProp.floatValue);
  566. m_HavePropertiesChanged = true;
  567. }
  568. rect.x += rect.width;
  569. EditorGUIUtility.labelWidth = 27;
  570. EditorGUI.BeginChangeCheck();
  571. EditorGUI.PropertyField(rect, m_FontSizeMaxProp, k_MaxLabel);
  572. if (EditorGUI.EndChangeCheck())
  573. {
  574. float maxSize = Mathf.Clamp(m_FontSizeMaxProp.floatValue, 0, 32767);
  575. m_FontSizeMaxProp.floatValue = Mathf.Max(m_FontSizeMinProp.floatValue, maxSize);
  576. m_HavePropertiesChanged = true;
  577. }
  578. rect.x += rect.width;
  579. EditorGUI.BeginChangeCheck();
  580. EditorGUIUtility.labelWidth = 36;
  581. EditorGUI.PropertyField(rect, m_CharWidthMaxAdjProp, k_WdLabel);
  582. rect.x += rect.width;
  583. EditorGUIUtility.labelWidth = 28;
  584. EditorGUI.PropertyField(rect, m_LineSpacingMaxProp, k_LineLabel);
  585. EditorGUIUtility.labelWidth = 0;
  586. if (EditorGUI.EndChangeCheck())
  587. {
  588. m_CharWidthMaxAdjProp.floatValue = Mathf.Clamp(m_CharWidthMaxAdjProp.floatValue, 0, 50);
  589. m_LineSpacingMaxProp.floatValue = Mathf.Min(0, m_LineSpacingMaxProp.floatValue);
  590. m_HavePropertiesChanged = true;
  591. }
  592. EditorGUI.indentLevel = previousIndent;
  593. }
  594. EditorGUI.indentLevel -= 1;
  595. EditorGUILayout.Space();
  596. }
  597. void DrawColor()
  598. {
  599. // FACE VERTEX COLOR
  600. EditorGUI.BeginChangeCheck();
  601. EditorGUILayout.PropertyField(m_FontColorProp, k_BaseColorLabel);
  602. if (EditorGUI.EndChangeCheck())
  603. {
  604. m_HavePropertiesChanged = true;
  605. }
  606. EditorGUI.BeginChangeCheck();
  607. EditorGUILayout.PropertyField(m_EnableVertexGradientProp, k_ColorGradientLabel);
  608. if (EditorGUI.EndChangeCheck())
  609. {
  610. m_HavePropertiesChanged = true;
  611. }
  612. EditorGUIUtility.fieldWidth = 0;
  613. if (m_EnableVertexGradientProp.boolValue)
  614. {
  615. EditorGUI.indentLevel += 1;
  616. EditorGUI.BeginChangeCheck();
  617. EditorGUILayout.PropertyField(m_FontColorGradientPresetProp, k_ColorPresetLabel);
  618. SerializedObject obj = null;
  619. SerializedProperty colorMode;
  620. SerializedProperty topLeft;
  621. SerializedProperty topRight;
  622. SerializedProperty bottomLeft;
  623. SerializedProperty bottomRight;
  624. if (m_FontColorGradientPresetProp.objectReferenceValue == null)
  625. {
  626. colorMode = m_ColorModeProp;
  627. topLeft = m_FontColorGradientProp.FindPropertyRelative("topLeft");
  628. topRight = m_FontColorGradientProp.FindPropertyRelative("topRight");
  629. bottomLeft = m_FontColorGradientProp.FindPropertyRelative("bottomLeft");
  630. bottomRight = m_FontColorGradientProp.FindPropertyRelative("bottomRight");
  631. }
  632. else
  633. {
  634. obj = new SerializedObject(m_FontColorGradientPresetProp.objectReferenceValue);
  635. colorMode = obj.FindProperty("colorMode");
  636. topLeft = obj.FindProperty("topLeft");
  637. topRight = obj.FindProperty("topRight");
  638. bottomLeft = obj.FindProperty("bottomLeft");
  639. bottomRight = obj.FindProperty("bottomRight");
  640. }
  641. EditorGUILayout.PropertyField(colorMode, k_ColorModeLabel);
  642. Rect rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2));
  643. EditorGUI.PrefixLabel(rect, k_CorenerColorsLabel);
  644. rect.x += EditorGUIUtility.labelWidth;
  645. rect.width = rect.width - EditorGUIUtility.labelWidth;
  646. switch ((ColorMode)colorMode.enumValueIndex)
  647. {
  648. case ColorMode.Single:
  649. TMP_EditorUtility.DrawColorProperty(rect, topLeft);
  650. topRight.colorValue = topLeft.colorValue;
  651. bottomLeft.colorValue = topLeft.colorValue;
  652. bottomRight.colorValue = topLeft.colorValue;
  653. break;
  654. case ColorMode.HorizontalGradient:
  655. rect.width /= 2f;
  656. TMP_EditorUtility.DrawColorProperty(rect, topLeft);
  657. rect.x += rect.width;
  658. TMP_EditorUtility.DrawColorProperty(rect, topRight);
  659. bottomLeft.colorValue = topLeft.colorValue;
  660. bottomRight.colorValue = topRight.colorValue;
  661. break;
  662. case ColorMode.VerticalGradient:
  663. TMP_EditorUtility.DrawColorProperty(rect, topLeft);
  664. rect = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2));
  665. rect.x += EditorGUIUtility.labelWidth;
  666. TMP_EditorUtility.DrawColorProperty(rect, bottomLeft);
  667. topRight.colorValue = topLeft.colorValue;
  668. bottomRight.colorValue = bottomLeft.colorValue;
  669. break;
  670. case ColorMode.FourCornersGradient:
  671. rect.width /= 2f;
  672. TMP_EditorUtility.DrawColorProperty(rect, topLeft);
  673. rect.x += rect.width;
  674. TMP_EditorUtility.DrawColorProperty(rect, topRight);
  675. rect = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2));
  676. rect.x += EditorGUIUtility.labelWidth;
  677. rect.width = (rect.width - EditorGUIUtility.labelWidth) / 2f;
  678. TMP_EditorUtility.DrawColorProperty(rect, bottomLeft);
  679. rect.x += rect.width;
  680. TMP_EditorUtility.DrawColorProperty(rect, bottomRight);
  681. break;
  682. }
  683. if (EditorGUI.EndChangeCheck())
  684. {
  685. m_HavePropertiesChanged = true;
  686. if (obj != null)
  687. {
  688. obj.ApplyModifiedProperties();
  689. TMPro_EventManager.ON_COLOR_GRADIENT_PROPERTY_CHANGED(m_FontColorGradientPresetProp.objectReferenceValue as TMP_ColorGradient);
  690. }
  691. }
  692. EditorGUI.indentLevel -= 1;
  693. }
  694. EditorGUILayout.PropertyField(m_OverrideHtmlColorProp, k_OverrideTagsLabel);
  695. EditorGUILayout.Space();
  696. }
  697. void DrawSpacing()
  698. {
  699. // CHARACTER, LINE & PARAGRAPH SPACING
  700. EditorGUI.BeginChangeCheck();
  701. Rect rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight);
  702. EditorGUI.PrefixLabel(rect, k_SpacingOptionsLabel);
  703. int oldIndent = EditorGUI.indentLevel;
  704. EditorGUI.indentLevel = 0;
  705. float currentLabelWidth = EditorGUIUtility.labelWidth;
  706. rect.x += currentLabelWidth;
  707. rect.width = (rect.width - currentLabelWidth - 3f) / 2f;
  708. EditorGUIUtility.labelWidth = Mathf.Min(rect.width * 0.55f, 80f);
  709. EditorGUI.PropertyField(rect, m_CharacterSpacingProp, k_CharacterSpacingLabel);
  710. rect.x += rect.width + 3f;
  711. EditorGUI.PropertyField(rect, m_WordSpacingProp, k_WordSpacingLabel);
  712. rect = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight);
  713. rect.x += currentLabelWidth;
  714. rect.width = (rect.width - currentLabelWidth -3f) / 2f;
  715. EditorGUIUtility.labelWidth = Mathf.Min(rect.width * 0.55f, 80f);
  716. EditorGUI.PropertyField(rect, m_LineSpacingProp, k_LineSpacingLabel);
  717. rect.x += rect.width + 3f;
  718. EditorGUI.PropertyField(rect, m_ParagraphSpacingProp, k_ParagraphSpacingLabel);
  719. EditorGUIUtility.labelWidth = currentLabelWidth;
  720. EditorGUI.indentLevel = oldIndent;
  721. if (EditorGUI.EndChangeCheck())
  722. {
  723. m_HavePropertiesChanged = true;
  724. }
  725. EditorGUILayout.Space();
  726. }
  727. void DrawAlignment()
  728. {
  729. // TEXT ALIGNMENT
  730. EditorGUI.BeginChangeCheck();
  731. Rect rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.currentViewWidth > 504 ? 20 : 40 + 3);
  732. EditorGUI.BeginProperty(rect, k_AlignmentLabel, m_HorizontalAlignmentProp);
  733. EditorGUI.BeginProperty(rect, k_AlignmentLabel, m_VerticalAlignmentProp);
  734. EditorGUI.PrefixLabel(rect, k_AlignmentLabel);
  735. rect.x += EditorGUIUtility.labelWidth;
  736. EditorGUI.PropertyField(rect, m_HorizontalAlignmentProp, GUIContent.none);
  737. EditorGUI.PropertyField(rect, m_VerticalAlignmentProp, GUIContent.none);
  738. // WRAPPING RATIOS shown if Justified mode is selected.
  739. if (((HorizontalAlignmentOptions)m_HorizontalAlignmentProp.intValue & HorizontalAlignmentOptions.Justified) == HorizontalAlignmentOptions.Justified || ((HorizontalAlignmentOptions)m_HorizontalAlignmentProp.intValue & HorizontalAlignmentOptions.Flush) == HorizontalAlignmentOptions.Flush)
  740. DrawPropertySlider(k_WrapMixLabel, m_WordWrappingRatiosProp);
  741. if (EditorGUI.EndChangeCheck())
  742. m_HavePropertiesChanged = true;
  743. EditorGUI.EndProperty();
  744. EditorGUI.EndProperty();
  745. EditorGUILayout.Space();
  746. }
  747. void DrawWrappingOverflow()
  748. {
  749. // TEXT WRAPPING
  750. Rect rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight);
  751. EditorGUI.BeginProperty(rect, k_WrappingLabel, m_EnableWordWrappingProp);
  752. EditorGUI.BeginChangeCheck();
  753. int wrapSelection = EditorGUI.Popup(rect, k_WrappingLabel, m_EnableWordWrappingProp.boolValue ? 1 : 0, k_WrappingOptions);
  754. if (EditorGUI.EndChangeCheck())
  755. {
  756. m_EnableWordWrappingProp.boolValue = wrapSelection == 1;
  757. m_HavePropertiesChanged = true;
  758. }
  759. EditorGUI.EndProperty();
  760. // TEXT OVERFLOW
  761. EditorGUI.BeginChangeCheck();
  762. if ((TextOverflowModes)m_TextOverflowModeProp.enumValueIndex == TextOverflowModes.Linked)
  763. {
  764. EditorGUILayout.BeginHorizontal();
  765. float fieldWidth = EditorGUIUtility.fieldWidth;
  766. EditorGUIUtility.fieldWidth = 65;
  767. EditorGUILayout.PropertyField(m_TextOverflowModeProp, k_OverflowLabel);
  768. EditorGUIUtility.fieldWidth = fieldWidth;
  769. EditorGUILayout.PropertyField(m_LinkedTextComponentProp, GUIContent.none);
  770. EditorGUILayout.EndHorizontal();
  771. if (GUI.changed)
  772. {
  773. TMP_Text linkedComponent = m_LinkedTextComponentProp.objectReferenceValue as TMP_Text;
  774. if (linkedComponent == null)
  775. {
  776. m_LinkedTextComponentProp.objectReferenceValue = null;
  777. if (m_PreviousLinkedTextComponent != null)
  778. m_TextComponent.ReleaseLinkedTextComponent(m_PreviousLinkedTextComponent);
  779. }
  780. else if (m_TextComponent.IsSelfOrLinkedAncestor(linkedComponent))
  781. {
  782. m_LinkedTextComponentProp.objectReferenceValue = m_PreviousLinkedTextComponent;
  783. }
  784. else
  785. {
  786. if (m_PreviousLinkedTextComponent != null)
  787. m_TextComponent.ReleaseLinkedTextComponent(m_PreviousLinkedTextComponent);
  788. m_LinkedTextComponentProp.objectReferenceValue = linkedComponent;
  789. linkedComponent.parentLinkedComponent = m_TextComponent;
  790. m_PreviousLinkedTextComponent = linkedComponent;
  791. }
  792. }
  793. }
  794. else if ((TextOverflowModes)m_TextOverflowModeProp.enumValueIndex == TextOverflowModes.Page)
  795. {
  796. EditorGUILayout.BeginHorizontal();
  797. EditorGUILayout.PropertyField(m_TextOverflowModeProp, k_OverflowLabel);
  798. EditorGUILayout.PropertyField(m_PageToDisplayProp, GUIContent.none);
  799. EditorGUILayout.EndHorizontal();
  800. if (m_PreviousLinkedTextComponent)
  801. {
  802. m_TextComponent.ReleaseLinkedTextComponent(m_PreviousLinkedTextComponent);
  803. m_TextComponent.linkedTextComponent = null;
  804. }
  805. }
  806. else
  807. {
  808. EditorGUILayout.PropertyField(m_TextOverflowModeProp, k_OverflowLabel);
  809. if (m_PreviousLinkedTextComponent)
  810. {
  811. m_TextComponent.ReleaseLinkedTextComponent(m_PreviousLinkedTextComponent);
  812. m_TextComponent.linkedTextComponent = null;
  813. }
  814. }
  815. if (EditorGUI.EndChangeCheck())
  816. {
  817. m_HavePropertiesChanged = true;
  818. }
  819. EditorGUILayout.Space();
  820. }
  821. protected abstract void DrawExtraSettings();
  822. protected void DrawMargins()
  823. {
  824. EditorGUI.BeginChangeCheck();
  825. DrawMarginProperty(m_MarginProp, k_MarginsLabel);
  826. if (EditorGUI.EndChangeCheck())
  827. {
  828. m_HavePropertiesChanged = true;
  829. }
  830. EditorGUILayout.Space();
  831. }
  832. protected void DrawGeometrySorting()
  833. {
  834. EditorGUI.BeginChangeCheck();
  835. EditorGUILayout.PropertyField(m_GeometrySortingOrderProp, k_GeometrySortingLabel);
  836. if (EditorGUI.EndChangeCheck())
  837. m_HavePropertiesChanged = true;
  838. EditorGUILayout.Space();
  839. }
  840. protected void DrawIsTextObjectScaleStatic()
  841. {
  842. EditorGUI.BeginChangeCheck();
  843. EditorGUILayout.PropertyField(m_IsTextObjectScaleStaticProp, k_IsTextObjectScaleStatic);
  844. if (EditorGUI.EndChangeCheck())
  845. {
  846. m_TextComponent.isTextObjectScaleStatic = m_IsTextObjectScaleStaticProp.boolValue;
  847. m_HavePropertiesChanged = true;
  848. }
  849. EditorGUILayout.Space();
  850. }
  851. protected void DrawRichText()
  852. {
  853. EditorGUI.BeginChangeCheck();
  854. EditorGUILayout.PropertyField(m_IsRichTextProp, k_RichTextLabel);
  855. if (EditorGUI.EndChangeCheck())
  856. m_HavePropertiesChanged = true;
  857. }
  858. protected void DrawParsing()
  859. {
  860. EditorGUI.BeginChangeCheck();
  861. EditorGUILayout.PropertyField(m_EnableEscapeCharacterParsingProp, k_EscapeCharactersLabel);
  862. EditorGUILayout.PropertyField(m_UseMaxVisibleDescenderProp, k_VisibleDescenderLabel);
  863. if (EditorGUI.EndChangeCheck())
  864. m_HavePropertiesChanged = true;
  865. EditorGUILayout.Space();
  866. }
  867. protected void DrawSpriteAsset()
  868. {
  869. EditorGUI.BeginChangeCheck();
  870. EditorGUILayout.PropertyField(m_SpriteAssetProp, k_SpriteAssetLabel, true);
  871. if (EditorGUI.EndChangeCheck())
  872. m_HavePropertiesChanged = true;
  873. EditorGUILayout.Space();
  874. }
  875. protected void DrawStyleSheet()
  876. {
  877. EditorGUI.BeginChangeCheck();
  878. EditorGUILayout.PropertyField(m_StyleSheetAssetProp, k_StyleSheetAssetLabel, true);
  879. if (EditorGUI.EndChangeCheck())
  880. {
  881. m_StyleNames = GetStyleNames();
  882. m_HavePropertiesChanged = true;
  883. }
  884. EditorGUILayout.Space();
  885. }
  886. protected void DrawTextureMapping()
  887. {
  888. // TEXTURE MAPPING OPTIONS
  889. EditorGUI.BeginChangeCheck();
  890. EditorGUILayout.PropertyField(m_HorizontalMappingProp, k_HorizontalMappingLabel);
  891. EditorGUILayout.PropertyField(m_VerticalMappingProp, k_VerticalMappingLabel);
  892. if (EditorGUI.EndChangeCheck())
  893. {
  894. m_HavePropertiesChanged = true;
  895. }
  896. // UV OPTIONS
  897. if (m_HorizontalMappingProp.enumValueIndex > 0)
  898. {
  899. EditorGUI.BeginChangeCheck();
  900. EditorGUILayout.PropertyField(m_UvLineOffsetProp, k_LineOffsetLabel, GUILayout.MinWidth(70f));
  901. if (EditorGUI.EndChangeCheck())
  902. {
  903. m_HavePropertiesChanged = true;
  904. }
  905. }
  906. EditorGUILayout.Space();
  907. }
  908. protected void DrawKerning()
  909. {
  910. // KERNING
  911. EditorGUI.BeginChangeCheck();
  912. EditorGUILayout.PropertyField(m_EnableKerningProp, k_KerningLabel);
  913. if (EditorGUI.EndChangeCheck())
  914. {
  915. m_HavePropertiesChanged = true;
  916. }
  917. }
  918. protected void DrawPadding()
  919. {
  920. // EXTRA PADDING
  921. EditorGUI.BeginChangeCheck();
  922. EditorGUILayout.PropertyField(m_EnableExtraPaddingProp, k_PaddingLabel);
  923. if (EditorGUI.EndChangeCheck())
  924. {
  925. m_HavePropertiesChanged = true;
  926. m_CheckPaddingRequiredProp.boolValue = true;
  927. }
  928. }
  929. /// <summary>
  930. /// Method to retrieve the material presets that match the currently selected font asset.
  931. /// </summary>
  932. protected GUIContent[] GetMaterialPresets()
  933. {
  934. TMP_FontAsset fontAsset = m_FontAssetProp.objectReferenceValue as TMP_FontAsset;
  935. if (fontAsset == null) return null;
  936. m_MaterialPresets = TMP_EditorUtility.FindMaterialReferences(fontAsset);
  937. m_MaterialPresetNames = new GUIContent[m_MaterialPresets.Length];
  938. m_MaterialPresetIndexLookup.Clear();
  939. for (int i = 0; i < m_MaterialPresetNames.Length; i++)
  940. {
  941. m_MaterialPresetNames[i] = new GUIContent(m_MaterialPresets[i].name);
  942. m_MaterialPresetIndexLookup.Add(m_MaterialPresets[i].GetInstanceID(), i);
  943. //if (m_TargetMaterial.GetInstanceID() == m_MaterialPresets[i].GetInstanceID())
  944. // m_MaterialPresetSelectionIndex = i;
  945. }
  946. m_IsPresetListDirty = false;
  947. return m_MaterialPresetNames;
  948. }
  949. protected GUIContent[] GetStyleNames()
  950. {
  951. k_AvailableStyles.Clear();
  952. m_TextStyleIndexLookup.Clear();
  953. m_Styles.Clear();
  954. // First style on the list is always the Normal default style.
  955. TMP_Style styleNormal = TMP_Style.NormalStyle;
  956. m_Styles.Add(styleNormal);
  957. m_TextStyleIndexLookup.Add(styleNormal.hashCode, 0);
  958. k_AvailableStyles.Add(styleNormal.hashCode, styleNormal);
  959. // Get styles from Style Sheet potentially assigned to the text object.
  960. TMP_StyleSheet localStyleSheet = (TMP_StyleSheet)m_StyleSheetAssetProp.objectReferenceValue;
  961. if (localStyleSheet != null)
  962. {
  963. int styleCount = localStyleSheet.styles.Count;
  964. for (int i = 0; i < styleCount; i++)
  965. {
  966. TMP_Style style = localStyleSheet.styles[i];
  967. if (k_AvailableStyles.ContainsKey(style.hashCode) == false)
  968. {
  969. k_AvailableStyles.Add(style.hashCode, style);
  970. m_Styles.Add(style);
  971. m_TextStyleIndexLookup.Add(style.hashCode, m_TextStyleIndexLookup.Count);
  972. }
  973. }
  974. }
  975. // Get styles from TMP Settings' default style sheet.
  976. TMP_StyleSheet globalStyleSheet = TMP_Settings.defaultStyleSheet;
  977. if (globalStyleSheet != null)
  978. {
  979. int styleCount = globalStyleSheet.styles.Count;
  980. for (int i = 0; i < styleCount; i++)
  981. {
  982. TMP_Style style = globalStyleSheet.styles[i];
  983. if (k_AvailableStyles.ContainsKey(style.hashCode) == false)
  984. {
  985. k_AvailableStyles.Add(style.hashCode, style);
  986. m_Styles.Add(style);
  987. m_TextStyleIndexLookup.Add(style.hashCode, m_TextStyleIndexLookup.Count);
  988. }
  989. }
  990. }
  991. // Create array that will contain the list of available styles.
  992. GUIContent[] styleNames = k_AvailableStyles.Values.Select(item => new GUIContent(item.name)).ToArray();
  993. // Set text style index
  994. m_TextStyleIndexLookup.TryGetValue(m_TextStyleHashCodeProp.intValue, out m_StyleSelectionIndex);
  995. return styleNames;
  996. }
  997. // DRAW MARGIN PROPERTY
  998. protected void DrawMarginProperty(SerializedProperty property, GUIContent label)
  999. {
  1000. Rect rect = EditorGUILayout.GetControlRect(false, 2 * 18);
  1001. EditorGUI.BeginProperty(rect, label, property);
  1002. Rect pos0 = new Rect(rect.x, rect.y + 2, rect.width - 15, 18);
  1003. float width = rect.width + 3;
  1004. pos0.width = EditorGUIUtility.labelWidth;
  1005. EditorGUI.PrefixLabel(pos0, label);
  1006. Vector4 margins = property.vector4Value;
  1007. float widthB = width - EditorGUIUtility.labelWidth;
  1008. float fieldWidth = widthB / 4;
  1009. pos0.width = Mathf.Max(fieldWidth - 5, 45f);
  1010. // Labels
  1011. pos0.x = EditorGUIUtility.labelWidth + 15;
  1012. margins.x = DrawMarginField(pos0, "Left", margins.x);
  1013. pos0.x += fieldWidth;
  1014. margins.y = DrawMarginField(pos0, "Top", margins.y);
  1015. pos0.x += fieldWidth;
  1016. margins.z = DrawMarginField(pos0, "Right", margins.z);
  1017. pos0.x += fieldWidth;
  1018. margins.w = DrawMarginField(pos0, "Bottom", margins.w);
  1019. property.vector4Value = margins;
  1020. EditorGUI.EndProperty();
  1021. }
  1022. float DrawMarginField(Rect position, string label, float value)
  1023. {
  1024. int controlId = GUIUtility.GetControlID(FocusType.Keyboard, position);
  1025. EditorGUI.PrefixLabel(position, controlId, new GUIContent(label));
  1026. Rect dragZone = new Rect(position.x, position.y, position.width, position.height);
  1027. position.y += EditorGUIUtility.singleLineHeight;
  1028. return EditorGUI.DoFloatField(EditorGUI.s_RecycledEditor, position, dragZone, controlId, value, EditorGUI.kFloatFieldFormatString, EditorStyles.numberField, true);
  1029. }
  1030. protected void DrawPropertySlider(GUIContent label, SerializedProperty property)
  1031. {
  1032. Rect rect = EditorGUILayout.GetControlRect(false, 17);
  1033. GUIContent content = label ?? GUIContent.none;
  1034. EditorGUI.Slider(new Rect(rect.x, rect.y, rect.width, rect.height), property, 0.0f, 1.0f, content);
  1035. }
  1036. protected abstract bool IsMixSelectionTypes();
  1037. // Special Handling of Undo / Redo Events.
  1038. protected abstract void OnUndoRedo();
  1039. }
  1040. }