Отображение tooltip's

Лучший способ помочь другим, поделиться своими находками.

Отображение tooltip's

Сообщение Sergion 16 июл 2010, 13:44

Простая функция для отображение текущего тултипа. Подсказка отображается с задержкой, с учетом разрешения. Функцию Tooltip() нужно вызывать вконце функции OnGUI().
В GUIStyle подсказки нужно включить Word Wrap, и Stretch Height (Stretch Width выключить), Border по 5, Padding по 2, Alignment - MiddleCenter.

Код: Выделить всё
var styleTooltip : GUIStyle;

private var tooltipDelay : float = 0.5;
private var tooltipDelayer : float;

function Tooltip () {
   var tooltip : String = GUI.tooltip;
   
   //Задержка перед отображением
   if(tooltip == "") {
      if(tooltipDelayer > 0) tooltipDelayer -= Time.deltaTime/2;
      return;
   }
   else if(tooltipDelayer < tooltipDelay + 0.1) {
      tooltipDelayer += Time.deltaTime;
   }
   if(tooltipDelayer < tooltipDelay) return;
   
   //Вычислить позицию
   var tooltipX : float = Input.mousePosition.x + 10;
   var tooltipY : float = Screen.height - Input.mousePosition.y;
   var tooltipWidth : float = 150 + tooltip.length;
   var tooltipHeight : float = 34 + (5 * (tooltip.length/20));
   if(tooltipX > Screen.width - tooltipWidth) tooltipX = Input.mousePosition.x - tooltipWidth;
   if(Input.mousePosition.y < tooltipHeight) tooltipY -= tooltipHeight;
      
   //Отобразить подсказку
   GUI.Box( Rect(tooltipX, tooltipY,  tooltipWidth, tooltipHeight), tooltip, GUIStyle(styleTooltip) );   
}
Аватара пользователя
Sergion
Админ
 
Сообщения: 116
Зарегистрирован: 20 мар 2009, 20:51
Откуда: Москва

Вернуться в Исходники (Копилка)

Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 3