示例#1
0
        /// <summary>
        /// Search through the given sprite asset and its fallbacks for the specified sprite matching the given unicode character.
        /// </summary>
        /// <param name="spriteAsset">The font asset to search for the given character.</param>
        /// <param name="unicode">The character to find.</param>
        /// <param name="glyph">out parameter containing the glyph for the specified character (if found).</param>
        /// <returns></returns>
        public static TMP_SpriteAsset SearchFallbackForSprite(TMP_SpriteAsset spriteAsset, int unicode, out int spriteIndex)
        {
            spriteIndex = -1;
            if (spriteAsset == null)
            {
                return(null);
            }

            spriteIndex = spriteAsset.GetSpriteIndexFromUnicode(unicode);
            if (spriteIndex != -1)
            {
                return(spriteAsset);
            }
            else if (spriteAsset.fallbackSpriteAssets != null && spriteAsset.fallbackSpriteAssets.Count > 0)
            {
                for (int i = 0; i < spriteAsset.fallbackSpriteAssets.Count && spriteIndex == -1; i++)
                {
                    TMP_SpriteAsset temp = SearchFallbackForSprite(spriteAsset.fallbackSpriteAssets[i], unicode, out spriteIndex);

                    if (temp != null)
                    {
                        return(temp);
                    }
                }
            }
            return(null);
        }
 public static TMP_SpriteAsset SearchFallbackForSprite(TMP_SpriteAsset spriteAsset, int unicode, out int spriteIndex)
 {
     spriteIndex = -1;
     if (spriteAsset == null)
     {
         return(null);
     }
     spriteIndex = spriteAsset.GetSpriteIndexFromUnicode(unicode);
     if (spriteIndex != -1)
     {
         return(spriteAsset);
     }
     if (spriteAsset.fallbackSpriteAssets != null && spriteAsset.fallbackSpriteAssets.Count > 0)
     {
         int num = 0;
         while (num < spriteAsset.fallbackSpriteAssets.Count && spriteIndex == -1)
         {
             TMP_SpriteAsset tmp_SpriteAsset = TMP_SpriteAsset.SearchFallbackForSprite(spriteAsset.fallbackSpriteAssets[num], unicode, out spriteIndex);
             if (tmp_SpriteAsset != null)
             {
                 return(tmp_SpriteAsset);
             }
             num++;
         }
     }
     return(null);
 }
示例#3
0
        /// <summary>
        /// Search the given sprite asset and fallbacks for a sprite whose unicode value matches the target unicode.
        /// </summary>
        /// <param name="spriteAsset"></param>
        /// <param name="unicode"></param>
        /// <param name="includeFallbacks"></param>
        /// <param name="spriteIndex"></param>
        /// <returns></returns>
        private static TMP_SpriteAsset SearchForSpriteByUnicodeInternal(TMP_SpriteAsset spriteAsset, int unicode, bool includeFallbacks, out int spriteIndex)
        {
            // Get sprite index for the given unicode
            spriteIndex = spriteAsset.GetSpriteIndexFromUnicode(unicode);
            if (spriteIndex != -1)
            {
                return(spriteAsset);
            }

            if (includeFallbacks && spriteAsset.fallbackSpriteAssets != null && spriteAsset.fallbackSpriteAssets.Count > 0)
            {
                return(SearchForSpriteByUnicodeInternal(spriteAsset.fallbackSpriteAssets, unicode, includeFallbacks, out spriteIndex));
            }

            spriteIndex = -1;
            return(null);
        }
示例#4
0
        /// <summary>
        /// Search through the given sprite asset and its fallbacks for the specified sprite matching the given unicode character.
        /// </summary>
        /// <param name="spriteAsset">The font asset to search for the given character.</param>
        /// <param name="unicode">The character to find.</param>
        /// <param name="glyph">out parameter containing the glyph for the specified character (if found).</param>
        /// <returns></returns>
        public static TMP_SpriteAsset SearchForSpriteByUnicode(TMP_SpriteAsset spriteAsset, uint unicode, bool includeFallbacks, out int spriteIndex)
        {
            // Check to make sure sprite asset is not null
            if (spriteAsset == null)
            {
                spriteIndex = -1; return(null);
            }

            // Get sprite index for the given unicode
            spriteIndex = spriteAsset.GetSpriteIndexFromUnicode(unicode);
            if (spriteIndex != -1)
            {
                return(spriteAsset);
            }

            // Initialize list to track instance of Sprite Assets that have already been searched.
            if (k_searchedSpriteAssets == null)
            {
                k_searchedSpriteAssets = new HashSet <int>();
            }
            else
            {
                k_searchedSpriteAssets.Clear();
            }

            // Get instance ID of sprite asset and add to list.
            int id = spriteAsset.GetInstanceID();

            k_searchedSpriteAssets.Add(id);

            // Search potential fallback sprite assets if includeFallbacks is true.
            if (includeFallbacks && spriteAsset.fallbackSpriteAssets != null && spriteAsset.fallbackSpriteAssets.Count > 0)
            {
                return(SearchForSpriteByUnicodeInternal(spriteAsset.fallbackSpriteAssets, unicode, true, out spriteIndex));
            }

            // Search default sprite asset potentially assigned in the TMP Settings.
            if (includeFallbacks && TMP_Settings.defaultSpriteAsset != null)
            {
                return(SearchForSpriteByUnicodeInternal(TMP_Settings.defaultSpriteAsset, unicode, true, out spriteIndex));
            }

            spriteIndex = -1;
            return(null);
        }
