Exemple #1
0
 // Event received when font asset properties are changed in Font Inspector
 void ON_FONT_PROPERTY_CHANGED(bool isChanged, TMP_FontAsset font)
 {
     if (m_fontAsset != null && font.GetInstanceID() == m_fontAsset.GetInstanceID())
     {
         // Copy Normal and Bold Weight
         if (m_fallbackMaterial != null)
         {
             m_fallbackMaterial.SetFloat(ShaderUtilities.ID_WeightNormal, m_fontAsset.normalStyle);
             m_fallbackMaterial.SetFloat(ShaderUtilities.ID_WeightBold, m_fontAsset.boldStyle);
         }
     }
 }
        /// <summary>
        /// Function to check if a certain font asset is contained in the material reference array.
        /// </summary>
        /// <param name="materialReferences"></param>
        /// <param name="fontAsset"></param>
        /// <returns></returns>
        public static bool Contains(MaterialReference[] materialReferences, TMP_FontAsset fontAsset)
        {
            int id = fontAsset.GetInstanceID();

            for (int i = 0; i < materialReferences.Length && materialReferences[i].fontAsset != null; i++)
            {
                if (materialReferences[i].fontAsset.GetInstanceID() == id)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #3
0
        private static TMP_FontAsset SearchForGlyphInternal(TMP_FontAsset font, int character, out TMP_Glyph glyph)
        {
            glyph = null;

            if (font == null)
            {
                return(null);
            }

            if (font.characterDictionary.TryGetValue(character, out glyph))
            {
                return(font);
            }
            else if (font.fallbackFontAssets != null && font.fallbackFontAssets.Count > 0)
            {
                for (int i = 0; i < font.fallbackFontAssets.Count && glyph == null; i++)
                {
                    TMP_FontAsset temp = font.fallbackFontAssets[i];
                    if (temp == null)
                    {
                        continue;
                    }

                    int id = temp.GetInstanceID();

                    // Skip over the fallback font asset in the event it is null or if already searched.
                    if (k_searchedFontAssets.Contains(id))
                    {
                        continue;
                    }

                    // Add to list of font assets already searched.
                    k_searchedFontAssets.Add(id);

                    temp = SearchForGlyphInternal(temp, character, out glyph);

                    if (temp != null)
                    {
                        return(temp);
                    }
                }
            }

            return(null);
        }