- 最后登录
- 2018-6-29
- 注册时间
- 2011-7-1
- 阅读权限
- 20
- 积分
- 359
- 纳金币
- 335582
- 精华
- 0
|
using UnityEngine;
namespace user
{//by gotoxy
class userFont
{
/*
LoadResources.FontTexture[]:为字体的纹理图片,格式为m*n个,每个字符大小相同,从空格(0x20)开始
使用的是Graphics.DrawTexture(),所以要在OnGUI()中调用
*/
private static int font_width = 16;
private static int font_height = 16;
private static int font_space_width = 4;//字符边沿空隙
private static int font_space_height = 2;//字符边沿空隙
private static int fontid = 0;
private static float zoom = 1.0f;
private static Color color = new Color(255, 0, 255);
//---------------------------------------------------------------------------------------------------------------
public static
void choosefont(int f)
{
if (f >= LoadResources.FontTexture.Length) return;
fontid = f;
if(fontid==0)
{
font_width = 16;
font_height = 16;
font_space_width = 4;
font_space_height = 2;
}
else if(fontid==1)
{
font_width = 16;
font_height = 16;
font_space_width = 4;
font_space_height = 2;
}
else
{
fontid = 0;
font_width = 16;
font_height = 16;
font_space_width = 4;
font_space_height = 2;
}
}
public static
void setcolor(Color usercolor)
{
color = usercolor;
}
public static
Color getcolor()
{
return color;
}
public static
void setzoom(float z)
{
zoom = z;
}
public static
void setsize(int w, int h)
{
font_width = w;
font_height = h;
}
public static
void setsize(float fw, float fh)
{
font_width = (int)((float)font_width * fw);
font_height = (int)((float)font_height * fh);
}
//---------------------------------------------------------------------------------------------------------------
public static
void user_puts(int x, int y, string str)
{
int FONT_W = font_width;
int FONT_H = font_height;
if (FONT_W == 0 || FONT_H == 0) return;
float font_base_w = (float)FONT_W / LoadResources.FontTexture[fontid].width; //fontWidth/LoadResources.FontTexture[fontid].width;
float font_base_h = (float)FONT_H / LoadResources.FontTexture[fontid].height; //fontHeight/LoadResources.FontTexture[fontid].height;
float Space_X = (float)font_space_width / LoadResources.FontTexture[fontid].width;//字符边沿空隙
float Space_Y = (float)font_space_height / LoadResources.FontTexture[fontid].height;
float tx, ty;
int i, a;
int XTile = LoadResources.FontTexture[fontid].width / FONT_W;
int YTile = LoadResources.FontTexture[fontid].height / FONT_H;
FONT_W = (int)((float)FONT_W * zoom);
FONT_H = (int)((float)FONT_H * zoom);
char[] buff = new char[str.Length];
buff = str.ToCharArray();
for (i = 0; i < buff.Length; i++)
{
if (buff >= 0x20) a = (int)(buff & 0xff) - 0x20;//从空格开始
else a = 0;
tx = (float)(a % XTile) * font_base_w;
ty = (float)(YTile - 1 - (a / XTile)) * font_base_h;
Graphics.DrawTexture(new Rect(x, y, FONT_W, FONT_H), LoadResources.FontTexture[fontid], new Rect(tx + Space_X, ty + Space_Y, font_base_w - 2 * Space_X, font_base_h - 2 * Space_Y), 0, 0, 0, 0, color);
x += FONT_W;
}
}
public static
void user_puts(int x, int y, string str, float userzoom)
{
int FONT_W = font_width;
int FONT_H = font_height;
if (FONT_W == 0 || FONT_H == 0) return;
float font_base_w = (float)FONT_W / LoadResources.FontTexture[fontid].width; //fontWidth/LoadResources.FontTexture[fontid].width;
float font_base_h = (float)FONT_H / LoadResources.FontTexture[fontid].height; //fontHeight/LoadResources.FontTexture[fontid].height;
float Space_X = (float)font_space_width / LoadResources.FontTexture[fontid].width;//字符边沿空隙
float Space_Y = (float)font_space_height / LoadResources.FontTexture[fontid].height;
float tx, ty;
int i, a;
int XTile = LoadResources.FontTexture[fontid].width / FONT_W;
int YTile = LoadResources.FontTexture[fontid].height / FONT_H;
FONT_W = (int)((float)FONT_W * userzoom);
FONT_H = (int)((float)FONT_H * userzoom);
char[] buff = new char[str.Length];
buff = str.ToCharArray();
for (i = 0; i < buff.Length; i++)
{
if (buff >= 0x20) a = (int)(buff & 0xff) - 0x20;
else a = 0;
tx = (float)(a % XTile) * font_base_w;
ty = (float)(YTile - 1 - (a / XTile)) * font_base_h;
Graphics.DrawTexture(new Rect(x, y, FONT_W, FONT_H), LoadResources.FontTexture[fontid], new Rect(tx + Space_X, ty + Space_Y, font_base_w - 2 * Space_X, font_base_h - 2 * Space_Y), 0, 0, 0, 0, color);
x += FONT_W;
}
}
public static
void user_puts(int x, int y, string str, float userzoom, Color usercolor)
{
int FONT_W = font_width;
int FONT_H = font_height;
if (FONT_W == 0 || FONT_H == 0) return;
float font_base_w = (float)FONT_W / LoadResources.FontTexture[fontid].width; //fontWidth/LoadResources.FontTexture[fontid].width;
float font_base_h = (float)FONT_H / LoadResources.FontTexture[fontid].height; //fontHeight/LoadResources.FontTexture[fontid].height;
float Space_X = (float)font_space_width / LoadResources.FontTexture[fontid].width;//字符边沿空隙
float Space_Y = (float)font_space_height / LoadResources.FontTexture[fontid].height;
float tx, ty;
int i, a;
int XTile = LoadResources.FontTexture[fontid].width / FONT_W;
int YTile = LoadResources.FontTexture[fontid].height / FONT_H;
FONT_W = (int)((float)FONT_W * userzoom);
FONT_H = (int)((float)FONT_H * userzoom);
char[] buff = new char[str.Length];
buff = str.ToCharArray();
for (i = 0; i < buff.Length; i++)
{
if (buff >= 0x20) a = (int)(buff & 0xff) - 0x20;
else a = 0;
tx = (float)(a % XTile) * font_base_w;
ty = (float)(YTile - 1 - (a / XTile)) * font_base_h;
Graphics.DrawTexture(new Rect(x, y, FONT_W, FONT_H), LoadResources.FontTexture[fontid], new Rect(tx + Space_X, ty + Space_Y, font_base_w - 2 * Space_X, font_base_h - 2 * Space_Y), 0, 0, 0, 0, usercolor);
x += FONT_W;
}
}
//---------------------------------------------------------------------------------------------------------------
public static
void user_puts(int x, int y, byte[] buff, int len)
{
int FONT_W = font_width;
int FONT_H = font_height;
if (FONT_W == 0 || FONT_H == 0) return;
float font_base_w = (float)FONT_W / LoadResources.FontTexture[fontid].width; //fontWidth/LoadResources.FontTexture[fontid].width;
float font_base_h = (float)FONT_H / LoadResources.FontTexture[fontid].height; //fontHeight/LoadResources.FontTexture[fontid].height;
float Space_X = (float)font_space_width / LoadResources.FontTexture[fontid].width;//字符边沿空隙
float Space_Y = (float)font_space_height / LoadResources.FontTexture[fontid].height;
float tx, ty;
int i, a;
int XTile = LoadResources.FontTexture[fontid].width / FONT_W;
int YTile = LoadResources.FontTexture[fontid].height / FONT_H;
FONT_W = (int)((float)FONT_W * zoom);
FONT_H = (int)((float)FONT_H * zoom);
for (i = 0; i < len && i < buff.Length; i++)
{
if (buff >= 0x20) a = (int)(buff & 0xff) - 0x20;
else a = 0;
tx = (float)(a % XTile) * font_base_w;
ty = (float)(YTile - 1 - (a / XTile)) * font_base_h;
Graphics.DrawTexture(new Rect(x, y, FONT_W, FONT_H), LoadResources.FontTexture[fontid], new Rect(tx + Space_X, ty + Space_Y, font_base_w - 2 * Space_X, font_base_h - 2 * Space_Y), 0, 0, 0, 0, color);
x += FONT_W;
}
}
public static
void user_puts(int x, int y, byte[] buff, int len, float userzoom)
{
int FONT_W = font_width;
int FONT_H = font_height;
if (FONT_W == 0 || FONT_H == 0) return;
float font_base_w = (float)FONT_W / LoadResources.FontTexture[fontid].width; //fontWidth/LoadResources.FontTexture[fontid].width;
float font_base_h = (float)FONT_H / LoadResources.FontTexture[fontid].height; //fontHeight/LoadResources.FontTexture[fontid].height;
float Space_X = (float)font_space_width / LoadResources.FontTexture[fontid].width;//字符边沿空隙
float Space_Y = (float)font_space_height / LoadResources.FontTexture[fontid].height;
float tx, ty;
int i, a;
int XTile = LoadResources.FontTexture[fontid].width / FONT_W;
int YTile = LoadResources.FontTexture[fontid].height / FONT_H;
FONT_W = (int)((float)FONT_W * userzoom);
FONT_H = (int)((float)FONT_H * userzoom);
for (i = 0; i < len && i < buff.Length; i++)
{
if (buff >= 0x20) a = (int)(buff & 0xff) - 0x20;
else a = 0;
tx = (float)(a % XTile) * font_base_w;
ty = (float)(YTile - 1 - (a / XTile)) * font_base_h;
Graphics.DrawTexture(new Rect(x, y, FONT_W, FONT_H), LoadResources.FontTexture[fontid], new Rect(tx + Space_X, ty + Space_Y, font_base_w - 2 * Space_X, font_base_h - 2 * Space_Y), 0, 0, 0, 0, color);
x += FONT_W;
}
}
public static
void user_puts(int x, int y, byte[] buff, int len, float userzoom, Color usercolor)
{
int FONT_W = font_width;
int FONT_H = font_height;
if (FONT_W == 0 || FONT_H == 0) return;
float font_base_w = (float)FONT_W / LoadResources.FontTexture[fontid].width; //fontWidth/LoadResources.FontTexture[fontid].width;
float font_base_h = (float)FONT_H / LoadResources.FontTexture[fontid].height; //fontHeight/LoadResources.FontTexture[fontid].height;
float Space_X = (float)font_space_width / LoadResources.FontTexture[fontid].width;//字符边沿空隙
float Space_Y = (float)font_space_height / LoadResources.FontTexture[fontid].height;
float tx, ty;
int i, a;
int XTile = LoadResources.FontTexture[fontid].width / FONT_W;
int YTile = LoadResources.FontTexture[fontid].height / FONT_H;
FONT_W = (int)((float)FONT_W * userzoom);
FONT_H = (int)((float)FONT_H * userzoom);
for (i = 0; i < len && i < buff.Length; i++)
{
if (buff >= 0x20) a = (int)(buff & 0xff) - 0x20;
else a = 0;
tx = (float)(a % XTile) * font_base_w;
ty = (float)(YTile - 1 - (a / XTile)) * font_base_h;
Graphics.DrawTexture(new Rect(x, y, FONT_W, FONT_H), LoadResources.FontTexture[fontid], new Rect(tx + Space_X, ty + Space_Y, font_base_w - 2 * Space_X, font_base_h - 2 * Space_Y), 0, 0, 0, 0, usercolor);
x += FONT_W;
}
}
}
} |
|