Author Topic: [NGUI] Proper way to update widgets in code?  (Read 3819 times)

OmegaQueen

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
[NGUI] Proper way to update widgets in code?
« on: November 26, 2014, 07:52:53 PM »
Hi,

I have a group of labels attached to one GameObject each. The labels are all under one parent object.

I want to move the parent object (from a script) and then have each label's position/collider/bounds update immediately in the next line in the script so I can perform a check on the new position before the next frame starts.

How do I do this?

I've tried using UILabel.Update(), but the values don't change. Or am I supposed to do something with the UIPanel?

Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: [NGUI] Proper way to update widgets in code?
« Reply #1 on: November 26, 2014, 08:59:18 PM »
I'm not sure I understand the question. If you move something, then its position is updated right away. What are you trying to check?

OmegaQueen

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: [NGUI] Proper way to update widgets in code?
« Reply #2 on: November 27, 2014, 12:27:36 AM »
Hi Aren, sorry for the poor explanation. I'll try again

So I have a bunch of UILabels that are children of an object in 3D space. I move the parent/root in 3D space using:

  1. transform.localPosition += adjustmentVector;

but the positions of all the children labels don't seem to update their position until the next frame. So when I use them in the next line of code after moving the label they are in the position that they were before the parent object was moved, instead of the new position.

I am assuming the labels don't update immediately because I am moving objects based on whether or not they overlapp on screen. I want to do this with a while loop:

  1. //While There are intersections
  2.                 while(Intersections(enemyLabelsSortedByIntersections) > 0)

but the program gets stuck in the while loop. If I change it to an if statement then it slowly works over time and the Intersections() method returns 0 when nothing is touching. So I was wondering if NGUI labels had to be updated by their panel or something after Mono Update() or something
« Last Edit: November 27, 2014, 12:33:46 AM by OmegaQueen »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: [NGUI] Proper way to update widgets in code?
« Reply #3 on: November 27, 2014, 08:48:10 PM »
Well again, what are you checking? You mentioned what you're changing, but what code do you use to check whatever you're checking? If it's transform position, then it's all Unity. And it's updated right away, just like any other game object. If it's widget's corners, then that may not be, depending on a couple of factors.