예제 #1
0
        /// <summary>
        /// Search through the given list of sprite assets and fallbacks for a sprite whose unicode value matches the target unicode.
        /// </summary>
        /// <param name="spriteAssets"></param>
        /// <param name="unicode"></param>
        /// <param name="includeFallbacks"></param>
        /// <param name="spriteIndex"></param>
        /// <returns></returns>
        private static SpriteAsset SearchForSpriteByUnicodeInternal(List <SpriteAsset> spriteAssets, uint unicode, bool includeFallbacks, out int spriteIndex)
        {
            for (int i = 0; i < spriteAssets.Count; i++)
            {
                SpriteAsset temp = spriteAssets[i];
                if (temp == null)
                {
                    continue;
                }

                int id = temp.GetInstanceID();

                // Skip sprite asset if it has already been searched.
                if (k_searchedSpriteAssets.Add(id) == false)
                {
                    continue;
                }

                temp = SearchForSpriteByUnicodeInternal(temp, unicode, includeFallbacks, out spriteIndex);

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

            spriteIndex = -1;
            return(null);
        }
예제 #2
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 sprite asset asset to search for the given unicode.</param>
        /// <param name="unicode">The unicode character to find.</param>
        /// <param name="includeFallbacks">Include fallback sprite assets in the search?</param>
        /// <param name="spriteIndex">The index of the sprite in the sprite asset (if found)</param>
        /// <returns></returns>
        public static SpriteAsset SearchForSpriteByUnicode(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);
        }