/*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; } }