Exemple #1
0
        /// <summary>
        ///  Search through the given list of sprite assets and fallbacks for a sprite whose hash code value of its name matches the target hash code.
        /// </summary>
        /// <param name="spriteAssets"></param>
        /// <param name="hashCode"></param>
        /// <param name="searchFallbacks"></param>
        /// <param name="spriteIndex"></param>
        /// <returns></returns>
        static TextSpriteAsset SearchForSpriteByHashCodeInternal(List <TextSpriteAsset> spriteAssets, int hashCode, bool searchFallbacks, out int spriteIndex)
        {
            // Search through the list of sprite assets
            for (int i = 0; i < spriteAssets.Count; i++)
            {
                TextSpriteAsset temp = spriteAssets[i];
                if (temp == null)
                {
                    continue;
                }

                int id = temp.GetInstanceID();

                // Skip over the fallback sprite asset if it has already been searched.
                if (s_SearchedSpriteAssets.Contains(id))
                {
                    continue;
                }

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

                temp = SearchForSpriteByHashCodeInternal(temp, hashCode, searchFallbacks, out spriteIndex);

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

            spriteIndex = -1;
            return(null);
        }
Exemple #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 font asset to search for the given character.</param>
        /// <param name="unicode">The character to find.</param>
        /// <param name="includeFallbacks"></param>
        /// <param name="spriteIndex"></param>
        /// <returns></returns>
        public static TextSpriteAsset SearchForSpriteByUnicode(TextSpriteAsset 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 (s_SearchedSpriteAssets == null)
            {
                s_SearchedSpriteAssets = new List <int>();
            }

            s_SearchedSpriteAssets.Clear();

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

            s_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, includeFallbacks, out spriteIndex));
            }

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

            spriteIndex = -1;
            return(null);
        }
Exemple #3
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 TextSpriteAsset SearchForSpriteByHashCode(TextSpriteAsset 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 list to track instance of Sprite Assets that have already been searched.
            if (s_SearchedSpriteAssets == null)
            {
                s_SearchedSpriteAssets = new List <int>();
            }

            s_SearchedSpriteAssets.Clear();

            int id = spriteAsset.GetInstanceID();

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

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

            // Search default sprite asset potentially assigned in the Text Settings.
            if (includeFallbacks && TextSettings.defaultSpriteAsset != null)
            {
                return(SearchForSpriteByHashCodeInternal(TextSettings.defaultSpriteAsset, hashCode, includeFallbacks, out spriteIndex));
            }

            spriteIndex = -1;
            return(null);
        }