2 using System.Collections;
3 using System.Collections.Generic;
14 private Dictionary<int, Material> m_FontMaterialReferenceLookup =
new Dictionary<int, Material>();
15 private Dictionary<int, TMP_FontAsset> m_FontAssetReferenceLookup =
new Dictionary<int, TMP_FontAsset>();
16 private Dictionary<int, TMP_SpriteAsset> m_SpriteAssetReferenceLookup =
new Dictionary<int, TMP_SpriteAsset>();
17 private Dictionary<int, TMP_ColorGradient> m_ColorGradientReferenceLookup =
new Dictionary<int, TMP_ColorGradient>();
50 if (m_FontAssetReferenceLookup.ContainsKey(fontAsset.
hashCode))
return;
53 m_FontAssetReferenceLookup.Add(fontAsset.
hashCode, fontAsset);
78 if (m_SpriteAssetReferenceLookup.ContainsKey(spriteAsset.
hashCode))
return;
81 m_SpriteAssetReferenceLookup.Add(spriteAsset.
hashCode, spriteAsset);
84 m_FontMaterialReferenceLookup.Add(spriteAsset.
hashCode, spriteAsset.
material);
104 if (m_SpriteAssetReferenceLookup.ContainsKey(hashCode))
return;
107 m_SpriteAssetReferenceLookup.Add(hashCode, spriteAsset);
110 m_FontMaterialReferenceLookup.Add(hashCode, spriteAsset.
material);
136 m_FontMaterialReferenceLookup.Add(hashCode, material);
157 if (m_ColorGradientReferenceLookup.ContainsKey(hashCode))
return;
160 m_ColorGradientReferenceLookup.Add(hashCode, spriteAsset);
249 if (m_FontAssetReferenceLookup.ContainsKey(font.
hashCode))
263 if (m_FontAssetReferenceLookup.ContainsKey(sprite.
hashCode))
292 if (m_FontAssetReferenceLookup.TryGetValue(hashCode, out fontAsset))
323 if (m_SpriteAssetReferenceLookup.TryGetValue(hashCode, out spriteAsset))
351 gradientPreset =
null;
353 if (m_ColorGradientReferenceLookup.TryGetValue(hashCode, out gradientPreset))
383 if (m_FontMaterialReferenceLookup.TryGetValue(hashCode, out material))
523 public Material material;
524 public bool isDefaultMaterial;
525 public bool isFallbackMaterial;
526 public Material fallbackMaterial;
527 public float padding;
528 public int referenceCount;
542 this.fontAsset = fontAsset;
543 this.spriteAsset = spriteAsset;
544 this.material = material;
545 this.isDefaultMaterial = material.GetInstanceID() == fontAsset.
material.GetInstanceID() ? true :
false;
546 this.isFallbackMaterial =
false;
547 this.fallbackMaterial =
null;
548 this.padding = padding;
549 this.referenceCount = 0;
561 int id = fontAsset.GetInstanceID();
563 for (
int i = 0; i < materialReferences.Length && materialReferences[i].fontAsset !=
null; i++)
565 if (materialReferences[i].fontAsset.GetInstanceID() == id)
583 int materialID = material.GetInstanceID();
586 if (materialReferenceIndexLookup.TryGetValue(materialID, out index))
592 index = materialReferenceIndexLookup.Count;
595 materialReferenceIndexLookup[materialID] = index;
597 materialReferences[index].index = index;
598 materialReferences[index].fontAsset = fontAsset;
599 materialReferences[index].spriteAsset =
null;
600 materialReferences[index].material = material;
601 materialReferences[index].isDefaultMaterial = materialID == fontAsset.
material.GetInstanceID() ? true :
false;
603 materialReferences[index].referenceCount = 0;
620 int materialID = material.GetInstanceID();
623 if (materialReferenceIndexLookup.TryGetValue(materialID, out index))
629 index = materialReferenceIndexLookup.Count;
632 materialReferenceIndexLookup[materialID] = index;
634 materialReferences[index].index = index;
635 materialReferences[index].fontAsset = materialReferences[0].fontAsset;
636 materialReferences[index].spriteAsset = spriteAsset;
637 materialReferences[index].material = material;
638 materialReferences[index].isDefaultMaterial =
true;
640 materialReferences[index].referenceCount = 0;
int hashCode
HashCode based on the name of the asset.
static void AddSpriteAsset(int hashCode, TMP_SpriteAsset spriteAsset)
Add new Sprite Asset to dictionary.
void AddColorGradientPreset_Internal(int hashCode, TMP_ColorGradient spriteAsset)
Internal method to add a new Color Gradient Preset to the dictionary.
bool TryGetFontAssetInternal(int hashCode, out TMP_FontAsset fontAsset)
Internal Function returning the Font Asset corresponding to the provided hash code.
bool TryGetMaterialInternal(int hashCode, out Material material)
Internal function returning the Font Material corresponding to the provided hash code.
bool TryGetColorGradientPresetInternal(int hashCode, out TMP_ColorGradient gradientPreset)
Internal function returning the Color Gradient Preset corresponding to the provided hash code.
bool Contains(TMP_SpriteAsset sprite)
Function to check if the sprite asset is already referenced.
bool Contains(TMP_FontAsset font)
Add new material reference and return the index of this new reference in the materialReferences array...
void AddSpriteAssetInternal(int hashCode, TMP_SpriteAsset spriteAsset)
Internal method to add a new sprite asset to the dictionary.
MaterialReference(int index, TMP_FontAsset fontAsset, TMP_SpriteAsset spriteAsset, Material material, float padding)
Constructor for new Material Reference.
static bool Contains(MaterialReference[] materialReferences, TMP_FontAsset fontAsset)
Function to check if a certain font asset is contained in the material reference array.
bool TryGetSpriteAssetInternal(int hashCode, out TMP_SpriteAsset spriteAsset)
Internal function returning the Sprite Asset corresponding to the provided hash code.
void AddFontAssetInternal(TMP_FontAsset fontAsset)
Add new Font Asset reference to dictionary.
static bool TryGetColorGradientPreset(int hashCode, out TMP_ColorGradient gradientPreset)
Function returning the Color Gradient Preset corresponding to the provided hash code.
static int AddMaterialReference(Material material, TMP_FontAsset fontAsset, MaterialReference[] materialReferences, Dictionary< int, int > materialReferenceIndexLookup)
Function to add a new material reference and returning its index in the material reference array.
int materialHashCode
HashCode based on the name of the material assigned to this asset.
static void AddColorGradientPreset(int hashCode, TMP_ColorGradient spriteAsset)
Add new Color Gradient Preset to dictionary.
Material material
The material used by this asset.
static int AddMaterialReference(Material material, TMP_SpriteAsset spriteAsset, MaterialReference[] materialReferences, Dictionary< int, int > materialReferenceIndexLookup)
static void AddSpriteAsset(TMP_SpriteAsset spriteAsset)
Add new Sprite Asset to dictionary.
static void AddFontMaterial(int hashCode, Material material)
Add new Material reference to dictionary.
static void AddFontAsset(TMP_FontAsset fontAsset)
Add new font asset reference to dictionary.
static bool TryGetMaterial(int hashCode, out Material material)
Function returning the Font Material corresponding to the provided hash code.
void AddSpriteAssetInternal(TMP_SpriteAsset spriteAsset)
Internal method to add a new sprite asset to the dictionary.
static bool TryGetSpriteAsset(int hashCode, out TMP_SpriteAsset spriteAsset)
Function returning the Sprite Asset corresponding to the provided hash code.
static bool TryGetFontAsset(int hashCode, out TMP_FontAsset fontAsset)
Function returning the Font Asset corresponding to the provided hash code.
static MaterialReferenceManager instance
Get a singleton instance of the registry
void AddFontMaterialInternal(int hashCode, Material material)
Add new material reference to dictionary.