Unity3d:Texture的简单缩放与旋转

以下是在unity3d中对GUITexture进行环绕图片中心的简单缩放与旋转的例子:


public class ScaleAndRotationGuiTexture: MonoBehaviour
{
/// <summary>
/// 将使用到的GUISkin
/// </summary>
public GUISkin mySkin;

/// <summary>
/// 变换焦点
/// </summary>
private Vector2 pivotPoint;

/// <summary>
/// 初始缩放向量
/// </summary>
private Vector2 scale = new Vector2(1, 1);

/// <summary>
/// 旋转角度
/// </summary>
private float rotAngle = 0;

/// <summary>
/// Texture的位置
/// </summary>
private Rect imgPosition = new Rect(100, 100, 320, 240);

protected void OnGUI () {
GUI.skin = mySkin;
Texture bg = GUI.skin.GetStyle("test").normal.background;

if (GUI.Button(new Rect(Screen.width / 2 - 25, Screen.height / 2 - 25, 50, 50), "放大!"))
{
scale += new Vector2(0.15F, 0.15F);
}

if (GUI.Button(new Rect(Screen.width / 2 - 90, Screen.height / 2 - 25, 50, 50), "缩小!"))
{
scale -= new Vector2(0.15F, 0.15F);
}

if (GUI.Button(new Rect(Screen.width / 2 - 150, Screen.height / 2 - 25, 50, 50), "左旋"))
{
rotAngle += 10;
}

if (GUI.Button(new Rect(Screen.width / 2 - 210, Screen.height / 2 - 25, 50, 50), "右旋!"))
{
rotAngle -= 10;
}


pivotPoint = new Vector2(imgPosition.x + imgPosition.width / 2, imgPosition.y + imgPosition.height / 2);//(Screen.width / 2, Screen.height / 2);
GUIUtility.ScaleAroundPivot(scale, pivotPoint);
GUIUtility.RotateAroundPivot(rotAngle, pivotPoint);

GUI.DrawTexture(new Rect(100, 100, 320, 240), bg);
}
}

©️2020 CSDN 皮肤主题: 大白 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值