public static int AddMaterialReference(Material material, TextSpriteAsset spriteAsset, MaterialReference[] materialReferences, Dictionary <int, int> materialReferenceIndexLookup) { int instanceID = material.GetInstanceID(); int count; bool flag = materialReferenceIndexLookup.TryGetValue(instanceID, out count); int result; if (flag) { result = count; } else { count = materialReferenceIndexLookup.Count; materialReferenceIndexLookup[instanceID] = count; materialReferences[count].index = count; materialReferences[count].fontAsset = materialReferences[0].fontAsset; materialReferences[count].spriteAsset = spriteAsset; materialReferences[count].material = material; materialReferences[count].isDefaultMaterial = true; materialReferences[count].referenceCount = 0; result = count; } return(result); }
/// <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); }
/// <summary> /// Function to check if the sprite asset is already referenced. /// </summary> /// <param name="sprite"></param> /// <returns></returns> public bool Contains(TextSpriteAsset sprite) { if (m_FontAssetReferenceLookup.ContainsKey(sprite.hashCode)) { return(true); } return(false); }
private void AddSpriteAssetInternal(TextSpriteAsset spriteAsset) { bool flag = this.m_SpriteAssetReferenceLookup.ContainsKey(spriteAsset.hashCode); if (!flag) { this.m_SpriteAssetReferenceLookup.Add(spriteAsset.hashCode, spriteAsset); this.m_FontMaterialReferenceLookup.Add(spriteAsset.hashCode, spriteAsset.material); } }
/// <summary> /// Internal function returning the Sprite Asset corresponding to the provided hash code. /// </summary> /// <param name="hashCode"></param> /// <param name="spriteAsset"></param> /// <returns></returns> bool TryGetSpriteAssetInternal(int hashCode, out TextSpriteAsset spriteAsset) { spriteAsset = null; if (m_SpriteAssetReferenceLookup.TryGetValue(hashCode, out spriteAsset)) { return(true); } return(false); }
public MaterialReference(int index, FontAsset fontAsset, TextSpriteAsset spriteAsset, Material material, float padding) { this.index = index; this.fontAsset = fontAsset; this.spriteAsset = spriteAsset; this.material = material; this.isDefaultMaterial = (material.GetInstanceID() == fontAsset.material.GetInstanceID()); this.isFallbackMaterial = false; this.fallbackMaterial = null; this.padding = padding; this.referenceCount = 0; }
/// <summary> /// Internal method to add a new sprite asset to the dictionary. /// </summary> /// <param name="spriteAsset"></param> void AddSpriteAssetInternal(TextSpriteAsset spriteAsset) { if (m_SpriteAssetReferenceLookup.ContainsKey(spriteAsset.hashCode)) { return; } // Add reference to sprite asset. m_SpriteAssetReferenceLookup.Add(spriteAsset.hashCode, spriteAsset); // Adding reference to the sprite asset material as well m_FontMaterialReferenceLookup.Add(spriteAsset.hashCode, spriteAsset.material); }
public void Copy(TextGenerationSettings other) { bool flag = other == null; if (!flag) { this.text = other.text; this.screenRect = other.screenRect; this.margins = other.margins; this.scale = other.scale; this.fontAsset = other.fontAsset; this.material = other.material; this.spriteAsset = other.spriteAsset; this.fontStyle = other.fontStyle; this.textAlignment = other.textAlignment; this.overflowMode = other.overflowMode; this.wordWrap = other.wordWrap; this.wordWrappingRatio = other.wordWrappingRatio; this.color = other.color; this.fontColorGradient = other.fontColorGradient; this.tintSprites = other.tintSprites; this.overrideRichTextColors = other.overrideRichTextColors; this.fontSize = other.fontSize; this.autoSize = other.autoSize; this.fontSizeMin = other.fontSizeMin; this.fontSizeMax = other.fontSizeMax; this.enableKerning = other.enableKerning; this.richText = other.richText; this.isRightToLeft = other.isRightToLeft; this.extraPadding = other.extraPadding; this.parseControlCharacters = other.parseControlCharacters; this.characterSpacing = other.characterSpacing; this.wordSpacing = other.wordSpacing; this.lineSpacing = other.lineSpacing; this.paragraphSpacing = other.paragraphSpacing; this.lineSpacingMax = other.lineSpacingMax; this.maxVisibleCharacters = other.maxVisibleCharacters; this.maxVisibleWords = other.maxVisibleWords; this.maxVisibleLines = other.maxVisibleLines; this.firstVisibleCharacter = other.firstVisibleCharacter; this.useMaxVisibleDescender = other.useMaxVisibleDescender; this.fontWeight = other.fontWeight; this.pageToDisplay = other.pageToDisplay; this.horizontalMapping = other.horizontalMapping; this.verticalMapping = other.verticalMapping; this.uvLineOffset = other.uvLineOffset; this.geometrySortingOrder = other.geometrySortingOrder; this.inverseYAxis = other.inverseYAxis; this.charWidthMaxAdj = other.charWidthMaxAdj; } }
private void AddSpriteAssetInternal(int hashCode, TextSpriteAsset spriteAsset) { bool flag = this.m_SpriteAssetReferenceLookup.ContainsKey(hashCode); if (!flag) { this.m_SpriteAssetReferenceLookup.Add(hashCode, spriteAsset); this.m_FontMaterialReferenceLookup.Add(hashCode, spriteAsset.material); bool flag2 = spriteAsset.hashCode == 0; if (flag2) { spriteAsset.hashCode = hashCode; } } }
/// <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> static TextSpriteAsset SearchForSpriteByUnicodeInternal(TextSpriteAsset spriteAsset, uint 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); }
/// <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> static TextSpriteAsset SearchForSpriteByHashCodeInternal(TextSpriteAsset 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 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); }
/// <summary> /// Internal method to add a new sprite asset to the dictionary. /// </summary> /// <param name="hashCode"></param> /// <param name="spriteAsset"></param> void AddSpriteAssetInternal(int hashCode, TextSpriteAsset spriteAsset) { if (m_SpriteAssetReferenceLookup.ContainsKey(hashCode)) { return; } // Add reference to Sprite Asset. m_SpriteAssetReferenceLookup.Add(hashCode, spriteAsset); // Add reference to Sprite Asset using the asset hashcode. m_FontMaterialReferenceLookup.Add(hashCode, spriteAsset.material); // Compatibility check if (spriteAsset.hashCode == 0) { spriteAsset.hashCode = hashCode; } }
/// <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); }
/// <summary> /// /// </summary> /// <param name="material"></param> /// <param name="spriteAsset"></param> /// <param name="materialReferences"></param> /// <param name="materialReferenceIndexLookup"></param> /// <returns></returns> public static int AddMaterialReference(Material material, TextSpriteAsset spriteAsset, MaterialReference[] materialReferences, Dictionary <int, int> materialReferenceIndexLookup) { int materialId = material.GetInstanceID(); int index; if (materialReferenceIndexLookup.TryGetValue(materialId, out index)) { return(index); } index = materialReferenceIndexLookup.Count; // Add new reference index materialReferenceIndexLookup[materialId] = index; materialReferences[index].index = index; materialReferences[index].fontAsset = materialReferences[0].fontAsset; materialReferences[index].spriteAsset = spriteAsset; materialReferences[index].material = material; materialReferences[index].isDefaultMaterial = true; materialReferences[index].referenceCount = 0; return(index); }
/// <summary> /// Add new Sprite Asset to dictionary. /// </summary> /// <param name="hashCode"></param> /// <param name="spriteAsset"></param> public static void AddSpriteAsset(int hashCode, TextSpriteAsset spriteAsset) { instance.AddSpriteAssetInternal(hashCode, spriteAsset); }
/// <summary> /// Add new Sprite Asset to dictionary. /// </summary> /// <param name="spriteAsset"></param> public static void AddSpriteAsset(TextSpriteAsset spriteAsset) { instance.AddSpriteAssetInternal(spriteAsset); }
public bool Contains(TextSpriteAsset sprite) { return(this.m_FontAssetReferenceLookup.ContainsKey(sprite.hashCode)); }
/// <summary> /// Internal function returning the Sprite Asset corresponding to the provided hash code. /// </summary> /// <param name="hashCode"></param> /// <param name="spriteAsset"></param> /// <returns></returns> bool TryGetSpriteAssetInternal(int hashCode, out TextSpriteAsset spriteAsset) { spriteAsset = null; return(m_SpriteAssetReferenceLookup.TryGetValue(hashCode, out spriteAsset)); }
/// <summary> /// Function returning the Sprite Asset corresponding to the provided hash code. /// </summary> /// <param name="hashCode"></param> /// <param name="spriteAsset"></param> /// <returns></returns> public static bool TryGetSpriteAsset(int hashCode, out TextSpriteAsset spriteAsset) { return(instance.TryGetSpriteAssetInternal(hashCode, out spriteAsset)); }
public static bool TryGetSpriteAsset(int hashCode, out TextSpriteAsset spriteAsset) { return(MaterialReferenceManager.instance.TryGetSpriteAssetInternal(hashCode, out spriteAsset)); }
public static void AddSpriteAsset(TextSpriteAsset spriteAsset) { MaterialReferenceManager.instance.AddSpriteAssetInternal(spriteAsset); }
public static void AddSpriteAsset(int hashCode, TextSpriteAsset spriteAsset) { MaterialReferenceManager.instance.AddSpriteAssetInternal(hashCode, spriteAsset); }