Author Topic: How do I move, reparent and show/hide widgets properly?  (Read 9837 times)

col000r

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 3
  • Posts: 43
  • Mighty Emperor of Planet "Home Office"
    • View Profile
    • BLACKISH
How do I move, reparent and show/hide widgets properly?
« on: September 30, 2014, 03:43:22 AM »
I have a scrollview with thousands of items. To make this work at a reasonable framerate, I only add 50 or so cells and repurpose, refill and move them around the scrollview as items move in and out of view. All in all I only need about twice as many cells as can be in view at once to scroll through thousands of items with great framerate.

But as I keep scrolling and showing and hiding and moving, things go weird. I'm fading visibilities in and out all over the place (due to mouseover, different parts of a cell have different opacities depending on their type, fade out/fade in when I switch categories, etc.) All cells that are not currently needed are moved to a secondary off-screen widget on a different panel and are hidden.

My problem: widgets tend to get stuck at wrong opacity. The inspector displays the correct opacity, but it's displaying something else. If I disable and enable the gameObject in the inspector, everything snaps back to the way it should look.

What can I do in code to make sure a widget that might have been hidden, moved to a different parent and had its opacity changed will refresh and display its current condition properly?

So far I'm calling ParentHasChanged on the widget and panel.Refresh on the panel.
Games: BLACKISH | Blog | Assets

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How do I move, reparent and show/hide widgets properly?
« Reply #1 on: September 30, 2014, 04:25:33 AM »
In which version of NGUI? I vaguely recall this happening in a version from maybe 3 months ago or so...

Bastek

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 3
    • View Profile
Re: How do I move, reparent and show/hide widgets properly?
« Reply #2 on: October 08, 2014, 03:22:06 PM »
I have similar problem. I use Unity 4.5.3 and NGUI 3.7.1.
Sometimes when i change parent of the object to different panel and use ParentHasChanged on widget (and all of it's children) not every object is visible after reparenting. And like col000r said - when i disable and enable this object in editor it is visible again.

col000r

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 3
  • Posts: 43
  • Mighty Emperor of Planet "Home Office"
    • View Profile
    • BLACKISH
Re: How do I move, reparent and show/hide widgets properly?
« Reply #3 on: October 22, 2014, 08:38:45 AM »
I'm still on 3.6.9, let's see if upgrading to 3.7.1 fixes it!
Games: BLACKISH | Blog | Assets

PoN

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 4
  • Posts: 111
    • View Profile
Re: How do I move, reparent and show/hide widgets properly?
« Reply #4 on: October 22, 2014, 09:06:43 PM »
i think i have similar trouble , in unity 4.5.5 and ngui 3.7.4. . when i use drag & drop item which has uipanel component, and when item goes back to grid if can't dropped to right a surface. i use hack like this :
  1.         panelItem.enabled = false;// NGUI hack
  2.         panelItem.enabled = true; // NGUI hack
  3.  

or without this hack, item is just disappear when moved back to grid.
Worked on Doc&DogAge Of Fury 3D. Actually working on WarMach.