public void PrintString(Texture2D originalTex, string str, FontStyle style, Vector2 position, uint spacing, uint size, Color fontColor, byte rotation, out int width, out int height, float scaleX = 1f, float scaleY = 1f) { var stringTex = GetString(str, style, spacing); if (size != m_charSize || scaleX != 1f || scaleY != 1f) { TextureScale.Bilinear(stringTex, (int)((stringTex.width * size / m_charSize) * scaleX), (int)(size * scaleY)); } if (rotation > 0) { for (byte b = 0; b <= rotation; b++) { var dumpTex = stringTex; stringTex = TextureUtils.RotateRight(stringTex); dumpTex.DisposeTexFromMemory(); } } width = stringTex.width; height = stringTex.height; position.y = originalTex.height - position.y - height; for (int x = 0; x < stringTex.width; x++) { if ((int)position.x + x < originalTex.width) { for (int y = 0; y < stringTex.height; y++) { if ((int)position.y + y > 0) { Color stringColor = stringTex.GetPixel(x, y); if (stringColor.a > 0) { if (!m_disableColorOverwriting) { stringColor = new Color(fontColor.r, fontColor.g, fontColor.b, stringColor.a); } if (stringColor.a < 1) { stringColor = TextureUtils.AverageColor(originalTex.GetPixel((int)position.x + x, (int)position.y + y), stringColor); } originalTex.SetPixel((int)position.x + x, (int)position.y + y, stringColor); } } } } } originalTex.Apply(); // attempt to reduce RAM usage (1.7.1) stringTex.DisposeTexFromMemory(); }
public void PrintString(Texture2D originalTex, string str, FontStyle style, Vector2 position, uint spacing, uint size, Color fontColor, byte rotation, out int width, out int height, float scaleX = 1f, float scaleY = 1f) { var stringTex = GetString(str, style, spacing); if (size != 50 || scaleX != 1f || scaleY != 1f) { TextureScale.Bilinear(stringTex, (int)((stringTex.width * size / 50) * scaleX), (int)(size * scaleY)); } if (rotation > 0) { for (byte b = 0; b <= rotation; b++) { stringTex = TextureUtils.RotateRight(stringTex); } } width = stringTex.width; height = stringTex.height; // position.y = Mathf.Abs(position.y - originalTex.height) - stringTex.height; position.y = originalTex.height - position.y - height; for (int x = 0; x < stringTex.width; x++) { if ((int)position.x + x < originalTex.width) { for (int y = 0; y < stringTex.height; y++) { if ((int)position.y + y > 0) { Color stringColor = stringTex.GetPixel(x, y); if (stringColor.a > 0) { if (!m_disableColorOverwriting) { stringColor = new Color(fontColor.r, fontColor.g, fontColor.b, stringColor.a); } if (stringColor.a < 1) { stringColor = TextureUtils.AverageColor(originalTex.GetPixel((int)position.x + x, (int)position.y + y), stringColor); } originalTex.SetPixel((int)position.x + x, (int)position.y + y, stringColor); } } } } } originalTex.Apply(); // return originalTex; }