void Init() { Release(); mainTexture = new NTexture(_fontAsset.atlasTexture); mainTexture.destroyMethod = DestroyMethod.None; _manager = mainTexture.GetMaterialManager(this.shader); _manager.onCreateNewMaterial += OnCreateNewMaterial; _material = new Material(_fontAsset.material); //copy _material.SetFloat(ShaderUtilities.ID_TextureWidth, mainTexture.width); _material.SetFloat(ShaderUtilities.ID_TextureHeight, mainTexture.height); _material.SetFloat(ShaderUtilities.ID_GradientScale, fontAsset.atlasPadding + 1); _material.SetFloat(ShaderUtilities.ID_WeightNormal, fontAsset.normalStyle); _material.SetFloat(ShaderUtilities.ID_WeightBold, fontAsset.boldStyle); // _ascent = _fontAsset.faceInfo.ascentLine; // _lineHeight = _fontAsset.faceInfo.lineHeight; _ascent = _fontAsset.faceInfo.pointSize; _lineHeight = _fontAsset.faceInfo.pointSize * 1.25f; bool isAlternativeTypeface; TMP_FontAsset actualAsset; _lineChar = TMP_FontAssetUtilities.GetCharacterFromFontAsset('_', _fontAsset, true, FontStyles.Normal, _fontWeight, out isAlternativeTypeface, out actualAsset); }
TMP_Character GetCharacterFromFontAsset(uint unicode, FontStyles fontStyle) { bool isAlternativeTypeface; #pragma warning disable TMP_FontAsset actualAsset; #pragma warning restore return(TMP_FontAssetUtilities.GetCharacterFromFontAsset(unicode, _fontAsset, true, fontStyle, _fontWeight, out isAlternativeTypeface //,out actualAsset //old TMP version need this line )); }
override public bool GetGlyph(char ch, out float width, out float height, out float baseline) { bool isAlternativeTypeface; TMP_FontAsset actualAsset; _char = TMP_FontAssetUtilities.GetCharacterFromFontAsset(ch, _fontAsset, true, _style, _fontWeight, out isAlternativeTypeface, out actualAsset); if (_char != null) { width = _char.glyph.metrics.horizontalAdvance * _boldMultiplier * _scale; height = _lineHeight * _scale; baseline = _ascent * _scale; if (_format.specialStyle == TextFormat.SpecialStyle.Subscript) { height /= SupScale; baseline /= SupScale; } else if (_format.specialStyle == TextFormat.SpecialStyle.Superscript) { height = height / SupScale + baseline * SupOffset; baseline *= (SupOffset + 1 / SupScale); } height = Mathf.RoundToInt(height); baseline = Mathf.RoundToInt(baseline); return(true); } else { width = 0; height = 0; baseline = 0; return(false); } }