示例#5
0
        /// <summary>
        /// Search the given sprite asset and fallbacks for a sprite whose hash code value of its name matches the target hash code.
        /// </summary>
        /// <param name="spriteAsset">The Sprite Asset to search for the given sprite whose name matches the hashcode value</param>
        /// <param name="hashCode">The hash code value matching the name of the sprite</param>
        /// <param name="includeFallbacks">Include fallback sprite assets in the search</param>
        /// <param name="spriteIndex">The index of the sprite matching the provided hash code</param>
        /// <returns>The Sprite Asset that contains the sprite</returns>
        public static TMP_SpriteAsset SearchForSpriteByHashCode(TMP_SpriteAsset spriteAsset, int hashCode, bool includeFallbacks, out int spriteIndex)
        {
            // Make sure sprite asset is not null
            if (spriteAsset == null)
            {
                spriteIndex = -1; return(null);
            }

            spriteIndex = spriteAsset.GetSpriteIndexFromHashcode(hashCode);
            if (spriteIndex != -1)
            {
                return(spriteAsset);
            }

            // Initialize or clear list to Sprite Assets that have already been searched.
            if (k_searchedSpriteAssets == null)
            {
                k_searchedSpriteAssets = new HashSet <int>();
            }
            else
            {
                k_searchedSpriteAssets.Clear();
            }

            int id = spriteAsset.instanceID;

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

            TMP_SpriteAsset tempSpriteAsset;

            // Search potential fallbacks assigned to local sprite asset.
            if (includeFallbacks && spriteAsset.fallbackSpriteAssets != null && spriteAsset.fallbackSpriteAssets.Count > 0)
            {
                tempSpriteAsset = SearchForSpriteByHashCodeInternal(spriteAsset.fallbackSpriteAssets, hashCode, true, out spriteIndex);

                if (spriteIndex != -1)
                {
                    return(tempSpriteAsset);
                }
            }

            // Search default sprite asset potentially assigned in the TMP Settings.
            if (includeFallbacks && TMP_Settings.defaultSpriteAsset != null)
            {
                tempSpriteAsset = SearchForSpriteByHashCodeInternal(TMP_Settings.defaultSpriteAsset, hashCode, true, out spriteIndex);

                if (spriteIndex != -1)
                {
                    return(tempSpriteAsset);
                }
            }

            // Clear search list since we are now looking for the missing sprite character.
            k_searchedSpriteAssets.Clear();

            uint missingSpriteCharacterUnicode = TMP_Settings.missingCharacterSpriteUnicode;

            // Get sprite index for the given unicode
            spriteIndex = spriteAsset.GetSpriteIndexFromUnicode(missingSpriteCharacterUnicode);
            if (spriteIndex != -1)
            {
                return(spriteAsset);
            }

            // Add current sprite asset to list of assets already searched.
            k_searchedSpriteAssets.Add(id);

            // Search for the missing sprite character in the local sprite asset and potential fallbacks.
            if (includeFallbacks && spriteAsset.fallbackSpriteAssets != null && spriteAsset.fallbackSpriteAssets.Count > 0)
            {
                tempSpriteAsset = SearchForSpriteByUnicodeInternal(spriteAsset.fallbackSpriteAssets, missingSpriteCharacterUnicode, true, out spriteIndex);

                if (spriteIndex != -1)
                {
                    return(tempSpriteAsset);
                }
            }

            // Search for the missing sprite character in the default sprite asset and potential fallbacks.
            if (includeFallbacks && TMP_Settings.defaultSpriteAsset != null)
            {
                tempSpriteAsset = SearchForSpriteByUnicodeInternal(TMP_Settings.defaultSpriteAsset, missingSpriteCharacterUnicode, true, out spriteIndex);
                if (spriteIndex != -1)
                {
                    return(tempSpriteAsset);
                }
            }

            spriteIndex = -1;
            return(null);
        }