Для вызова хинта, необходимо в элемент GUI передать GUIContent с заполненной переменной tooltip
После завершения отображения GUI, проверить GUI.tooltip и, если получено значение, передать его классу CsShowHint
Примерно так :
Синтаксис:
Используется cpp
<script type="text/javascript">
<!--
var id = 'SXBB_0_fd3ceca0';
SXBB[id] = new _SXBB(id);
SXBB[id].T['select'] = 'Select';
SXBB[id].T['expand'] = 'Expand';
SXBB[id].T['contract'] = 'Contract';
//-->
</script>
<!--
var id = 'SXBB_0_fd3ceca0';
SXBB[id] = new _SXBB(id);
SXBB[id].T['select'] = 'Select';
SXBB[id].T['expand'] = 'Expand';
SXBB[id].T['contract'] = 'Contract';
//-->
</script>
Синтаксис:
Используется cpp
Rect hintRect;
switch(GUI.tooltip)
{
case "Копировать" :
hintRect = new Rect(wRect.x + bottomButton0.x, wRect.y + wRect.height + 1, 10, 30);
CsShowHint.Hint(hintRect, buttonContent0.tooltip, true);
break;
case "Вставить" :
hintRect = new Rect(wRect.x + bottomButton1.x, wRect.y + wRect.height + 1, 10, 30);
CsShowHint.Hint(hintRect, buttonContent1.tooltip, true);
break;
case "Удалить" :
hintRect = new Rect(wRect.x + bottomButton2.x, wRect.y + wRect.height + 1, 10, 30);
CsShowHint.Hint(hintRect, buttonContent2.tooltip, true);
break;
}
switch(GUI.tooltip)
{
case "Копировать" :
hintRect = new Rect(wRect.x + bottomButton0.x, wRect.y + wRect.height + 1, 10, 30);
CsShowHint.Hint(hintRect, buttonContent0.tooltip, true);
break;
case "Вставить" :
hintRect = new Rect(wRect.x + bottomButton1.x, wRect.y + wRect.height + 1, 10, 30);
CsShowHint.Hint(hintRect, buttonContent1.tooltip, true);
break;
case "Удалить" :
hintRect = new Rect(wRect.x + bottomButton2.x, wRect.y + wRect.height + 1, 10, 30);
CsShowHint.Hint(hintRect, buttonContent2.tooltip, true);
break;
}
И в результате увидите примерно такой тултип (если ваш скин будет похож на мой, конечно) :
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
CsShowHint.cs
Синтаксис:
Используется cpp
//Created by Neodrop
using UnityEngine;
using System.Collections;
public class CsShowHint : MonoBehaviour
{
public GUISkin mySkin;
public static GUISkin mySkinStatic;
const float TIME_TO_WAIT = .5f, TIME_TO_SHOW = 2.5f;
protected static bool showHint = false;
protected static Rect guiElementRect;
protected static CsShowHint thisScript;
protected static Vector3 startMousePos;
protected static string hintText;
protected static bool globalGUI = false;
void Awake()
{
thisScript = this;
mySkinStatic = mySkin;
}
static void HintOnGUI()
{
//GUI.Box(guiElementRect, hintText, "Hint Box"); // Раскомментировать для удобной настройки скина.
if (!showHint) return;
GUI.skin = mySkinStatic;
GUIContent content = new GUIContent(hintText);
Rect rect = GUILayoutUtility.GetRect(content, GUI.skin.box);
rect.x = guiElementRect.x - rect.width/2; rect.y = guiElementRect.y; rect.height = 25;
GUI.Box(rect, hintText, "Hint Box"); ..Здесь может быть указан ваш собственный стиль или вовсе никакого.
}
void OnGUI()
{
if (!globalGUI) return;
GUI.depth = -1;
CsShowHint.HintOnGUI();
}
public static void Hint(Rect guiElement_Rect, string hint_Text, bool globalOnGUI)
{
if (guiElementRect != guiElement_Rect)
{
globalGUI = globalOnGUI;
showHint = false;
thisScript.StopAllCoroutines();
hintText = hint_Text;
thisScript.StartToWait();
guiElementRect = guiElement_Rect;
}
else if (startMousePos != Input.mousePosition)
{
globalGUI = globalOnGUI;
showHint = false;
thisScript.StopCoroutine("Waiter");
thisScript.StartToWait();
}
else { if(!globalGUI)HintOnGUI(); }
}
void StartToWait()
{
StartCoroutine(Waiter());
}
IEnumerator Waiter()
{
startMousePos = Input.mousePosition;
yield return new WaitForSeconds(TIME_TO_WAIT);
if (startMousePos == Input.mousePosition)
{
showHint = true;
StartCoroutine(TimeToShowDone());
}
}
IEnumerator TimeToShowDone()
{
yield return new WaitForSeconds(TIME_TO_SHOW);
showHint = false;
}
}
using UnityEngine;
using System.Collections;
public class CsShowHint : MonoBehaviour
{
public GUISkin mySkin;
public static GUISkin mySkinStatic;
const float TIME_TO_WAIT = .5f, TIME_TO_SHOW = 2.5f;
protected static bool showHint = false;
protected static Rect guiElementRect;
protected static CsShowHint thisScript;
protected static Vector3 startMousePos;
protected static string hintText;
protected static bool globalGUI = false;
void Awake()
{
thisScript = this;
mySkinStatic = mySkin;
}
static void HintOnGUI()
{
//GUI.Box(guiElementRect, hintText, "Hint Box"); // Раскомментировать для удобной настройки скина.
if (!showHint) return;
GUI.skin = mySkinStatic;
GUIContent content = new GUIContent(hintText);
Rect rect = GUILayoutUtility.GetRect(content, GUI.skin.box);
rect.x = guiElementRect.x - rect.width/2; rect.y = guiElementRect.y; rect.height = 25;
GUI.Box(rect, hintText, "Hint Box"); ..Здесь может быть указан ваш собственный стиль или вовсе никакого.
}
void OnGUI()
{
if (!globalGUI) return;
GUI.depth = -1;
CsShowHint.HintOnGUI();
}
public static void Hint(Rect guiElement_Rect, string hint_Text, bool globalOnGUI)
{
if (guiElementRect != guiElement_Rect)
{
globalGUI = globalOnGUI;
showHint = false;
thisScript.StopAllCoroutines();
hintText = hint_Text;
thisScript.StartToWait();
guiElementRect = guiElement_Rect;
}
else if (startMousePos != Input.mousePosition)
{
globalGUI = globalOnGUI;
showHint = false;
thisScript.StopCoroutine("Waiter");
thisScript.StartToWait();
}
else { if(!globalGUI)HintOnGUI(); }
}
void StartToWait()
{
StartCoroutine(Waiter());
}
IEnumerator Waiter()
{
startMousePos = Input.mousePosition;
yield return new WaitForSeconds(TIME_TO_WAIT);
if (startMousePos == Input.mousePosition)
{
showHint = true;
StartCoroutine(TimeToShowDone());
}
}
IEnumerator TimeToShowDone()
{
yield return new WaitForSeconds(TIME_TO_SHOW);
showHint = false;
}
}