Author Topic: Reset checkboxes in grid  (Read 2778 times)

giosolo

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Reset checkboxes in grid
« on: September 12, 2012, 12:26:27 AM »
Based on Example 7 (Scroll view panel) I added 3 checkboxes dynamically to a grid.
I had set a layer to the Grid's parent panel, and according to my game state I add/remove this layer from camera.cullingMask and camera.eventReceiverMask.

Once the player had checked some of the checkboxes and submit - the panel is not rendered (and the checkboxes are still checked).   
Next time the panel should be rendered (with the appropriate game state) I  reset the checkboxes to be unchecked with the following code:
  1.         foreach (Transform child in grid)
  2.                 {
  3.                     UICheckbox cb = child.GetComponent<UICheckbox>();
  4.                         cb.isChecked = false;
  5.                 }

This reset cause the grid to respond incorrectly when I click a checkbox immediately after the reset. Though the checkbox hover works correctly, after the click it is still unchecked.
I found out that if I wait ~3 seconds after this reset - then chicking a checkbox works fine.

In several places I tried to use
  1. grid.GetComponent<UIGrid>().Reposition() ,
  2. grid.parent.GetComponent<UIPanel>().Refresh() ,
  3. grid.parent.GetComponent<UIDraggablePanel>().ResetPosition()
  4.  

but couldn't solve this issue.
What am I missing?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Reset checkboxes in grid
« Reply #1 on: September 12, 2012, 01:40:34 AM »
I'm not sure what waiting for 3 seconds does in this case. Even if it was tween-related, tweens and animations are both very short -- a quarter of a second long at longest, I believe. Going with the grid, there is also no need to do a reposition unless you physically add/remove checkboxes yourself. So unfortunately off the top of my head, I can't tell you what's happening in your project here.