/// <summary> /// Search through 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"></param> /// <param name="hashCode"></param> /// <param name="searchFallbacks"></param> /// <param name="spriteIndex"></param> /// <returns></returns> private static TMP_SpriteAsset SearchForSpriteByHashCodeInternal(TMP_SpriteAsset spriteAsset, int hashCode, bool searchFallbacks, out int spriteIndex) { // Get the sprite for the given hash code. spriteIndex = spriteAsset.GetSpriteIndexFromHashcode(hashCode); if (spriteIndex != -1) { return(spriteAsset); } if (searchFallbacks && spriteAsset.fallbackSpriteAssets != null && spriteAsset.fallbackSpriteAssets.Count > 0) { return(SearchForSpriteByHashCodeInternal(spriteAsset.fallbackSpriteAssets, hashCode, searchFallbacks, out spriteIndex)); } spriteIndex = -1; return(null); }
/// <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 list to track instance of Sprite Assets that have already been searched. if (k_searchedSpriteAssets == null) { k_searchedSpriteAssets = new List <int>(); } k_searchedSpriteAssets.Clear(); int id = spriteAsset.GetInstanceID(); // Add to list of font assets already searched. k_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 TMP Settings. if (includeFallbacks && TMP_Settings.defaultSpriteAsset != null) { return(SearchForSpriteByHashCodeInternal(TMP_Settings.defaultSpriteAsset, hashCode, includeFallbacks, out spriteIndex)); } spriteIndex = -1; return(null); }