Version: 5.3 (switch to 5.4b)
言語English
  • C#
  • JS

スクリプト言語

好きな言語を選択してください。選択した言語でスクリプトコードが表示されます。

GUI.tooltip

マニュアルに切り替える
public static var tooltip: string;

説明

マウスが現在上にある、またはキーボードフォーカスを持つコントロールのツールチップ(読み取り専用)

GUI コントロールを作成するときは、GUI コントロールのツールチップを渡すことができます。これは GUIContent オブジェクトを作成してツールチップの文字列を渡すことになります。

マウスがツールチップを持つコントロールの上にあるとき、GUI.tooltip にそのツールチップの文字列を設定します。 もしマウスがどのコントロール上にもいない場合は、キーボードフォーカスを持つコントロールのツールチップを設定します。 OnGUI コードの最後に、GUI.tooltip の値を表示するためのラベルを作成することができます。


マウスをボタンの上にのせるとゲームビューに GUI ツールチップが表示されます

	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); }

要素の順番を利用して「階層的な」ツールチップを作成することができます:

	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); }

ツールチップは OnMouseOver / OnMouseOut のメッセージングシステムを実装するために利用することもできます:

	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"); }