Hue Preserving Color Blending
TMP_SubMeshUI.cs
1 using UnityEngine;
2 using UnityEngine.UI;
3 using System.Collections;
4 using System.Collections.Generic;
5 
6 #pragma warning disable 0414 // Disabled a few warnings related to serialized variables not used in this script but used in the editor.
7 
8 namespace TMPro
9 {
10 
11  [ExecuteInEditMode]
12  public class TMP_SubMeshUI : MaskableGraphic, IClippable, IMaskable, IMaterialModifier
13  {
18  {
19  get { return m_fontAsset; }
20  set { m_fontAsset = value; }
21  }
22  [SerializeField]
23  private TMP_FontAsset m_fontAsset;
24 
25 
30  {
31  get { return m_spriteAsset; }
32  set { m_spriteAsset = value; }
33  }
34  [SerializeField]
35  private TMP_SpriteAsset m_spriteAsset;
36 
37 
41  public override Texture mainTexture
42  {
43  get
44  {
45  if (this.sharedMaterial != null)
46  return this.sharedMaterial.GetTexture(ShaderUtilities.ID_MainTex);
47 
48 
49  return null;
50  }
51  }
52 
53 
57  public override Material material
58  {
59  // Return a new Instance of the Material if none exists. Otherwise return the current Material Instance.
60  get { return GetMaterial(m_sharedMaterial); }
61 
62  // Assign new font material
63  set
64  {
65  if (m_sharedMaterial != null && m_sharedMaterial.GetInstanceID() == value.GetInstanceID())
66  return;
67 
68  m_sharedMaterial = m_material = value;
69 
70  m_padding = GetPaddingForMaterial();
71 
74  }
75  }
76  [SerializeField]
77  private Material m_material;
78 
79 
83  public Material sharedMaterial
84  {
85  get { return m_sharedMaterial; }
86  set { SetSharedMaterial(value); }
87  }
88  [SerializeField]
89  private Material m_sharedMaterial;
90 
91 
95  public Material fallbackMaterial
96  {
97  get { return m_fallbackMaterial; }
98  set
99  {
100  if (m_fallbackMaterial == value) return;
101 
102  if (m_fallbackMaterial != null && m_fallbackMaterial != value)
103  TMP_MaterialManager.ReleaseFallbackMaterial(m_fallbackMaterial);
104 
105  m_fallbackMaterial = value;
106  TMP_MaterialManager.AddFallbackMaterialReference(m_fallbackMaterial);
107 
108  SetSharedMaterial(m_fallbackMaterial);
109  }
110  }
111  private Material m_fallbackMaterial;
112 
113 
117  public Material fallbackSourceMaterial
118  {
119  get { return m_fallbackSourceMaterial; }
120  set { m_fallbackSourceMaterial = value; }
121  }
122  private Material m_fallbackSourceMaterial;
123 
124 
128  public override Material materialForRendering
129  {
130  get
131  {
132  return TMP_MaterialManager.GetMaterialForRendering(this, m_sharedMaterial);
133  }
134  }
135 
136 
140  public bool isDefaultMaterial
141  {
142  get { return m_isDefaultMaterial; }
143  set { m_isDefaultMaterial = value; }
144  }
145  [SerializeField]
146  private bool m_isDefaultMaterial;
147 
148 
152  public float padding
153  {
154  get { return m_padding; }
155  set { m_padding = value; }
156  }
157  [SerializeField]
158  private float m_padding;
159 
160 
164  public new CanvasRenderer canvasRenderer
165  {
166  get { if (m_canvasRenderer == null) m_canvasRenderer = GetComponent<CanvasRenderer>();
167 
168  return m_canvasRenderer;
169  }
170  }
171  [SerializeField]
172  private CanvasRenderer m_canvasRenderer;
173 
174 
178  public Mesh mesh
179  {
180  get
181  {
182  if (m_mesh == null)
183  {
184  m_mesh = new Mesh();
185  m_mesh.hideFlags = HideFlags.HideAndDontSave;
186  }
187 
188  return m_mesh;
189  }
190  set { m_mesh = value; }
191  }
192  private Mesh m_mesh;
193 
194 
195  [SerializeField]
196  private TextMeshProUGUI m_TextComponent;
197 
198 
199  [System.NonSerialized]
200  private bool m_isRegisteredForEvents;
201  private bool m_materialDirty;
202  [SerializeField]
203  private int m_materialReferenceIndex;
204 
205 
206 
213  public static TMP_SubMeshUI AddSubTextObject(TextMeshProUGUI textComponent, MaterialReference materialReference)
214  {
215  GameObject go = new GameObject("TMP UI SubObject [" + materialReference.material.name + "]", typeof(RectTransform));
216 
217  go.transform.SetParent(textComponent.transform, false);
218  go.layer = textComponent.gameObject.layer;
219 
220  RectTransform rectTransform = go.GetComponent<RectTransform>();
221  rectTransform.anchorMin = Vector2.zero;
222  rectTransform.anchorMax = Vector2.one;
223  rectTransform.sizeDelta = Vector2.zero;
224  rectTransform.pivot = textComponent.rectTransform.pivot;
225 
226  TMP_SubMeshUI subMesh = go.AddComponent<TMP_SubMeshUI>();
227 
228  subMesh.m_canvasRenderer = subMesh.canvasRenderer;
229  subMesh.m_TextComponent = textComponent;
230 
231  subMesh.m_materialReferenceIndex = materialReference.index;
232  subMesh.m_fontAsset = materialReference.fontAsset;
233  subMesh.m_spriteAsset = materialReference.spriteAsset;
234  subMesh.m_isDefaultMaterial = materialReference.isDefaultMaterial;
235  subMesh.SetSharedMaterial(materialReference.material);
236 
237  return subMesh;
238  }
239 
240 
241 
245  protected override void OnEnable()
246  {
247  //Debug.Log("*** SubObject OnEnable() ***");
248 
249  // Register Callbacks for various events.
250  if (!m_isRegisteredForEvents)
251  {
252 
253  #if UNITY_EDITOR
254  TMPro_EventManager.MATERIAL_PROPERTY_EVENT.Add(ON_MATERIAL_PROPERTY_CHANGED);
255  TMPro_EventManager.FONT_PROPERTY_EVENT.Add(ON_FONT_PROPERTY_CHANGED);
256  //TMPro_EventManager.TEXTMESHPRO_PROPERTY_EVENT.Add(ON_TEXTMESHPRO_PROPERTY_CHANGED);
257  TMPro_EventManager.DRAG_AND_DROP_MATERIAL_EVENT.Add(ON_DRAG_AND_DROP_MATERIAL);
258  //TMPro_EventManager.TEXT_STYLE_PROPERTY_EVENT.Add(ON_TEXT_STYLE_CHANGED);
259  TMPro_EventManager.SPRITE_ASSET_PROPERTY_EVENT.Add(ON_SPRITE_ASSET_PROPERTY_CHANGED);
260  //TMPro_EventManager.TMP_SETTINGS_PROPERTY_EVENT.Add(ON_TMP_SETTINGS_CHANGED);
261  #endif
262 
263  m_isRegisteredForEvents = true;
264  }
265 
266  m_ShouldRecalculateStencil = true;
269 
270  //SetAllDirty();
271  }
272 
273 
274  protected override void OnDisable()
275  {
276  //Debug.Log("*** SubObject OnDisable() ***");
277 
278  //m_canvasRenderer.Clear();
280 
281  if (m_MaskMaterial != null)
282  {
283  TMP_MaterialManager.ReleaseStencilMaterial(m_MaskMaterial);
284  m_MaskMaterial = null;
285  }
286 
287  if (m_fallbackMaterial != null)
288  {
289  TMP_MaterialManager.ReleaseFallbackMaterial(m_fallbackMaterial);
290  m_fallbackMaterial = null;
291  }
292 
293  base.OnDisable();
294  }
295 
296 
297  protected override void OnDestroy()
298  {
299  //Debug.Log("*** OnDestroy() ***");
300 
301  // Destroy Mesh
302  if (m_mesh != null) DestroyImmediate(m_mesh);
303 
304  if (m_MaskMaterial != null)
305  TMP_MaterialManager.ReleaseStencilMaterial(m_MaskMaterial);
306 
307  if (m_fallbackMaterial != null)
308  {
309  TMP_MaterialManager.ReleaseFallbackMaterial(m_fallbackMaterial);
310  m_fallbackMaterial = null;
311  }
312 
313 #if UNITY_EDITOR
314  // Unregister the event this object was listening to
315  TMPro_EventManager.MATERIAL_PROPERTY_EVENT.Remove(ON_MATERIAL_PROPERTY_CHANGED);
316  TMPro_EventManager.FONT_PROPERTY_EVENT.Remove(ON_FONT_PROPERTY_CHANGED);
317  //TMPro_EventManager.TEXTMESHPRO_PROPERTY_EVENT.Remove(ON_TEXTMESHPRO_PROPERTY_CHANGED);
318  TMPro_EventManager.DRAG_AND_DROP_MATERIAL_EVENT.Remove(ON_DRAG_AND_DROP_MATERIAL);
319  //TMPro_EventManager.TEXT_STYLE_PROPERTY_EVENT.Remove(ON_TEXT_STYLE_CHANGED);
320  TMPro_EventManager.SPRITE_ASSET_PROPERTY_EVENT.Remove(ON_SPRITE_ASSET_PROPERTY_CHANGED);
321  //TMPro_EventManager.TMP_SETTINGS_PROPERTY_EVENT.Remove(ON_TMP_SETTINGS_CHANGED);
322  #endif
323 
324  m_isRegisteredForEvents = false;
325 
327  }
328 
329 
330 
331 #if UNITY_EDITOR
332  // Event received when custom material editor properties are changed.
333  void ON_MATERIAL_PROPERTY_CHANGED(bool isChanged, Material mat)
334  {
335  //Debug.Log("*** ON_MATERIAL_PROPERTY_CHANGED ***");
336 
337  int targetMaterialID = mat.GetInstanceID();
338  int sharedMaterialID = m_sharedMaterial.GetInstanceID();
339  int maskingMaterialID = m_MaskMaterial == null ? 0 : m_MaskMaterial.GetInstanceID();
340  int fallbackSourceMaterialID = m_fallbackSourceMaterial == null ? 0 : m_fallbackSourceMaterial.GetInstanceID();
341 
342  // Filter events and return if the affected material is not this object's material.
343  //if (targetMaterialID != sharedMaterialID && targetMaterialID != maskingMaterialID) return;
344 
345  // Filter events and return if the affected material is not this object's material.
346  if (m_fallbackMaterial != null && fallbackSourceMaterialID == targetMaterialID)
347  TMP_MaterialManager.CopyMaterialPresetProperties(mat, m_fallbackMaterial);
348 
349  if (m_TextComponent == null) m_TextComponent = GetComponentInParent<TextMeshProUGUI>();
350 
351  // Make sure material properties are synchronized between the assigned material and masking material.
352  if (m_MaskMaterial != null)
353  {
354  UnityEditor.Undo.RecordObject(m_MaskMaterial, "Material Property Changes");
355  UnityEditor.Undo.RecordObject(m_sharedMaterial, "Material Property Changes");
356 
357  if (targetMaterialID == sharedMaterialID)
358  {
359  //Debug.Log("Copy base material properties to masking material if not null.");
360  float stencilID = m_MaskMaterial.GetFloat(ShaderUtilities.ID_StencilID);
361  float stencilComp = m_MaskMaterial.GetFloat(ShaderUtilities.ID_StencilComp);
362  m_MaskMaterial.CopyPropertiesFromMaterial(mat);
363  m_MaskMaterial.shaderKeywords = mat.shaderKeywords;
364 
365  m_MaskMaterial.SetFloat(ShaderUtilities.ID_StencilID, stencilID);
366  m_MaskMaterial.SetFloat(ShaderUtilities.ID_StencilComp, stencilComp);
367  }
368  else if (targetMaterialID == maskingMaterialID)
369  {
370  // Update the padding
372 
373  m_sharedMaterial.CopyPropertiesFromMaterial(mat);
374  m_sharedMaterial.shaderKeywords = mat.shaderKeywords;
375  m_sharedMaterial.SetFloat(ShaderUtilities.ID_StencilID, 0);
376  m_sharedMaterial.SetFloat(ShaderUtilities.ID_StencilComp, 8);
377  }
378  else if (fallbackSourceMaterialID == targetMaterialID)
379  {
380  float stencilID = m_MaskMaterial.GetFloat(ShaderUtilities.ID_StencilID);
381  float stencilComp = m_MaskMaterial.GetFloat(ShaderUtilities.ID_StencilComp);
382  m_MaskMaterial.CopyPropertiesFromMaterial(m_fallbackMaterial);
383  m_MaskMaterial.shaderKeywords = m_fallbackMaterial.shaderKeywords;
384 
385  m_MaskMaterial.SetFloat(ShaderUtilities.ID_StencilID, stencilID);
386  m_MaskMaterial.SetFloat(ShaderUtilities.ID_StencilComp, stencilComp);
387  }
388  }
389 
390  m_padding = GetPaddingForMaterial();
391 
393  m_ShouldRecalculateStencil = true;
396  }
397 
398 
399  // Event to Track Material Changed resulting from Drag-n-drop.
400  void ON_DRAG_AND_DROP_MATERIAL(GameObject obj, Material currentMaterial, Material newMaterial)
401  {
402  // Check if event applies to this current object
403  #if UNITY_2018_2_OR_NEWER
404  if (obj == gameObject || UnityEditor.PrefabUtility.GetCorrespondingObjectFromSource(gameObject) == obj)
405  #else
406  if (obj == gameObject || UnityEditor.PrefabUtility.GetPrefabParent(gameObject) == obj)
407  #endif
408  {
409  if (!m_isDefaultMaterial) return;
410 
411  // Make sure we have a valid reference to the renderer.
412  if (m_canvasRenderer == null) m_canvasRenderer = GetComponent<CanvasRenderer>();
413 
414  UnityEditor.Undo.RecordObject(this, "Material Assignment");
415  UnityEditor.Undo.RecordObject(m_canvasRenderer, "Material Assignment");
416 
417  SetSharedMaterial(newMaterial);
418  m_TextComponent.havePropertiesChanged = true;
419  }
420  }
421 
422  // Event received when font asset properties are changed in Font Inspector
423  void ON_SPRITE_ASSET_PROPERTY_CHANGED(bool isChanged, UnityEngine.Object obj)
424  {
425  //if (spriteSheet != null && (obj as TMP_SpriteAsset == m_spriteAsset || obj as Texture2D == m_spriteAsset.spriteSheet))
426  //{
427  if (m_TextComponent != null)
428  {
429  m_TextComponent.havePropertiesChanged = true;
430  //m_TextComponent.SetVerticesDirty();
431  }
432 
433  //}
434  }
435 
436  // Event received when font asset properties are changed in Font Inspector
437  void ON_FONT_PROPERTY_CHANGED(bool isChanged, TMP_FontAsset font)
438  {
439  if (m_fontAsset != null && font.GetInstanceID() == m_fontAsset.GetInstanceID())
440  {
441  // Copy Normal and Bold Weight
442  if (m_fallbackMaterial != null)
443  {
444  m_fallbackMaterial.SetFloat(ShaderUtilities.ID_WeightNormal, m_fontAsset.normalStyle);
445  m_fallbackMaterial.SetFloat(ShaderUtilities.ID_WeightBold, m_fontAsset.boldStyle);
446  }
447  }
448  }
449 
453  void ON_TMP_SETTINGS_CHANGED()
454  {
455  //Debug.Log("TMP Setting have changed.");
456  //SetVerticesDirty();
457  //SetMaterialDirty();
458  }
459 #endif
460 
464  protected override void OnTransformParentChanged()
465  {
466  if (!this.IsActive())
467  return;
468 
469  m_ShouldRecalculateStencil = true;
472  }
473 
474 
480  public override Material GetModifiedMaterial(Material baseMaterial)
481  {
482  Material mat = baseMaterial;
483 
484  if (m_ShouldRecalculateStencil)
485  {
486  m_StencilValue = TMP_MaterialManager.GetStencilID(gameObject);
487  m_ShouldRecalculateStencil = false;
488  }
489 
490  if (m_StencilValue > 0)
491  {
492  mat = TMP_MaterialManager.GetStencilMaterial(baseMaterial, m_StencilValue);
493  if (m_MaskMaterial != null)
494  TMP_MaterialManager.ReleaseStencilMaterial(m_MaskMaterial);
495 
496  m_MaskMaterial = mat;
497  }
498 
499  return mat;
500  }
501 
502 
507  public float GetPaddingForMaterial()
508  {
509  float padding = ShaderUtilities.GetPadding(m_sharedMaterial, m_TextComponent.extraPadding, m_TextComponent.isUsingBold);
510 
511  return padding;
512  }
513 
514 
519  public float GetPaddingForMaterial(Material mat)
520  {
521  float padding = ShaderUtilities.GetPadding(mat, m_TextComponent.extraPadding, m_TextComponent.isUsingBold);
522 
523  return padding;
524  }
525 
526 
532  public void UpdateMeshPadding(bool isExtraPadding, bool isUsingBold)
533  {
534  m_padding = ShaderUtilities.GetPadding(m_sharedMaterial, isExtraPadding, isUsingBold);
535  }
536 
537 
541  public override void SetAllDirty()
542  {
543  //SetLayoutDirty();
544  //SetVerticesDirty();
545  //SetMaterialDirty();
546  }
547 
548 
552  public override void SetVerticesDirty()
553  {
554  if (!this.IsActive())
555  return;
556 
557  // This is called on the parent TextMeshPro component.
558  if (m_TextComponent != null)
559  {
560  m_TextComponent.havePropertiesChanged = true;
561  m_TextComponent.SetVerticesDirty();
562  }
563  }
564 
565 
569  public override void SetLayoutDirty()
570  {
571 
572  }
573 
574 
578  public override void SetMaterialDirty()
579  {
580  //Debug.Log("*** STO-UI - SetMaterialDirty() *** FRAME (" + Time.frameCount + ")");
581 
582  //if (!this.IsActive())
583  // return;
584 
585  m_materialDirty = true;
586 
587  UpdateMaterial();
588 
589  if (m_OnDirtyMaterialCallback != null)
590  m_OnDirtyMaterialCallback();
591 
592  //TMP_ITextElementUpdateManager.RegisterTextElementForGraphicRebuild(this);
593 
594  //TMP_UpdateRegistry.RegisterCanvasElementForGraphicRebuild((ICanvasElement)this);
595  //m_TextComponent.SetMaterialDirty();
596  }
597 
598 
602  public void SetPivotDirty()
603  {
604  if (!this.IsActive())
605  return;
606 
607  this.rectTransform.pivot = m_TextComponent.rectTransform.pivot;
608  }
609 
610 
616  public override void Cull(Rect clipRect, bool validRect)
617  {
618  if (m_TextComponent.ignoreRectMaskCulling) return;
619 
620  base.Cull(clipRect, validRect);
621  }
622 
623 
627  protected override void UpdateGeometry()
628  {
629  // Need to override to prevent Unity from changing the geometry of the object.
630  Debug.Log("UpdateGeometry()");
631  }
632 
633 
638  public override void Rebuild(CanvasUpdate update)
639  {
640  if (update == CanvasUpdate.PreRender)
641  {
642  if (!m_materialDirty) return;
643 
644  UpdateMaterial();
645  m_materialDirty = false;
646  }
647  }
648 
649 
653  public void RefreshMaterial()
654  {
655  UpdateMaterial();
656  }
657 
658 
662  protected override void UpdateMaterial()
663  {
664  //Debug.Log("*** STO-UI - UpdateMaterial() *** FRAME (" + Time.frameCount + ")");
665 
666  //if (!this.IsActive())
667  // return;
668 
669  if (m_canvasRenderer == null) m_canvasRenderer = this.canvasRenderer;
670 
671  m_canvasRenderer.materialCount = 1;
672  m_canvasRenderer.SetMaterial(materialForRendering, 0);
673  m_canvasRenderer.SetTexture(mainTexture);
674 
675  #if UNITY_EDITOR
676  if (m_sharedMaterial != null && gameObject.name != "TMP SubMeshUI [" + m_sharedMaterial.name + "]")
677  gameObject.name = "TMP SubMeshUI [" + m_sharedMaterial.name + "]";
678  #endif
679  }
680 
681 
682  // IClippable implementation
686  public override void RecalculateClipping()
687  {
688  //Debug.Log("*** RecalculateClipping() ***");
689  base.RecalculateClipping();
690  }
691 
692 
696  public override void RecalculateMasking()
697  {
698  //Debug.Log("RecalculateMasking()");
699 
700  this.m_ShouldRecalculateStencil = true;
702  }
703 
704 
705 
710  Material GetMaterial()
711  {
712  // Make sure we have a valid reference to the renderer.
713  //if (m_renderer == null) m_renderer = GetComponent<Renderer>();
714 
715  //if (m_material == null || m_isNewSharedMaterial)
716  //{
717  // m_renderer.material = m_sharedMaterial;
718  // m_material = m_renderer.material;
719  // m_sharedMaterial = m_material;
720  // m_padding = ShaderUtilities.GetPadding(m_sharedMaterial, m_TextMeshPro.extraPadding, false);
721  // m_isNewSharedMaterial = false;
722  //}
723 
724  return m_sharedMaterial;
725  }
726 
727 
728  // Function called internally when a new material is assigned via the fontMaterial property.
729  Material GetMaterial(Material mat)
730  {
731  // Check in case Object is disabled. If so, we don't have a valid reference to the Renderer.
732  // This can occur when the Duplicate Material Context menu is used on an inactive object.
733  //if (m_renderer == null)
734  // m_renderer = GetComponent<Renderer>();
735 
736  // Create Instance Material only if the new material is not the same instance previously used.
737  if (m_material == null || m_material.GetInstanceID() != mat.GetInstanceID())
738  m_material = CreateMaterialInstance(mat);
739 
740  m_sharedMaterial = m_material;
741 
742  // Compute and Set new padding values for this new material.
743  m_padding = GetPaddingForMaterial();
744 
747 
748  return m_sharedMaterial;
749  }
750 
751 
757  Material CreateMaterialInstance(Material source)
758  {
759  Material mat = new Material(source);
760  mat.shaderKeywords = source.shaderKeywords;
761  mat.name += " (Instance)";
762 
763  return mat;
764  }
765 
766 
771  Material GetSharedMaterial()
772  {
773  if (m_canvasRenderer == null)
774  m_canvasRenderer = GetComponent<CanvasRenderer>();
775 
776  return m_canvasRenderer.GetMaterial();
777  }
778 
779 
784  void SetSharedMaterial(Material mat)
785  {
786  //Debug.Log("*** SetSharedMaterial UI() *** FRAME (" + Time.frameCount + ")");
787 
788  // Assign new material.
789  m_sharedMaterial = mat;
790  m_Material = m_sharedMaterial;
791 
792  //m_isDefaultMaterial = false;
793  //if (mat.GetInstanceID() == m_fontAsset.material.GetInstanceID())
794  // m_isDefaultMaterial = true;
795 
796  // Compute and Set new padding values for this new material.
797  m_padding = GetPaddingForMaterial();
798 
799  //SetVerticesDirty();
801 
802 #if UNITY_EDITOR
803  //if (m_sharedMaterial != null)
804  // gameObject.name = "TMP SubMesh [" + m_sharedMaterial.name + "]";
805 #endif
806  }
807  }
808 }
override Texture mainTexture
float padding
Padding value resulting for the property settings on the material.
override void UpdateMaterial()
void UpdateMeshPadding(bool isExtraPadding, bool isUsingBold)
override void SetLayoutDirty()
override Material materialForRendering
Get the material that will be used for rendering.
override void RecalculateClipping()
Method called when the state of a parent changes.
override void Cull(Rect clipRect, bool validRect)
Override to Cull function of MaskableGraphic to prevent Culling.
override void OnEnable()
void RefreshMaterial()
Function to update the material from the parent text object.
void SetSharedMaterial(Material mat)
Method to set the shared material.
override void RecalculateMasking()
float GetPaddingForMaterial()
Function called when the padding value for the material needs to be re-calculated.
Class for handling and scheduling text object updates.
Material CreateMaterialInstance(Material source)
Method used to create an instance of the material
static void UnRegisterCanvasElementForRebuild(ICanvasElement element)
Function to unregister elements which no longer require a rebuild.
Mesh mesh
The Mesh of this text sub object.
override void Rebuild(CanvasUpdate update)
new Transform transform
Returns are reference to the Transform
Definition: TMP_Text.cs:1048
override Material GetModifiedMaterial(Material baseMaterial)
Function returning the modified material for masking if necessary.
override void SetVerticesDirty()
new RectTransform rectTransform
Returns are reference to the RectTransform
Definition: TMP_Text.cs:1063
bool havePropertiesChanged
Property tracking if any of the text properties have changed. Flag is set before the text is regenera...
Definition: TMP_Text.cs:1024
override void UpdateGeometry()
Material GetSharedMaterial()
Method returning the shared material assigned to the text object.
TMP_FontAsset fontAsset
The TMP Font Asset assigned to this sub text object.
override Material material
The material to be assigned to this object. Returns an instance of the material.
Material fallbackSourceMaterial
The source material used by the fallback font
static TMP_SubMeshUI AddSubTextObject(TextMeshProUGUI textComponent, MaterialReference materialReference)
Function to add a new sub text object.
Material GetMaterial()
Method which returns an instance of the shared material
bool isDefaultMaterial
Is the text object using the default font asset material.
bool isUsingBold
Property used in conjunction with padding calculation for the geometry.
Definition: TMP_Text.cs:499
bool extraPadding
Adds extra padding around each character. This may be necessary when the displayed text is very small...
Definition: TMP_Text.cs:761
TMP_SpriteAsset spriteAsset
The TMP Sprite Asset assigned to this sub text object.
new CanvasRenderer canvasRenderer
The Mesh Renderer of this text sub object.
override void OnTransformParentChanged()
override void SetMaterialDirty()
Material sharedMaterial
The material to be assigned to this text object.
override void SetAllDirty()
float GetPaddingForMaterial(Material mat)
Function called when the padding value for the material needs to be re-calculated.
bool ignoreRectMaskCulling
Controls whether or not the text object will be culled when using a 2D Rect Mask.
Definition: TMP_Text.cs:833
Material fallbackMaterial