public void Update() { if (_texture == null) { _texture = new Texture2D(1, 1, TextureFormat.Alpha8, false); _texture.hideFlags = HideFlags.HideInInspector | HideFlags.DontSave; _texture.filterMode = FilterMode.Point; _texture.wrapMode = TextureWrapMode.Clamp; //Debug.Log("Texture2D creation: " + _texture.GetNativeTextureID()); } int textureID = _texture.GetNativeTextureID(); SysFont.QueueTexture(_text, FontName, _fontSize, _isBold, _isItalic, _alignment, _isMultiLine, _maxWidthPixels, _maxHeightPixels, textureID); _textWidthPixels = SysFont.GetTextWidth(textureID); _textHeightPixels = SysFont.GetTextHeight(textureID); _widthPixels = SysFont.GetTextureWidth(textureID); _heightPixels = SysFont.GetTextureHeight(textureID); SysFont.UpdateQueuedTexture(textureID); _lastText = _text; _lastFontName = FontName; _lastFontSize = _fontSize; _lastIsBold = _isBold; _lastIsItalic = _isItalic; _lastAlignment = _alignment; _lastIsMultiLine = _isMultiLine; _lastMaxWidthPixels = _maxWidthPixels; _lastMaxHeightPixels = _maxHeightPixels; }
public bool Update() { if (_texture == null) { _texture = new Texture2D(1, 1, TextureFormat.Alpha8, false); _texture.hideFlags = HideFlags.HideInInspector | HideFlags.DontSave; _texture.filterMode = FilterMode.Point; _texture.wrapMode = TextureWrapMode.Clamp; _texture.Apply(false, true); _textureId = 0; } if (_textureId == 0) { _textureId = _texture.GetNativeTextureID(); if (_textureId == 0) { // texture not ready, it may happen on multi-threaded rendering return(false); } //Debug.Log("Texture2D creation: " + _textureId); } SysFont.QueueTexture(_text, FontName, _fontSize, _isBold, _isItalic, _alignment, _isMultiLine, _maxWidthPixels, _maxHeightPixels, _textureId); _textWidthPixels = SysFont.GetTextWidth(_textureId); _textHeightPixels = SysFont.GetTextHeight(_textureId); _widthPixels = SysFont.GetTextureWidth(_textureId); _heightPixels = SysFont.GetTextureHeight(_textureId); SysFont.UpdateQueuedTexture(_textureId); _lastText = _text; _lastFontName = FontName; _lastFontSize = _fontSize; _lastIsBold = _isBold; _lastIsItalic = _isItalic; _lastAlignment = _alignment; _lastIsMultiLine = _isMultiLine; _lastMaxWidthPixels = _maxWidthPixels; _lastMaxHeightPixels = _maxHeightPixels; _lastScaleSize = _scaleSize; return(true); }
public Vector3 GetAdvance(object parameters, object font, char c) { //return Vector3.zero; FontSelector fs = font as FontSelector; Parameters cp = parameters as Parameters; if (cp.fixedWidth) { return(new Vector3(1, 0, 0)); } else { Texture2D _texture = new Texture2D(1, 1, TextureFormat.Alpha8, false); _texture.hideFlags = HideFlags.HideInInspector | HideFlags.DontSave; _texture.filterMode = FilterMode.Point; _texture.wrapMode = TextureWrapMode.Clamp; int textureID = _texture.GetNativeTextureID(); SysFont.QueueTexture("" + c, #if UNITY_ANDROID fs.AndroidFontName #else #if UNITY_IPHONE fs.AppleFontName #else ((string)font) #endif #endif , 12, false, //_isBold, false, //_isItalic, SysFont.Alignment.Left, //_alignment, false, 2048, 2048, textureID ); int _textWidthPixels = SysFont.GetTextWidth(textureID); // int _textHeightPixels = SysFont.GetTextHeight(textureID); GameObject.Destroy(_texture); return(new Vector3(_textWidthPixels * cp.scale, 0, 0)); } }
public TTFTextTexturePortion ComputeGlyphBitmap(object parameters, object font, char c) { SysFontTexture tex = new SysFontTexture(); FontSelector fs = (FontSelector)GetFontSelectorFromFontName((string)font); tex.AndroidFontName = fs.AndroidFontName; tex.AppleFontName = fs.AppleFontName; tex.Update(); Texture2D _texture = new Texture2D(1, 1, TextureFormat.Alpha8, false); //Texture2D _texture = new Texture2D(64, 64, TextureFormat.RGBA32, false); _texture.hideFlags = HideFlags.HideInInspector | HideFlags.DontSave; _texture.filterMode = FilterMode.Point; _texture.wrapMode = TextureWrapMode.Clamp; int textureID = _texture.GetNativeTextureID(); SysFont.QueueTexture("" + c, #if UNITY_ANDROID fs.AndroidFontName #else #if UNITY_IPHONE fs.AppleFontName #else ((string)font) #endif #endif , 12, false, //_isBold, false, //_isItalic, SysFont.Alignment.Left, //_alignment, false, 2048, 2048, textureID ); int _textWidthPixels = SysFont.GetTextWidth(textureID); int _textHeightPixels = SysFont.GetTextHeight(textureID); SysFont.UpdateQueuedTexture(textureID); Debug.Log("."); Parameters cp = parameters as Parameters; Material m = null; if (cp != null) { Shader shader = Shader.Find(cp.shaderName); if (shader == null) { shader = Shader.Find("Mobile/Diffuse"); } if (shader == null) { shader = Shader.Find("Diffuse"); } m = new Material(shader); m.color = new Color(cp.red, cp.green, cp.blue, cp.alpha); m.mainTexture = _texture; } else { Shader shader = Shader.Find("SysFont/Unlit Transparent"); if (shader == null) { shader = Shader.Find("Mobile/Diffuse"); } if (shader == null) { shader = Shader.Find("Diffuse"); } m = new Material(shader); m.color = Color.black; m.mainTexture = _texture; } TTFTextTexturePortion p = new TTFTextTexturePortion( m, 0, 0, 1, 1, _textWidthPixels * cp.scale, _textHeightPixels * cp.scale, 0, 0, true ); return(p); }