2 using System.Collections.Generic;
10 internal Dictionary<int, int> m_UnicodeLookup;
11 internal Dictionary<int, int> m_NameLookup;
20 if (m_defaultSpriteAsset ==
null)
22 m_defaultSpriteAsset = Resources.Load<
TMP_SpriteAsset>(
"Sprite Assets/Default Sprite Asset");
25 return m_defaultSpriteAsset;
32 public Texture spriteSheet;
35 public List<TMP_Sprite> spriteInfoList;
68 TMPro_EventManager.ON_SPRITE_ASSET_PROPERTY_CHANGED(
true,
this);
80 ShaderUtilities.GetShaderPropertyIDs();
83 Shader shader = Shader.Find(
"TextMeshPro/Sprite");
84 Material tempMaterial =
new Material(shader);
85 tempMaterial.SetTexture(ShaderUtilities.ID_MainTex, spriteSheet);
86 tempMaterial.hideFlags = HideFlags.HideInHierarchy;
89 UnityEditor.AssetDatabase.AddObjectToAsset(tempMaterial,
this);
104 if (m_NameLookup ==
null) m_NameLookup =
new Dictionary<int, int>();
105 m_NameLookup.Clear();
107 if (m_UnicodeLookup ==
null) m_UnicodeLookup =
new Dictionary<int, int>();
108 m_UnicodeLookup.Clear();
110 for (
int i = 0; i < spriteInfoList.Count; i++)
112 int nameHashCode = spriteInfoList[i].hashCode;
114 if (m_NameLookup.ContainsKey(nameHashCode) ==
false)
115 m_NameLookup.Add(nameHashCode, i);
117 int unicode = spriteInfoList[i].unicode;
119 if (m_UnicodeLookup.ContainsKey(unicode) ==
false)
120 m_UnicodeLookup.Add(unicode, i);
132 if (m_NameLookup ==
null)
136 if (m_NameLookup.TryGetValue(
hashCode, out index))
150 if (m_UnicodeLookup ==
null)
154 if (m_UnicodeLookup.TryGetValue(unicode, out index))
168 if (m_NameLookup ==
null)
171 int hashCode = TMP_TextUtilities.GetSimpleHashCode(name);
192 if (spriteAsset ==
null) { spriteIndex = -1;
return null; }
196 if (spriteIndex != -1)
206 int id = spriteAsset.GetInstanceID();
232 for (
int i = 0; i < spriteAssets.Count; i++)
235 if (temp ==
null)
continue;
237 int id = temp.GetInstanceID();
268 if (spriteIndex != -1)
290 if (spriteAsset ==
null) { spriteIndex = -1;
return null; }
293 if (spriteIndex != -1)
302 int id = spriteAsset.GetInstanceID();
329 for (
int i = 0; i < spriteAssets.Count; i++)
332 if (temp ==
null)
continue;
334 int id = temp.GetInstanceID();
365 if (spriteIndex != -1)
int hashCode
HashCode based on the name of the asset.
static TMP_SpriteAsset SearchForSpriteByHashCodeInternal(List< TMP_SpriteAsset > spriteAssets, int hashCode, bool searchFallbacks, out int spriteIndex)
Search through the given list of sprite assets and fallbacks for a sprite whose hash code value of it...
int GetSpriteIndexFromHashcode(int hashCode)
Function which returns the sprite index using the hashcode of the name
static TMP_SpriteAsset SearchForSpriteByUnicodeInternal(List< TMP_SpriteAsset > spriteAssets, int unicode, bool includeFallbacks, out int spriteIndex)
Search through the given list of sprite assets and fallbacks for a sprite whose unicode value matches...
static TMP_SpriteAsset SearchForSpriteByHashCodeInternal(TMP_SpriteAsset spriteAsset, int hashCode, bool searchFallbacks, out int spriteIndex)
Search through the given sprite asset and fallbacks for a sprite whose hash code value of its name ma...
void UpdateLookupTables()
Function to update the sprite name and unicode lookup tables. This function should be called when a s...
static TMP_SpriteAsset SearchForSpriteByUnicode(TMP_SpriteAsset spriteAsset, int unicode, bool includeFallbacks, out int spriteIndex)
Search through the given sprite asset and its fallbacks for the specified sprite matching the given u...
int GetSpriteIndexFromUnicode(int unicode)
Returns the index of the sprite for the given unicode value.
static TMP_SpriteAsset SearchForSpriteByHashCode(TMP_SpriteAsset spriteAsset, int hashCode, bool includeFallbacks, out int spriteIndex)
Search the given sprite asset and fallbacks for a sprite whose hash code value of its name matches th...
Material GetDefaultSpriteMaterial()
Create a material for the sprite asset.
static List< int > k_searchedSpriteAssets
Used to keep track of which Sprite Assets have been searched.
int GetSpriteIndexFromName(string name)
Returns the index of the sprite for the given name.
List< TMP_SpriteAsset > fallbackSpriteAssets
Dictionary used to lookup the index of a given sprite based on a Unicode value.
static TMP_SpriteAsset SearchForSpriteByUnicodeInternal(TMP_SpriteAsset spriteAsset, int unicode, bool includeFallbacks, out int spriteIndex)
Search the given sprite asset and fallbacks for a sprite whose unicode value matches the target unico...
static TMP_SpriteAsset defaultSpriteAsset
The Default Sprite Asset to be used by default.
static TMP_SpriteAsset defaultSpriteAsset
Static reference to the default font asset included with TextMesh Pro.