智慧 + 毅力 = 无所不能

正确性、健壮性、可靠性、效率、易用性、可读性、可复用性、兼容性、可移植性...

导航

button和Rect上悬停显示tips

Posted on 2012-11-26 12:02  Bill Yuan  阅读(919)  评论(0编辑  收藏  举报

转自:http://www.cnblogs.com/Mygirl/archive/2011/07/07/2099740.html

/*button 和Rect上悬停显示tips */
var buttonText : GUIContent = new GUIContent("some dasdfgwbutton");
var buttonStyle : GUIStyle = GUIStyle.none;
var leftPosition:float;
var topPosition:float;
var btn_w :float;
var btn_h :float;
public var isOver;
public var create;

function Awake(){
  isOver = false;
  create = false;
}
function Update()
{   Over(); }
function OnGUI()
{   GUILayout.Button(
"My button" );   if(Event.current.type == EventType.Repaint &&     GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition ))
  {
    //GUILayout.Label( "Mouse over!" );     create = true;     if(isOver == true)
    {
      if(btn_w<100&&btn_h<200)
      {         btn_w
+=1;         btn_h+=2;     }     GUI.Window(0,Rect(leftPosition,topPosition,btn_w,btn_h),ShowTips,"");     }   }else
  {     create = false;   }   var rt : Rect = GUILayoutUtility.GetRect(buttonText, buttonStyle);   if (rt.Contains(Event.current.mousePosition))
  {     create
= true;     if(isOver == true)
    {
      if(btn_w<100&&btn_h<200)
      {         btn_w
+=1;         btn_h+=2;       }     }     GUI.Label(Rect(leftPosition,topPosition,btn_w,btn_h), "PosX: " + rt.x + "\nPosY: " + rt.y +       "\nWidth: " + rt.width + "\nHeight: " + rt.height);   }   GUI.Button(rt, buttonText, buttonStyle); }
function ShowTips(windowID:int)
{   
if(isOver == true)
  {     GUI.Box(Rect(
0,0,btn_w,btn_h),"Mouse over!");   } }
function Over()
{   
if(create == true)
  {     leftPosition
= Input.mousePosition.x;     topPosition = Screen.height - Input.mousePosition.y;     isOver = true;   }else
  {     btn_w = 0;     btn_h = 0;   } }