/// <summary> /// Constructor for new sprite character. /// </summary> /// <param name="unicode">Unicode value of the sprite character.</param> /// <param name="glyph">Glyph used by the sprite character.</param> public SpriteCharacter(uint unicode, SpriteGlyph glyph) { m_ElementType = TextElementType.Sprite; this.unicode = unicode; this.glyphIndex = glyph.index; this.glyph = glyph; this.scale = 1.0f; }
/// <summary> /// Create a material for the sprite asset. /// </summary> /// <returns></returns> /*Material GetDefaultSpriteMaterial() * { * //isEditingAsset = true; * TextShaderUtilities.GetShaderPropertyIDs(); * * // Add a new material * Shader shader = Shader.Find("TextMeshPro/Sprite"); * Material tempMaterial = new Material(shader); * tempMaterial.SetTexture(TextShaderUtilities.ID_MainTex, spriteSheet); * tempMaterial.hideFlags = HideFlags.HideInHierarchy; * #if UNITY_EDITOR * UnityEditor.AssetDatabase.AddObjectToAsset(tempMaterial, this); * UnityEditor.AssetDatabase.ImportAsset(UnityEditor.AssetDatabase.GetAssetPath(this)); #endif * //isEditingAsset = false; * * return tempMaterial; * }*/ /// <summary> /// Function to update the sprite name and unicode lookup tables. /// This function should be called when a sprite's name or unicode value changes or when a new sprite is added. /// </summary> public void UpdateLookupTables() { //Debug.Log("Updating [" + this.name + "] Lookup tables."); // Initialize / Clear glyph index lookup dictionary. if (m_GlyphIndexLookup == null) { m_GlyphIndexLookup = new Dictionary <uint, int>(); } else { m_GlyphIndexLookup.Clear(); } // if (m_SpriteGlyphLookup == null) { m_SpriteGlyphLookup = new Dictionary <uint, SpriteGlyph>(); } else { m_SpriteGlyphLookup.Clear(); } // Initialize SpriteGlyphLookup for (int i = 0; i < m_SpriteGlyphTable.Count; i++) { SpriteGlyph spriteGlyph = m_SpriteGlyphTable[i]; uint glyphIndex = spriteGlyph.index; if (m_GlyphIndexLookup.ContainsKey(glyphIndex) == false) { m_GlyphIndexLookup.Add(glyphIndex, i); } if (m_SpriteGlyphLookup.ContainsKey(glyphIndex) == false) { m_SpriteGlyphLookup.Add(glyphIndex, spriteGlyph); } } // Initialize name lookup if (m_NameLookup == null) { m_NameLookup = new Dictionary <int, int>(); } else { m_NameLookup.Clear(); } // Initialize character lookup if (m_SpriteCharacterLookup == null) { m_SpriteCharacterLookup = new Dictionary <uint, SpriteCharacter>(); } else { m_SpriteCharacterLookup.Clear(); } // Populate Sprite Character lookup tables for (int i = 0; i < m_SpriteCharacterTable.Count; i++) { SpriteCharacter spriteCharacter = m_SpriteCharacterTable[i]; // Make sure sprite character is valid if (spriteCharacter == null) { continue; } uint glyphIndex = spriteCharacter.glyphIndex; // Lookup the glyph for this character if (m_SpriteGlyphLookup.ContainsKey(glyphIndex) == false) { continue; } // Assign glyph and text asset to this character spriteCharacter.glyph = m_SpriteGlyphLookup[glyphIndex]; spriteCharacter.textAsset = this; int nameHashCode = TextUtilities.GetHashCodeCaseInSensitive(m_SpriteCharacterTable[i].name); if (m_NameLookup.ContainsKey(nameHashCode) == false) { m_NameLookup.Add(nameHashCode, i); } uint unicode = m_SpriteCharacterTable[i].unicode; if (unicode != 0xFFFE && m_SpriteCharacterLookup.ContainsKey(unicode) == false) { m_SpriteCharacterLookup.Add(unicode, spriteCharacter); } } m_IsSpriteAssetLookupTablesDirty = false; }