UI的旋转

来源:互联网 发布:淘宝网站外推广 编辑:程序博客网 时间:2024/06/05 10:14

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


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


[html] view plaincopyprint?
  1. var n : int;  
  2.   
  3. function OnGUI()  
  4.   
  5. {  
  6.   
  7.     n++;    
  8.   
  9.     var oldMatrix : Matrix4x4 = GUI.matrix;    
  10.   
  11.     GUIUtility.RotateAroundPivot(n,Vector2(100,100));    
  12.   
  13.     GUI.Button( Rect(100,100,100,100), "Rotation" );    
  14.   
  15.     GUI.matrix = oldMatrix;    
  16.   
  17.     GUI.Button( Rect(200,200, 100,100),"static" );  
  18.   
  19. }  

将上述代码挂在摄像机上即可
原创粉丝点击