- 最后登录
- 2017-5-15
- 注册时间
- 2012-3-1
- 阅读权限
- 90
- 积分
- 32973
  
- 纳金币
- 32806
- 精华
- 12
|
下面是我模拟的函数。public void drawRegion(Texture img,int imgX,
int imgY, int imgWidth, int imgHeight, float rotate, int x, int y)
{
if (img != null)
{
float posX, posY;
if (Screen.width >= imgMapWidth)
{
posX = (Screen.width - imgMapWidth) / 2;
}
else
{
posX = 0;
}
if (Screen.height >= imgMapHeight)
{
posY = (Screen.height - imgMapHeight) / 2;
}
else
{
posY = 0;
}
//第1个坐标:x初始位置
//第2个坐标:y初始位置
//第3个坐标:宽度
//第4个坐标:高度
GUI.BeginGroup(new Rect(x + posX, y + posY, imgWidth, imgHeight));
//这里用-imgX , -imgY,原因是前面GUI.BeginGroup切了范围后,
//这里是相对坐标,如果切原图起始x坐标为20
//这里相当于图片相对于切的区域向左移了20个像素。原理和j2me的setclip类似
//旋转的中心点,设为是剪裁区域的中心点
//这里已经做了BeginGroup剪裁,起始坐标可以理解为从0开始。
//所以这里中心点坐标不用设x + posX,只设imgWidth / 2即可
//Vector2 pivotPoint = new Vector2(x + posX + imgWidth / 2, y + posY + imgHeight / 2);
Vector2 pivotPoint = new Vector2(imgWidth / 2, imgHeight / 2);
//屏幕画面整体旋转rotate角度
GUIUtility.RotateAroundPivot(rotate, pivotPoint);
GUI.DrawTexture(new Rect(-imgX , -imgY, img.width, img.height), img);
//旋转完后再旋转回去,这样后面的显示画面就不会是旋转的了
GUIUtility.RotateAroundPivot(-rotate, pivotPoint);
GUI.EndGroup();
}
}
角度旋转实现出来了,不过水平翻转不知道该怎么模拟了。请教。。。unity有什么函数可以水平翻转吗?
还有就是上面这个方法,运行起来很慢,哪里写的不好,给点意见。太感谢了。
|
|