- Home /
C# Tooltips through multiple windows
I am currently working on a script to auto-focus on the Gui window that is hovered over, the problem I am having is the window focus and tooltips. It seems as if the focus is shifted to the window, but the tooltips in the window will not show still until it is clicked on (manually focused).
Easy to test, just float over the windows, if the tooltip on the label doesnt show, click it and then it will.. Any ideas on how to fix this issue?
using UnityEngine;
using System.Collections;
public class TestScript : MonoBehaviour {
Rect charwindowRect = new Rect(10, 10, 200, 60);
Rect inventoryRect = new Rect(10, 80, 200, 60);
Rect tooltipRect = new Rect(10, 150, 200, 60);
private string _tooltip;
private int _tempfocus;
void OnGUI() {
charwindowRect = GUILayout.Window(3, charwindowRect, CharWindow, "Char window");
inventoryRect = GUILayout.Window(2, inventoryRect, InventoryWindow, "Inventory");
tooltipRect = GUILayout.Window(1, tooltipRect, TooltipWindow, "Tooltips");
}
void CharWindow(int windowID) {
FocusWindow(charwindowRect, windowID);
GUILayout.BeginHorizontal();
GUI.Label(new Rect(25,20,265,20), new GUIContent("char", "charwindow tooltip"));
GUILayout.EndHorizontal();
if (Event.current.type == EventType.Repaint) {
_tooltip = GUI.tooltip;
}
}
void InventoryWindow ( int windowID) {
FocusWindow(inventoryRect, windowID);
GUILayout.BeginHorizontal();
GUI.Label(new Rect(25,20,265,20), new GUIContent("inv", "inv window tooltip"));
GUILayout.EndHorizontal();
if (Event.current.type == EventType.Repaint) {
_tooltip = GUI.tooltip;
}
}
void TooltipWindow ( int windowID) {
GUILayout.BeginHorizontal();
GUI.Label(new Rect(25,20,265,20), _tooltip );
GUILayout.EndHorizontal();
}
void FocusWindow(Rect thisRect, int windowID) {
if(thisRect.Contains(new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y)))
{
if(_tempfocus != windowID) {
_tempfocus = windowID;
GUI.FocusWindow(windowID);
}
}
}
}
Awesome, just added in GUI.BringWindowToFront(windowID) in the FocusWindow function, it now focuses and shows tooltip. Thanks!
We've just noticed in our game that GUI.tooltip is not being set unless the window has focus, and that is definitely new behaviour. Previously we were able to do something like what you have without requiring a focus change. Has anyone else noticed this? (I have tried in 4.1.0 and 4.1.3).
Answer by AVividLight · Aug 07, 2013 at 09:10 PM
Hey dju4ic,
You should try using GUI.BringWindowToFront, it may be your problem.
I hope this helps! -Gibson
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Keeping Unity Focused 0 Answers
Trouble using C# tooltips 1 Answer
On object clicked open a window using C# 0 Answers