Class MaterialReferenceManager
Inherited Members
Namespace: TMPro
Assembly: Unity.TextMeshPro.dll
Syntax
public class MaterialReferenceManager
Properties
instance
Get a singleton instance of the registry
Declaration
public static MaterialReferenceManager instance { get; }
Property Value
| Type | Description |
|---|---|
| MaterialReferenceManager |
Methods
AddColorGradientPreset(int, TMP_ColorGradient)
Add new Color Gradient Preset to dictionary.
Declaration
public static void AddColorGradientPreset(int hashCode, TMP_ColorGradient colorGradient)
Parameters
| Type | Name | Description |
|---|---|---|
| int | hashCode | The hash code used to look up the gradient preset. |
| TMP_ColorGradient | colorGradient | The color gradient preset to register with the manager. |
Remarks
Registers a color gradient preset by hash code so it can be referenced in rich text (e.g. <gradient> tags). Duplicate hash codes are ignored. Call when loading or creating gradient presets at runtime.
Examples
Register a gradient preset so it can be used in text. Use a stable hashCode (e.g. from the preset name or asset) for lookups.
int gradientHash = myGradientAsset.GetHashCode();
MaterialReferenceManager.AddColorGradientPreset(gradientHash, myGradientAsset);
AddFontAsset(TMP_FontAsset)
Add new font asset reference to dictionary.
Declaration
public static void AddFontAsset(TMP_FontAsset fontAsset)
Parameters
| Type | Name | Description |
|---|---|---|
| TMP_FontAsset | fontAsset | The font asset to register with the manager. |
Remarks
Registers the font asset and its material with the singleton so TextMesh Pro can reuse them across text objects. Duplicate hash codes are ignored. Call when loading or creating font assets at runtime.
Examples
Register a font asset after loading it so it is tracked for material and mesh updates. Typically called from font asset initialization.
TMP_FontAsset myFont = Resources.Load<TMP_FontAsset>("MyFont");
MaterialReferenceManager.AddFontAsset(myFont);
AddFontMaterial(int, Material)
Add new Material reference to dictionary.
Declaration
public static void AddFontMaterial(int hashCode, Material material)
Parameters
| Type | Name | Description |
|---|---|---|
| int | hashCode | The hash code used to look up the material. |
| Material | material | The material instance to register with the manager. |
Remarks
Registers a font material by hash code so TextMesh Pro can look it up when building meshes. Use the same hashCode as the font asset's material for correct reference counting. Duplicate hash codes overwrite the previous entry.
Examples
Register a material by hash when you need to track it separately from a font asset. Ensure the hashCode matches the material instance.
int matHash = myMaterial.GetHashCode();
MaterialReferenceManager.AddFontMaterial(matHash, myMaterial);
AddSpriteAsset(int, TMP_SpriteAsset)
Add new Sprite Asset to dictionary.
Declaration
public static void AddSpriteAsset(int hashCode, TMP_SpriteAsset spriteAsset)
Parameters
| Type | Name | Description |
|---|---|---|
| int | hashCode | The hash code to use when looking up the sprite asset. |
| TMP_SpriteAsset | spriteAsset | The sprite asset to register with the manager. |
Remarks
Registers the sprite asset under the given hash code so it can be looked up by that code. Use when the asset's default hashCode is not suitable (e.g. custom atlases). Duplicate hash codes overwrite the previous entry.
Examples
Register a sprite asset with a specific hash for custom lookup. Use the same hashCode when resolving sprites in rich text.
int customHash = GetCustomSpriteHash(mySpriteAsset);
MaterialReferenceManager.AddSpriteAsset(customHash, mySpriteAsset);
AddSpriteAsset(TMP_SpriteAsset)
Add new Sprite Asset to dictionary.
Declaration
public static void AddSpriteAsset(TMP_SpriteAsset spriteAsset)
Parameters
| Type | Name | Description |
|---|---|---|
| TMP_SpriteAsset | spriteAsset | The sprite asset to register with the manager. |
Remarks
Registers the sprite asset and its material with the singleton so inline sprites in text can resolve references. Duplicate hash codes are ignored. Call when loading or creating sprite assets at runtime.
Examples
Register a sprite asset so it can be used in rich text (e.g. sprite tags). Typically called when the asset is loaded or created.
TMP_SpriteAsset emojiAsset = Resources.Load<TMP_SpriteAsset>("EmojiSprites");
MaterialReferenceManager.AddSpriteAsset(emojiAsset);
Contains(TMP_FontAsset)
Checks whether the font asset is referenced.
Declaration
public bool Contains(TMP_FontAsset font)
Parameters
| Type | Name | Description |
|---|---|---|
| TMP_FontAsset | font | The font asset to check for in the manager. |
Returns
| Type | Description |
|---|---|
| bool | True if the font asset is already registered in the manager. |
Contains(TMP_SpriteAsset)
Checks whether the sprite asset is referenced.
Declaration
public bool Contains(TMP_SpriteAsset sprite)
Parameters
| Type | Name | Description |
|---|---|---|
| TMP_SpriteAsset | sprite | The sprite asset to check for in the manager. |
Returns
| Type | Description |
|---|---|
| bool | True if the sprite asset is already registered in the manager. |
TryGetColorGradientPreset(int, out TMP_ColorGradient)
Gets the color gradient preset for the given hash code, if registered.
Declaration
public static bool TryGetColorGradientPreset(int hashCode, out TMP_ColorGradient gradientPreset)
Parameters
| Type | Name | Description |
|---|---|---|
| int | hashCode | The hash code of the gradient preset to look up. |
| TMP_ColorGradient | gradientPreset | The gradient preset if found, or null otherwise. |
Returns
| Type | Description |
|---|---|
| bool | True if the gradient preset was found; otherwise, false. |
TryGetFontAsset(int, out TMP_FontAsset)
Gets the font asset for the given hash code, if registered.
Declaration
public static bool TryGetFontAsset(int hashCode, out TMP_FontAsset fontAsset)
Parameters
| Type | Name | Description |
|---|---|---|
| int | hashCode | The hash code of the font asset to look up. |
| TMP_FontAsset | fontAsset | The font asset if found, or null otherwise. |
Returns
| Type | Description |
|---|---|
| bool | True if the font asset was found; otherwise, false. |
TryGetMaterial(int, out Material)
Gets the font material for the given hash code, if registered.
Declaration
public static bool TryGetMaterial(int hashCode, out Material material)
Parameters
| Type | Name | Description |
|---|---|---|
| int | hashCode | The hash code of the material to look up. |
| Material | material | The material if found, or null otherwise. |
Returns
| Type | Description |
|---|---|
| bool | True if the material was found; otherwise, false. |
TryGetSpriteAsset(int, out TMP_SpriteAsset)
Gets the sprite asset for the given hash code, if registered.
Declaration
public static bool TryGetSpriteAsset(int hashCode, out TMP_SpriteAsset spriteAsset)
Parameters
| Type | Name | Description |
|---|---|---|
| int | hashCode | The hash code of the sprite asset to look up. |
| TMP_SpriteAsset | spriteAsset | The sprite asset if found, or null otherwise. |
Returns
| Type | Description |
|---|---|
| bool | True if the sprite asset was found; otherwise, false. |