public void Bake()
{
var tSize = TextureSize;
_bakedTexture = new Bitmap(tSize.Width, tSize.Height);
// Clear baked texture with transparent color.
for (int y = 0; y < _bakedTexture.Height; y++)
for (int x = 0; x < _bakedTexture.Width; x++)
_bakedTexture.SetPixel(x, y, Color.Transparent);
int xOffset = 0;
for (int i = 0; i < Text.Length; i++)
{
if (_font.textureList.ContainsKey(Text[i]) == false) continue;
var textC = _font.textureList[Text[i]];
if (textC == null) continue;
float _scale = _charSettings[i].Scale;
Color _foreColor = _charSettings[i].ForeColor;
float cX = xOffset + textC.OffsetX * _scale;
float cY = GetCursor() - textC.OffsetY * _scale;
float cW = textC.Texture.Width * _scale;
float cH = textC.Texture.Height * _scale;
float cA = textC.Advance * _scale;
if (cW <= 0 || cH <= 0)
{
// Skip
}
else
{
var origPixels = textC.Texture.uTexture.GetPixels32();
var newTexture = new UnityEngine.Texture2D(textC.Texture.Width, textC.Texture.Height);
newTexture.name = "backedGlyphTexture";
newTexture.SetPixels32(origPixels);
newTexture.Apply();
// Scale texture if needed.
if ((int)cW != newTexture.width || (int)cH != newTexture.height)
{
TextureScaler.scale(newTexture, (int)cW, (int)cH);
//TextureScale.Bilinear(newTexture, (int)cW, (int)cH);
newTexture.Apply();
}
var newImagePixels = newTexture.GetPixels32();
for (int p = 0; p < newImagePixels.Length; p++)
{
// BlendMode: Multiply
var origColor = Color.FromUColor(newImagePixels[p]);
var blendColorA = (float)(origColor.A * _foreColor.A) / 255;
var blendColorR = (float)(origColor.R * _foreColor.R) / 255;
var blendColorG = (float)(origColor.G * _foreColor.G) / 255;
var blendColorB = (float)(origColor.B * _foreColor.B) / 255;
var blendColor = Color.FromArgb((int)blendColorA, (int)blendColorR, (int)blendColorG, (int)blendColorB);
newImagePixels[p] = blendColor.ToUColor();
}
_bakedTexture.uTexture.SetPixels32((int)cX, (int)cY, newTexture.width, newTexture.height, newImagePixels);
}
xOffset += (int)cA;
}
_bakedTexture.Apply();
if (AutoSize)
Size = tSize;
}