返回介绍

GUI.tooltip 工具提示

发布于 2019-12-18 15:37:45 字数 6858 浏览 1369 评论 0 收藏 0

JavaScript => public static var tooltip: string;
C# => public static string tooltip;

Description 描述

The tooltip of the control the mouse is currently over, or which has keyboard focus. (Read Only).

控制鼠标当前通过对象的提升信息,或具有键盘焦点。

When you create GUI controls, you can pass in a tooltip for them. This is done by changing the content parameter to take a custom-made GUIContent object, rather than just passing in a string to display.

当你创建GUI控件的时候,你可以传递一个提示信息给他们。这可以通过改变内容参数去自定义GUIContent物体,而不是仅仅传递一个字符串。

When the mouse is over a control with a tooltip, it sets the global GUI.tooltip value to the tooltip you pass in. If the mouse is not hovering over any control, the value is set to the control which has keyboard focus. At the end of the OnGUI code, you can make a label showing the value of GUI.tooltip

当鼠标通过控件有提示信息的控件时,它设置全局GUI.tooltip的值到你传递的提示信息。如果鼠标没有通过任何控件,这个值设置到有键盘焦点的控件。在OnGUI代码的最后你可以创建一个标签来显示GUI.tooltip的值。

GUI Tooltip on th Game view appears when the mouse is over the button.

当鼠标移到到按钮之上时,游戏视图显示的GUI工具提示。

JavaScript:

	function OnGUI () {
		// Make a button using a custom GUIContent parameter to pass in the tooltip.
		GUI.Button (Rect (10,10,100,20), GUIContent ("Click me", "This is the tooltip"));
 
		// Display the tooltip from the element that has mouseover or keyboard focus
		GUI.Label (Rect (10,40,100,40), GUI.tooltip);
	}

You can use the ordering of elements to create 'hierarchical' tooltips:

JavaScript:

	function OnGUI () {
		// This box is larger than many elements following it, and it has a tooltip.
		GUI.Box (Rect (5, 35, 110, 75), GUIContent ("Box", "this box has a tooltip"));
 
		// This button is inside the box, but has no tooltip so it does not
		// override the box's tooltip.
		GUI.Button (Rect (10, 55, 100, 20), "No tooltip here");
 
		// This button is inside the box, and HAS a tooltip so it overrides
		// the tooltip from the box.
		GUI.Button (Rect (10, 80, 100, 20),
			GUIContent ("I have a tooltip", "The button overrides the box"));
		// finally, display the tooltip from the element that has
		// mouseover or keyboard focus
		GUI.Label (Rect (10,40,100,40), GUI.tooltip);
	}

Tooltips can also be used to implement an OnMouseOver / OnMouseOut messaging system:

Tooltip也能用来实现 OnMouseOver / OnMouseOut 消息系统。

JavaScript:

var lastTooltip : String = " ";
 
	function OnGUI () {
		GUILayout.Button (GUIContent ("Play Game", "Button1"));
		GUILayout.Button (GUIContent ("Quit", "Button2"));
 
		if (Event.current.type == EventType.Repaint && GUI.tooltip != lastTooltip) {
			if (lastTooltip != "")
				SendMessage (lastTooltip + "OnMouseOut", SendMessageOptions.DontRequireReceiver);
			if (GUI.tooltip != "")
				SendMessage (GUI.tooltip + "OnMouseOver", SendMessageOptions.DontRequireReceiver);
			lastTooltip = GUI.tooltip;
		}
	}
 
	function Button1OnMouseOver () {
		Debug.Log ("Play game got focus");
	}
 
	function Button2OnMouseOut () {
		Debug.Log ("Quit lost focus");
	}

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    void OnGUI() {
        GUI.Button(new Rect(10, 10, 100, 20), new GUIContent("Click me", "This is the tooltip"));
        GUI.Label(new Rect(10, 40, 100, 40), GUI.tooltip);
    }
}

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    void OnGUI() {
        GUI.Box(new Rect(5, 35, 110, 75), new GUIContent("Box", "this box has a tooltip"));
        GUI.Button(new Rect(10, 55, 100, 20), "No tooltip here");
        GUI.Button(new Rect(10, 80, 100, 20), new GUIContent("I have a tooltip", "The button overrides the box"));
        GUI.Label(new Rect(10, 40, 100, 40), GUI.tooltip);
    }
}

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    public string lastTooltip = " ";
    void OnGUI() {
        GUILayout.Button(new GUIContent("Play Game", "Button1"));
        GUILayout.Button(new GUIContent("Quit", "Button2"));
        if (Event.current.type == EventType.Repaint && GUI.tooltip != lastTooltip) {
            if (lastTooltip != "")
                SendMessage(lastTooltip + "OnMouseOut", SendMessageOptions.DontRequireReceiver);
 
            if (GUI.tooltip != "")
                SendMessage(GUI.tooltip + "OnMouseOver", SendMessageOptions.DontRequireReceiver);
 
            lastTooltip = GUI.tooltip;
        }
    }
    void Button1OnMouseOver() {
        Debug.Log("Play game got focus");
    }
    void Button2OnMouseOut() {
        Debug.Log("Quit lost focus");
    }
}

gui

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文