Author Topic: ToolTip Display Issue  (Read 9489 times)

BlueSin

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 17
    • View Profile
ToolTip Display Issue
« on: October 05, 2015, 03:20:43 PM »
I have a weird issue going on right now with my tool tips.  Basically I have an item picker window, that fills a scrollview-grid system with the items matching a filter from my inventory, but it only displays the item icon.  When I hover my mouse cursor over the icon, I want a tool tip to display the extended details of that item.  The code I am using to position the tool tip is here:

  1. Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
  2. transform.OverlayPosition(mousePosition, Camera.main, UICamera.mainCamera);

That code is located on a script attached to the tooltip.  If I hover my mouse over the center of the item icon the tool tip upper left corner should display at my mouse cursor point.  But instead it is doing this:



You can see the tooltip is off in the bottom left corner, even though my mouse position is in the center of the pink square.  So what am I doing wrong?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: ToolTip Display Issue
« Reply #1 on: October 07, 2015, 08:19:23 PM »
The overlay position function will only work with 2D UIs. I am guessing yours is 3D?

BlueSin

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: ToolTip Display Issue
« Reply #2 on: October 10, 2015, 12:04:54 PM »
It should be 2D, I think NGUI auto generated it when I started placing components.  But I have been placing 3D colliders on objects and the UICamera event type says 3D, so maybe not.  How can I be sure it is a 2D UI?  When I set event type to 2D and change all the colliders to 2D colliders, it still pops up in the bottom left of the screen.
« Last Edit: October 10, 2015, 12:13:10 PM by BlueSin »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: ToolTip Display Issue
« Reply #3 on: October 10, 2015, 11:46:07 PM »
3D colliders are normal. When you select the camera it should tell you what it is under the Camera's "Projection" field in inspector. Orthographic = 2D. Perspective = 3D.

BlueSin

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: ToolTip Display Issue
« Reply #4 on: October 11, 2015, 11:23:30 AM »
Ah, in that case my UI is 2D as it is set to orthographic.  So it would seem that is not the problem.  Could it be because the item being hovered is in a scrollview and grid? I can't see how that would matter but, I have double and triple checked that I am not changing the position in way other that my code I originally posted.  Here is the code that spawns the tooltip from the item icon (pink square):

  1. private void OnTooltip(bool show)
  2. {
  3.             if (show)
  4.             {
  5.                 if (m_CurrentToolTip == null)
  6.                 {
  7.                     GameObject go = NGUITools.AddChild(m_CurrentRoot, ItemToolTipPrefab);
  8.                     m_CurrentToolTip = go.GetComponent<UIItemToolTip>();
  9.                     m_CurrentToolTip.SetData(DisplayedItem);
  10.                 }
  11.                 else
  12.                 {
  13.                     m_CurrentToolTip.SetData(DisplayedItem);
  14.                     m_CurrentToolTip.Show();
  15.                 }
  16.             }
  17.             else
  18.             {
  19.                 if (m_CurrentToolTip != null)
  20.                     m_CurrentToolTip.Hide();
  21.             }        
  22. }

The tooltip then has this code in the Awake & Show methods:

  1. Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
  2. transform.OverlayPosition(mousePosition, Camera.main, UICamera.mainCamera);
« Last Edit: October 11, 2015, 11:32:16 AM by BlueSin »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: ToolTip Display Issue
« Reply #5 on: October 12, 2015, 11:03:15 PM »
What's "m_CurrentRoot" and why are you adding the game object with the tooltip to it? The tooltip should already exist in the scene, ideally underneath a clean top-level panel just under the UIRoot.

What I always do in my games is have a singleton class attached to the tooltip (UITooltip comes with NGUI but I usually expand it), and that's what I use to show/hide it.

UITooltip.Show(...);

It positions itself.