• Unity3D☞button 和Rect上悬停显示tips


    /*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;
    }
    }
  • 相关阅读:
    devexpress13学习系列(三)PDFViewer(3)
    devexpress13学习系列(一)PDFViewer(2)
    devexpress13学习系列(一)PDFViewer(1)
    Android图像处理之Bitmap类(zz)
    laravel 制作购物车流程
    数据类型转换
    http返回值
    前段框架
    开启GD拓展
    PHP初级程序员出路
  • 原文地址:https://www.cnblogs.com/Mygirl/p/2099740.html
Copyright © 2020-2023  润新知