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

スクリプト言語

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

GUI.tooltip

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

説明

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

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

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


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

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

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

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

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

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