zoukankan      html  css  js  c++  java
  • button和Rect上悬停显示tips

    转自: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;   } }
  • 相关阅读:
    <hdu2072>单词数(set容器,string类应用)
    志愿者选拔
    Game of Life
    <LightOJ 1338> Hidden Secret!
    Miss Kitty and Her Little Ice Cream Shop(水题)
    约瑟夫问题
    <FZU 1019>猫捉老鼠
    <cf>System of Equations(水题)
    Palindromic Numbers (III)(回文数,较麻烦)
    <cf>Solitaire(DFS or DP)
  • 原文地址:https://www.cnblogs.com/sevenyuan/p/2788796.html
Copyright © 2011-2022 走看看