鼠标悬停显示tips的另类方法
1. var buttonText : GUIContent = new GUIContent("some dasdfgwbutton");
2. var buttonStyle : GUIStyle = GUIStyle.none;
3. var leftPosition:float;
4. var topPosition:float;
5. var btn_w :float;
6. var btn_h :float;
7. public var isOver;
8. public var create;
9.
10.
11.
12. function Awake(){
13. isOver = false;
14. create = false;
15. }
16. function Update(){
17. Over();
18. }
19.
20. function OnGUI() {
21.
22. GUILayout.Button( "My button" ); 23. if(Event.current.type == EventType.Repaint &&
24. GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition )) {
25. //GUILayout.Label( "Mouse over!" ); 26. create = true;
27. if(isOver == true){
28. if(btn_w<100&&btn_h<200){ 29. btn_w+=1;
30. btn_h+=2;
31. }
32. GUI.Window(0,Rect(leftPosition,topPosition,btn_w,btn_h),ShowTips,"");
33. }
34. }else{
35. create = false;
36. }
37.
38. var rt : Rect = GUILayoutUtility.GetRect(buttonText, buttonStyle);
39. if (rt.Contains(Event.current.mousePosition)) { 40. create = true;
41. if(isOver == true){
42. if(btn_w<100&&btn_h<200){
43. btn_w+=1;
44. btn_h+=2;
45. }
46. }
47. GUI.Label(Rect(leftPosition,topPosition,btn_w,btn_h), "PosX: " + rt.x + "\nPosY: " + rt.y +
48. "\nWidth: " + rt.width + "\nHeight: " + rt.height); 49. }
50. GUI.Button(rt, buttonText, buttonStyle); 51. }
52. function ShowTips(windowID:int){
53. if(isOver == true){
54. GUI.Box(Rect(0,0,btn_w,btn_h),"Mouse over!"); 55. }
56. }
57. function Over(){
58. if(create == true){
59. leftPosition = Input.mousePosition.x; 60. topPosition = Screen.height - Input.mousePosition.y;
61. isOver = true;
62. }else{
63. btn_w = 0;
64. btn_h = 0;
65. }
66. }