UI 的旋转

转自:http://blog.163.com/long_wtf/blog/static/185553270201192943354903/


现在的demo里用的2D显示是 GUI.DrawTexture(); 策划提了个需求,说是做个表,有时针、分针、秒针,要求和系统时间相对应。解决思路如下:使用矩阵的旋转来做,使用一个临时变量保存正常的矩阵,调用函数  static function RotateAroundPivot (angle : float, pivotPoint : Vector2) : void   来进行旋转(ScaleAroundPivot可以用来缩放),第一个参数为旋转角度,从当前状态顺时针旋转的度数。第二个为中心点。做完相应操作,还原矩阵。代码如下:


var n : int;

function OnGUI()

{

    n++;  

    var oldMatrix : Matrix4x4 = GUI.matrix;  

    GUIUtility.RotateAroundPivot(n,Vector2(100,100));  

    GUI.Button( Rect(100,100,100,100), "Rotation" );  

    GUI.matrix = oldMatrix;  

    GUI.Button( Rect(200,200, 100,100),"static" );

}


你可能感兴趣的:(UI 的旋转)