Author Topic: Trouble with CalculateRelativeWidgetBounds and inactive gameobject  (Read 2117 times)

AceDude

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
I have a world-space screen powered by NGUI, it works quite well. I'm trying to put something on the screen when the object is inactive, but immediately remove it if it exceeds the screen boundaries. I found the right function for it - NGUIMath.CalculateRelativeWidgetBounds.

When I call the function when the screen is active [NGUIMath.CalculateRelativeWidgetBounds(container.transform)], it works just fine. Trouble begin when I try to run it when the screen is disabled. I'm supposed to use NGUIMath.CalculateRelativeWidgetBounds(container.transform, true), but it returns pretty random output:


The dimensions should be 200x100.

Any clue how to fix it? Help is much appreciated :)
« Last Edit: September 03, 2014, 03:53:00 PM by AceDude »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Trouble with getInventoryPanelDimensions and inactive gameobject
« Reply #1 on: August 23, 2014, 03:17:40 AM »
Note line 461 in NGUIMath.cs. The second line of CalculateRelativeWidgetBounds() function.
  1. if (!considerInactive && !NGUITools.GetActive(content.gameObject)) return;

AceDude

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Trouble with getInventoryPanelDimensions and inactive gameobject
« Reply #2 on: August 25, 2014, 11:37:51 AM »
Well, I think I'm calling the function the right way (you can see it above). The whole function I call on the object that's disabled is:
  1. public Bounds getPanelDimensions() {           
  2.                 Bounds dimensions = NGUIMath.CalculateRelativeWidgetBounds(container.transform, true);
  3.  
  4.                 return dimensions ;
  5.         }

I really can't see what might be wrong :(

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Trouble with getInventoryPanelDimensions and inactive gameobject
« Reply #3 on: August 26, 2014, 02:25:14 AM »
Ah, well when you try to calculate the dimensions of a panel it calls UIPanel.worldCorners, which in turn uses the camera object and view size. But if the camera is disabled... I don't know what it uses. Have a closer look in UIPanel.worldCorners.